Sto usando il framework Moq per il test delle unità e vorrei poter passare in Action per registrare i metodi void.Come posso creare un'azione <T> in F #?
let log = new Mock<ILog>()
let quot = <@ fun (mock:ILog) -> mock.Info(It.IsAny<string>) @>
let expr = (quot.ToLinqExpression() :?> Expression<Action<ILog>>)
log.Verify(expr)
Questo codice non riesce con il seguente errore:
System.InvalidCastException : Unable to cast object of type 'System.Linq.Expressions.MethodCallExpressionN' to type 'System.Linq.Expressions.Expression
1[System.Action
1[log4net.ILog]]'.
posso stampare il tipo utilizzando
printfn "%s" (quot.Type.ToString())
che emette
Microsoft.FSharp.Core.FSharpFunc`2[log4net.ILog,Microsoft.FSharp.Core.Unit]
Così, come posso creare un'azione?
Moq in F # -> probabilmente una cattiva idea . –
Sì, in F #, noi Foq invece - vedi http://trelford.com/blog/post/Foq.aspx e http://trelford.com/blog/post/FoqItEasy.aspx (transizione molto facile da Moq) –