Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a FsCheck generator for an interface in C#

Tags:

c#

fscheck

Suppose I have an interface IPerson with 2 read properties age (int) and name (string).

I also have a class Person implementing IPerson.

How do I write a FsCheck generator for generating instances of IPerson type?

like image 476
sthiers Avatar asked Mar 13 '23 09:03

sthiers


1 Answers

Something like the below should work:

Gen<IPerson> gen = from age in Arb.Default.Int32().Generator
                   from name in Arb.Default.String().Generator
                   select new Person(age, name) as IPerson;
like image 130
Kurt Schelfthout Avatar answered Mar 15 '23 23:03

Kurt Schelfthout