We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to mock behaviour of HttpMessageHandler, but cannot do it because of exceptions thrown by Foq.
HttpMessageHandler
Is Strict mode I get NotImplementedException and in Loose mode I get NullReferenceException
Strict
NotImplementedException
Loose
NullReferenceException
open System open System.Net.Http open Foq open System.Threading open System.Threading.Tasks open System.Reflection open System.Linq [<AbstractClass>] type TestHandler() = inherit HttpMessageHandler() abstract member MockableSendAsync: HttpRequestMessage * CancellationToken -> Task<HttpResponseMessage> override this.SendAsync(request, cancellationToken) = this.MockableSendAsync(request, cancellationToken) type TestHandler2() = inherit TestHandler() override this.MockableSendAsync(request, token) = Task.FromResult(null) let handler = Mock<TestHandler2>(MockMode.Strict) .Setup(fun h -> <@ h.MockableSendAsync(any(), any()) @>) .Returns(Task.FromResult(null)) .Create() let method = typeof<TestHandler2> .GetMethods(BindingFlags.NonPublic ||| BindingFlags.Instance ||| BindingFlags.Public) .Single(fun x -> x.Name = "SendAsync") let p = [|null; box CancellationToken.None|] let result = method.Invoke(handler, p) :?> Task<HttpResponseMessage> result.Result
It should jus work, I assume =) I've discovered this does not work with Moq as well.
The text was updated successfully, but these errors were encountered:
Pay attention to this comment
Sorry, something went wrong.
No branches or pull requests
Description
I want to mock behaviour of
HttpMessageHandler
, but cannot do it because of exceptions thrown by Foq.Is
Strict
mode I getNotImplementedException
and inLoose
mode I getNullReferenceException
Repro steps
Expected behaviour
It should jus work, I assume =)
I've discovered this does not work with Moq as well.
Related information
The text was updated successfully, but these errors were encountered: