Background:
I have a large number of commands that satisfy following rules:
- no setters (immutable)
- one constructor
- parameter name matches the name of the property being set (other than casing)
I would like to write a tester that tests following
- given that all arguments are provided I get an instance of the class, and that all properties are set to the value passed.
- given that any one of the reguired parameters is either null, empty etc. based on the type constructor raises argument exception.
Now, I can write this via reflection, hand roll it, no problem, but I was wondering if I could tap into FsCheck generators to generate parameters.
Is this something that I could achieve with FSCheck?
Yes it can. In fact, if FsCheck can generate the types of the arguments (i.e. if they are primitive types like string or int, or can be generated reflectively), then from your description FsCheck can already generate these types out of the box without you doing anything.
For example, a type like this: (I'm assuming you're using C#)
can be generated by FsCheck, you can write an xunit test with FsCheck.Xunit as follows:
And FsCheck will generate a bunch of random Foo instances for you.