0

I have the following code:

open NSubstitute
type MyClass()=
    let myObject = Substitute.For<IMyInterface>()
    do myObject.MyProperty.Returns(true)
    do myObject.MyMethod().Returns(true)

On "Returns" (both) I get the error that is not defined. The equivalent C# code works without issue. Adding |> ignore at the end of the do lines does not help. Am I missing something there?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Miyamoto Akira
  • 327
  • 1
  • 7
  • 16

2 Answers2

1

I know you wrote that adding |> ignore at the end doesn't help, but this compiles on my machine:

type IMyInterface =
    abstract MyProperty : bool with get, set
    abstract member MyMethod : unit -> bool

open NSubstitute

type MyClass() =
    let myObject = Substitute.For<IMyInterface>()
    do myObject.MyProperty.Returns(true) |> ignore
    do myObject.MyMethod().Returns(true) |> ignore

I attempted to infer the definition of IMyInterface from the question; did I get it wrong?

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
0

So after I tried the code (Mark Seemann's, as to avoid my C# class) on VS2012, fsi, through direct compilation with fsc and on VS2013, the issue is clearly a VS2012 problem. The code works correctly with the other three.

Not sure yet if it is using a different version of F#. Will need further investigation. But at least, for now, on VS2012 I can use:

do SubstituteExtensions.Returns(myObject.MyProperty, true) |> ignore

It works as well when I need to pass parameters to methods.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Miyamoto Akira
  • 327
  • 1
  • 7
  • 16