MisterJames / GenFu

GenFu is a library you can use to generate realistic test data. It is composed of several property fillers that can populate commonly named properties through reflection using an internal database of values or randomly created data. You can override any of the fillers, give GenFu hints on how to fill them.
Other
831 stars 100 forks source link

How to force to fill nullable properties? #134

Closed ildoc closed 4 years ago

ildoc commented 6 years ago

Not a bug, but since I couldn't find any documentation, I don't know where else to ask for support...

I have a class like this:

public class Thing
{
    public int? Id { get; set; }
    public string Description { get; set; }
    public DateTime? Timestamp { get; set; }
}

And I configured like this:

A.Configure<Thing>()
    .Fill(x => x.Id)
    .Fill(x => x.Timestamp);

but when I create a list with var things = A.ListOf<Thing>(50);, all of them have Id and Timestamp as null

(I'm using it in a .NET framework 4.6.2 project)

What I'm missing? How can I force nullable properties to be filled?

dpaquette commented 6 years ago

You shouldn't need to do anything special to fill nullable properties. Can you try var things = A.ListOf<Thing>(50) without doing anything to Configure first?

When I try this on genfu.io, it works without configuration.

image

markphillips01 commented 6 years ago

I'm having the same issue as well - i think that website testbed might be doing some different config, so i pasted the code int a unit test

        public class Thing
        {
            public int? Id { get; set; }
            public string Description { get; set; }
            public DateTime? Timestamp { get; set; }
        }

        [TestMethod]
        public void TestMethod_2()
        {
            var things = A.ListOf<Thing>(5);
            foreach (var thing in things)
            {
                Debug.WriteLine($"Id: {thing.Id}, Descritpion: {thing.Description}, TimeStamp: {thing.Timestamp}");
            }
        }

and here's the debug output

Id: , Descritpion: pack, TimeStamp: 
Id: , Descritpion: williamsburg, TimeStamp: 
Id: , Descritpion: pack, TimeStamp: 
Id: , Descritpion: apparel, TimeStamp: 
Id: , Descritpion: government, TimeStamp: 
stimms commented 6 years ago

I think there was indeed a bug on this. Can you try the latest version?

On Wed, Mar 7, 2018 at 11:54 PM, markp notifications@github.com wrote:

I'm having the same issue as well - i think that website testbed might be doing some different config, so i pasted the code int a unit test

    public class Thing
    {
        public int? Id { get; set; }
        public string Description { get; set; }
        public DateTime? Timestamp { get; set; }
    }

    [TestMethod]
    public void TestMethod_2()
    {
        var things = A.ListOf<Thing>(5);
        foreach (var thing in things)
        {
            Debug.WriteLine($"Id: {thing.Id}, Descritpion: {thing.Description}, TimeStamp: {thing.Timestamp}");
        }
    }

and here's the debug output

Id: , Descritpion: pack, TimeStamp: Id: , Descritpion: williamsburg, TimeStamp: Id: , Descritpion: pack, TimeStamp: Id: , Descritpion: apparel, TimeStamp: Id: , Descritpion: government, TimeStamp:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MisterJames/GenFu/issues/134#issuecomment-371397433, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJZOBjj7p595ZM-EBG90BEerhq2eLISks5tcNW7gaJpZM4SIFPW .

markphillips01 commented 6 years ago

Awesome - just updated to the latest version (1.4.22) - All seems to working great!