bchavez / Bogus

:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Other
8.84k stars 502 forks source link

Profile 259 Compatibility? #78

Closed adamhill closed 7 years ago

adamhill commented 7 years ago

Is there any version of Bogus that is compatible with PCL Profile 259 in Xamarin? I tried all the way up to 7.1.2, which is the one just before .NET Core support was official. I always get:

Could not install package 'Bogus 7.1.3'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259'

when I try to add the the Nuget package.

Even though the Dependency is .NET 4.0 and 259 is Version=4.5 shouldn't I be able to add it? I thought dependencies were always >= <X.X>

Thanks.

bchavez commented 7 years ago

Hi @adamhill ,

Thank you for bringing the issue to attention. :sunglasses:

You're right. Bogus is not compatible with Xamarin at the moment. I think I tried Xamarin some time ago and ran into the same issue with as you've described above. I've just been too lazy to fix the problem because it's not an immediate need of mine in my current projects.

I suspect the crux of the issue is we're missing an explicit build target for profile259/xamarin in our build process. Additionally, there might be some .NET cross-platform reflection APIs that probably need some tweaking to be fully compatible with Xamarin.

There are a few ways we can proceed to get this resolved:

  1. I'd be happy to accept a PR for Xamarin compatibility. Just fork Bogus and explore the code on what needs to be fixed. Once you send in the PR: a) We'll review the PR. b) Make revisions c) Merge and Publish
  2. You can set up a bounty for about $200 and I'll get this implemented. I can aim to get it done within 72 hours or so.
  3. Wait for someone else to do the work.

Some helpful guidelines on modifying Bogus' source:

Please let me know how you'd like to proceed.

Also, just as a heads-up (no offense) I'll be closing this issue if we don't have a path forward because I'm OCD w.r.t unresolved-open issues in GitHub that might linger on for years. IMHO, GitHub issues are like trying to get to Inbox :mailbox_with_no_mail: zero! Hehe.

Thanks, Brian

:car: :blue_car: "Let the good times roll..."

bchavez commented 7 years ago

Hey @adamhill ,

FYI. Latest release v17 (compiled against .NET Standard 2.0) appears to run on Xamarin Mobile now:

screen_526


Here's how I got it working:

Here's a screenshot and XAML samples that I used to get it working:

devenv_528

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:BogusApp1"
             x:Class="BogusApp1.MainPage">

   <StackLayout>
      <Label Text="Welcome to Xamarin Forms!" 
             VerticalOptions="Center" 
             HorizontalOptions="Center" />

      <Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblName" />
      <Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblAge" />
      <Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblEmail" />
      <Label Text="Korean Lorem:" VerticalOptions="Center" HorizontalOptions="Center" />
      <Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblLorem" />

      <Button Clicked="Button_OnClicked" Text="Generate Random Stuff" x:Name="cmdButton"></Button>
   </StackLayout>

</ContentPage>

Mainpage.xaml.cs

using System;
using Bogus;
using Bogus.DataSets;
using Xamarin.Forms;

namespace BogusApp1
{

    public class Person
    {
        public string FirstName { get; set; }
        public string LastName;
        public int Age;
        public string Email { get; set; }
    }

    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_OnClicked(object sender, EventArgs e)
        {
            var personFaker = new Faker<Person>()
                .RuleFor(p => p.FirstName, f => f.Person.FirstName)
                .RuleFor(p => p.LastName, f => f.Person.LastName)
                .RuleFor(p => p.Age, f => f.Random.Int(18, 38))
                .RuleFor(p => p.Email, f => f.Person.Email);

            var fakePerson = personFaker.Generate();

            this.lblName.Text = $"{fakePerson.FirstName} {fakePerson.LastName}";
            this.lblAge.Text = $"Age: {fakePerson.Age}";
            this.lblEmail.Text = $"{fakePerson.Email}";

            var koLorem = new Lorem("ko");

            this.lblLorem.Text = $"{koLorem.Sentence(3, 2)}";
        }
    }
}