Created
October 1, 2013 17:09
-
-
Save alextercete/6781822 to your computer and use it in GitHub Desktop.
A good example of Fluent Mocking (see http://rodrigodumont.com/2013/09/26/fluent-mocking-for-unit-tests/)
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
public static class HttpMessageHandlerExtensions | |
{ | |
public static HttpMessageHandler ThatRespondsWithAnEmptyContent(this HttpMessageHandler handler) | |
{ | |
var mock = Mock.Get(handler); | |
var responseWithAnEmptyContent = new HttpResponseMessage {Content = new StringContent(string.Empty)}; | |
mock.Protected() | |
.Setup<Task<HttpResponseMessage>>("SendAsync", new object[] | |
{ | |
ItExpr.IsAny<HttpRequestMessage>(), | |
ItExpr.IsAny<CancellationToken>() | |
}) | |
.Returns(Task.FromResult(responseWithAnEmptyContent)); | |
return handler; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment