public async Task SetRegionHealthStateThrowsException() { // Arrange using var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, }; var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse); using var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); var logger = A.Fake <ILogger <AppRegistryService> >(); using var httpClient = new HttpClient(fakeHttpMessageHandler) { BaseAddress = new Uri("http://SomePathBaseAddress"), }; using var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); var appRegistryService = new AppRegistryService(logger, httpClient, memoryCache); // Act & Assert await Assert.ThrowsAnyAsync <HttpRequestException>(async() => await appRegistryService.SetRegionHealthState(appRegistrationModels.First().Path, appRegistrationModels.First().Regions.First().PageRegion, true)); }
public async Task SetRegionHealthStateSuccess() { // Arrange const bool expectedResult = true; using var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, }; var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse); using var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); var logger = A.Fake <ILogger <AppRegistryService> >(); using var httpClient = new HttpClient(fakeHttpMessageHandler) { BaseAddress = new Uri("http://SomePathBaseAddress"), }; using var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); var appRegistryService = new AppRegistryService(logger, httpClient, memoryCache); // Act var result = await appRegistryService.SetRegionHealthState(appRegistrationModels.First().Path, appRegistrationModels.First().Regions.First().PageRegion, expectedResult); // Assert Assert.Equal(expectedResult, result); }
public async Task SetRegionHealthStateCircuitBreakerException() { // Arrange const bool expectedResult = false; using var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, }; var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); using var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); var logger = A.Fake <ILogger <AppRegistryService> >(); using var httpClient = new HttpClient(fakeHttpMessageHandler) { BaseAddress = new Uri("http://SomePathBaseAddress"), }; A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Throws <BrokenCircuitException>(); var appRegistryService = new AppRegistryService(logger, httpClient); // Act var result = await appRegistryService.SetRegionHealthState(appRegistrationModels.First().Path, appRegistrationModels.First().Regions.First().PageRegion, expectedResult).ConfigureAwait(false); // Assert Assert.Equal(expectedResult, result); }