1

Closed

setting up a method that returns an Async

description

Hi,

I try to set up a mock using
 Mock<Interface>.With(fun y -> <@ y.DoIt (any()) --> async {()} @>)
This leads to a NotSupportedException being raised in the function toCall.

How should I mock Async in Foq?

Is it supported?

Regs,

Remko
Closed Jan 26, 2014 at 6:49 PM by ptrelford

comments

ptrelford wrote Oct 11, 2013 at 8:31 AM

Not tried this use case yet, I'll take a look later today. Thanks for reporting it :)

ptrelford wrote Oct 11, 2013 at 10:04 AM

I can't easily reproduce the issue on the latest version of Foq, i.e. this works:

type Interface =
abstract DoIt : int -> Async<unit>

let [<Test>] Boom ()=
let x = Mock<Interface>.With(fun y -> <@ y.DoIt (any()) --> async {()} @>)
let y = x.DoIt(1)
()

If you're still having issues, please send over a failing example.

One other thing to try is to use the Setup/Returns methods instead (Foq's small built-in quotation parser only covers more common cases).

remkoboschker wrote Oct 11, 2013 at 2:42 PM

I'm mistakenly thought the async was the culprit, but it is in fact the use of two parameters. Setup / Returns behaves the same.
type Interface =
        abstract DoIt : int -> int -> Async<unit>

    let [<Test>] Boom () =
        let x = Mock<Interface>.With(fun y -> <@ y.DoIt (any()) (any()) --> async {()} @>)
        let y = x.DoIt 1 1
        ()
results in:
System.NotSupportedException : Application (Application (Lambda (arg00,
                                  Lambda (arg10,
                                          Call (Some (Value (<null>)), DoIt,
                                                [arg00, arg10]))),
                          Call (None, any, [])), Call (None, any, []))

remkoboschker wrote Oct 23, 2013 at 9:10 AM

This partial application case is addressed in one of the other issues Add support for Application quotations

ptrelford wrote Oct 24, 2013 at 12:10 AM

Issue resolved by BlackwaterPark

** Closed by ptrelford 10/23/2013 4:10PM