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

Add setting to ignore default value checker

marius-stanescu opened this issue · comments

I see that GenFu will not write to a property if it doesn't have the default value. I think there should be a setting so we can turn this off if needed.

Can someone help me understand what is referred to as 'IT' in '...if IT doesn't have...'?

Can someone help me understand the meaning of '...the default value' in this context?

@JimKay1941 If you're filling an object and the property doesn't have a default value (0 for numerics, null for objects, ...) then GenFu will ignore the property and not fill it. That's what you were seeing in your other issue (#126). The idea here is that we could do

GenFu.Configure<BlogPost>().Fill(x=>x.Tags, 
() => new List<string> { "Azure", "AWS", "Chickens"}, 
ForceFillEvenIfAlreadyFilled = true);

And GenFu would fill the property regardless of it already had a value.

Disclaimer syntax above not the final syntax

Don't you find it jarring to have to combine 'new List<string>' and 'ForceFillEvenIfAlreadyFilled = true' in the very same statement?

Perhaps GenFu needs an additional boolean property: 'ForceFillEvenIfEmpty' wouldn't you say?

Though, upon reflection, I don't really understand how/why 'ignore' would EVER be acceptable behavior. When a service routine does NOT do what was requested, it really SHOULD provide some indication. The notion of 'fail silently' annoys me no end.

Keep in mind that we want to maintain backwards compatibility so this new behaviour cannot be the default. I'd argue that GenFu is doing what is expected, it is filling in missing data. Something like

var person = new Person("bob", "smith");
A.New<Person>(person); //fills in remaining fields

Is a reasonable application of GenFu. I'd also draw your attention to the disclaimer above that this is not a final syntax. I'm certainly willing to entertain other options so please feel free to expand upon your ForceFillEvenIfEmpty idea.

As a check against developer errors, I may want to differentiate between FillEvenIfAlreadyFilled and FillEvenIfEmpty.

To me, these are entirely different situations.

(Right now, I'm trying to test the latest version that MisterJames submitted as a Pull.)

FillEvenIfEmpty is the default behaviour now, we'll fill anything that looks like a collection unless it has things in it already.

I have tested this version by cloning it into a Git Repository.

This version is working now in the same way the Alice version was working.

Thank you for your assistance.

Can you estimate when this update will be available as a Nuget Package?