示例#1
0
        public async Task MarkRegionAsHealthyReturnsAppropriateResponseWhenPatchMessageSent(bool success, HttpStatusCode statusCode)
        {
            // Arrange
            var httpClientFactory = A.Fake <IHttpClientFactory>();

            using var httpResponse = new HttpResponseMessage { StatusCode = statusCode };
            var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>();
            var fakeILogger           = A.Fake <ILogger <AppRegistryService> >();

            using var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender);
            using var httpClient             = new HttpClient(fakeHttpMessageHandler)
                  {
                      BaseAddress = new Uri("http://baseaddress.com")
                  };

            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse);
            A.CallTo(() => httpClientFactory.CreateClient(A <string> .Ignored)).Returns(httpClient);

            var appRegistryService = new AppRegistryService(httpClientFactory, fakeILogger);

            // Act
            var response = await appRegistryService.MarkRegionAsHealthy("path1", PageRegion.Body).ConfigureAwait(false);

            // Assert
            Assert.Equal(success, response);
        }
示例#2
0
        public async Task MarkRegionAsHealthyCatchesExceoptionTest()
        {
            // Arrange
            var httpClientFactory = A.Fake <IHttpClientFactory>();
            var fakeILogger       = A.Fake <ILogger <AppRegistryService> >();

            A.CallTo(() => httpClientFactory.CreateClient(A <string> .Ignored)).Throws <HttpRequestException>();

            var appRegistryService = new AppRegistryService(httpClientFactory, fakeILogger);

            // Act
            var response = await appRegistryService.MarkRegionAsHealthy("path1", PageRegion.Body).ConfigureAwait(false);

            // Assert
            Assert.False(response);
        }