0

I'm using xunit and FsCheck from C# to generate random class data. Because of EF some of them are containing a ICollection<ChildElement> Children {get; set;} properties. Because of such properties generator gets stuck. I'm aware of possiblity to define own generator for particular class. But it is tempting and I can miss a property.

Is it possible to define a more general solution for this? Following generator doesn't work either:

    public class ICollectionGenerator
    {
        public static Arbitrary<ICollection<T>> Collection<T>()
        {
            return Arb.From(Arb.Generate<List<T>>().Select(x => (ICollection<T>)x));
        }
    }
python_kaa
  • 1,034
  • 13
  • 27

1 Answers1

0

A generator for ICollection<T> is built into FsCheck, so you don't need to provide it yourself. However, it won't work if the T is a type that FsCheck doesn't know how to generate out of the box - presumably ChildElement is one of those types. If however, you can write an Arbitrary<ChildElement> instance and provide that to a test that needs an ICollection<ChildElement>, FsCheck will be able to put both together automatically.

Kurt Schelfthout
  • 8,880
  • 1
  • 30
  • 48