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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to force to fill nullable properties?

ildoc opened this issue · comments

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?

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

commented

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: 
commented

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