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

偶尔善良 提交于 2019-12-10 19:22:54

问题


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?


回答1:


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;


来源:https://stackoverflow.com/questions/35203290/how-do-i-write-a-fscheck-generator-for-an-interface-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!