Search code examples
f#xunitnfluent

FSharpList assertions with NFluent?


I read on the nfluent documentation that you can assert lists like this:

var inteers = new int[] { 1, 2, 3, 4, 5, 666 };
Check.That(integers).Contains(3, 5, 666);

But when I try this in F# I cannot seem to get it work:

let myList : int list = [1;2;3]
Check.That(events).Contains(1, 2, 3)

The error message is seen here:

enter image description here

How do I get the list assertions to work i F#?

Update

In my actual code the F# function returns an FSharpList and I don't want to change this so I cannot simple change the type to e.g. a seq.


Solution

  • F# doesn't do implicit casting like C# does. Method signature expects to have IEnumerable, but you supply a list. That's what the error say. The easiest fix would be to create a sequence, that is same as IEnumerable in C#:

    let myList : int list = [1;2;3]
    let mySeq = list |> Seq.ofList
    Check.That(mySeq).Contains(1, 2, 3)