Skip to content

Instantly share code, notes, and snippets.

@HamidMosalla
Created February 8, 2017 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HamidMosalla/db7206325cfe9e552211d2f5fe4668be to your computer and use it in GitHub Desktop.
Save HamidMosalla/db7206325cfe9e552211d2f5fe4668be to your computer and use it in GitHub Desktop.
public class CaptchaValidatorTests
{
private Mock<FakeHttpMessageHandler> _fakeHttpMessageHandler;
private HttpClient _httpClient;
public CaptchaValidatorTests()
{
_fakeHttpMessageHandler = new Mock<FakeHttpMessageHandler> { CallBase = true };
_httpClient = new HttpClient(_fakeHttpMessageHandler.Object);
}
[Fact]
public async Task ValidateCaptchaAsync_ShouldReturn_TheCorrectType()
{
//Arrange
_fakeHttpMessageHandler.Setup(f => f.Send(It.IsAny<HttpRequestMessage>())).Returns(new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content =new StringContent("{\"success\": false,\"error-codes\": [\"It's a fake error!\",\"It's a fake error\"]}")
});
var sut = new CaptchaValidator(_httpClient);
//Act
var result = await sut.ValidateCaptchaAsync();
//Assert
result.Should().NotBeNull();
result.Should().BeOfType<CaptchaResponse>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment