Created
December 16, 2015 14:57
-
-
Save lkaczanowski/04698ad1093004012adc to your computer and use it in GitHub Desktop.
HttpMessageHandler mock helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static class MockHttpMessageHandlerHelper | |
{ | |
public static void SetupSendAsync(this Mock<HttpMessageHandler> handler, Func<HttpResponseMessage> sendAsyncResultFunc) | |
{ | |
handler.Protected() | |
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()) | |
.Returns(Task<HttpResponseMessage>.Factory.StartNew(sendAsyncResultFunc)); | |
} | |
public static void VerifySendAsync(this Mock<HttpMessageHandler> handler, Times times) | |
{ | |
handler.Protected() | |
.Verify<Task<HttpResponseMessage>>("SendAsync", times, ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()); | |
} | |
public static void VerifySendAsync(this Mock<HttpMessageHandler> handler, Expression<Func<HttpRequestMessage, bool>> requestMessagePredicate, Times times) | |
{ | |
handler.Protected() | |
.Verify<Task<HttpResponseMessage>>("SendAsync", times, ItExpr.Is<HttpRequestMessage>(requestMessagePredicate), ItExpr.IsAny<CancellationToken>()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment