public async Task CheckHealthAsync_ReadDataFromResponseIfFalse_Healthy() { //arrange var httpContextAccessor = new Mock <IHttpContextAccessor>(); var httpContext = new Mock <HttpContext>(); var httpRequest = new Mock <HttpRequest>(); var hostString = new HostString("google.com"); var httpClientFactory = new Mock <HttpClientFactory>(); httpContextAccessor.Setup(x => x.HttpContext).Returns(httpContext.Object); httpContext.Setup(x => x.Request).Returns(httpRequest.Object); httpRequest.Setup(x => x.Scheme).Returns("http - test"); httpRequest.Setup(x => x.Host).Returns(hostString); httpClientFactory.Setup(x => x.GetAsync("http - test://google.com")).ReturnsAsync(String.Empty); var target = new IndexPageHealthCheck(httpContextAccessor.Object, httpClientFactory.Object); //act var result = await target.CheckHealthAsync(null, default); //assert using (new AssertionScope()) { result.Status.Should().Be(HealthStatus.Unhealthy); result.Description.Should().Be("The check indicates an unhealthy result."); } }
public async Task CheckHealthAsync_ReadDataFromResponse_ReadData() { //arrange var httpContextAccessor = new Mock <IHttpContextAccessor>(); var httpContext = new Mock <HttpContext>(); var httpRequest = new Mock <HttpRequest>(); var httpClientFactory = new Mock <HttpClientFactory>(); var hostString = new HostString("google.com"); httpContextAccessor.Setup(x => x.HttpContext).Returns(httpContext.Object); httpContext.Setup(x => x.Request).Returns(httpRequest.Object); httpRequest.Setup(x => x.Scheme).Returns("http - test"); httpRequest.Setup(x => x.Host).Returns(hostString); httpClientFactory.Setup(x => x.GetAsync("http - test://google.com")).ReturnsAsync(string.Empty); var target = new IndexPageHealthCheck(httpContextAccessor.Object, httpClientFactory.Object); //act await target.CheckHealthAsync(null, default); //assert httpClientFactory.Verify(x => x.GetAsync("http - test://google.com"), Times.Once); }