0

I'm trying to mock the .NET HttpClient with Moq in F#. I currently have the following code:

open System.Net.Http
open Foq

[<Fact>]
let ``Some test`` () =
    Mock<HttpClient>.With
        (fun client ->
            <@ client.GetStringAsync("foo")
                --> task { return "bar" } @>)
    |> ignore

Upon running the test I get the following error.

System.Reflection.TargetParameterCountException : Parameter count mismatch.

How can I fix this?

I know there are many similar questions, but they are all for C#. They mention that either there are arguments missing somewhere or something with a callback should be added. But I can't figure out what arguments are missing, or how to add the callback to my example.

Roald
  • 2,459
  • 16
  • 43

1 Answers1

1

I looked into this a bit and it seems to be caused by an underlying problem with F# quotations, rather something that can be addressed within Foq. For example, the following code throws the same unhandled exception:

<@ task { return "bar" } @>
    |> FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.EvaluateQuotation
    |> printfn "%A"

I reported this as an issue in the F# core repository.

Brian Berns
  • 15,499
  • 2
  • 30
  • 40