This project is read-only.

Does / could the .With sytax facilitate access to the matched args?

Nov 20, 2013 at 1:47 PM
Is there a way to take a .With expression:-
Mock<AClient>.With( fun x ->
                    x.A( any(), any()) ---> fun () -> [1;2]
                    x.B( any(), any(), any(), any()) ---> fun () -> [1]
and, a la [Setup]Method... .Callback(), access the arguments being matched, i.e. to be able to do something along the lines of:
Mock<AClient>.With( fun x ->
                    x.A( any(), any()) ---> fun x _ -> [x]
                    x.B( any(), any(), any(), any()) ---> fun x -> [x]
(I couldnt find any examples in the tests?)

It's not massively critical coz AIUI there is a workaround syntax. Having to fully match the arg list a la ListAvailable above would be fine (and I don't really know what the x in the x.B setup above would bind to anyway.
Nov 22, 2013 at 7:55 AM
Edited Nov 22, 2013 at 8:01 AM
Mock.With currently only supports results of type 'a and functions of type unit -> 'a.

As you mentioned It is possible via the fluent API using Calls instead of Returns:
  .Setup(fun x -> <@ x.A(any(), any()) @>).Calls<int * int>(fun (x,_) -> [x])
  .Setup(fun x -> <@ x.B(any(), any(), any()) @>).Calls<int * int * int>(fun (x) -> [x])
It is possible to also implement this for Mock.With but I can't see any easy way to provide compile time type checking on the arguments of the result function.
Marked as answer by bartelink on 11/22/2013 at 1:56 AM
Nov 22, 2013 at 10:03 AM
Thanks - that makes sense. In fairness, being able to lash in a few any()s makes it pretty manageable.

The compile time type checking is definitely a critical affordance.