Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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