public async Task when_subscriber_return_unhautorized_it_should_log_an_error() { _searchApiOptionsMock.Setup(x => x.Value).Returns(new SearchApiOptions().AddWebHook("test", "http://test:1234")); var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); handlerMock .Protected() // Setup the PROTECTED method to mock .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("worked!"), }) .Verifiable(); var httpClient = new HttpClient(handlerMock.Object); _sut = new WebHookNotifierSearchEventStatus(httpClient, _searchApiOptionsMock.Object, _loggerMock.Object, _deepSearchServiceMock.Object); Assert.ThrowsAsync <Exception>(async() => await _sut.NotifyEventAsync(fakePersonSearchStatus.SearchRequestKey, fakePersonSearchStatus, "Accepted", CancellationToken.None)); //var expectedUri = new Uri($"http://test:1234/Accepted/{fakePersonSearchStatus.SearchRequestKey}"); //handlerMock.Protected().Verify( // "SendAsync", // Times.Exactly(1), // ItExpr.Is<HttpRequestMessage>(req => // req.Method == HttpMethod.Post // && req.RequestUri == expectedUri // to this uri // ), // ItExpr.IsAny<CancellationToken>() //); //_loggerMock.VerifyLog(LogLevel.Error, $"The webHook PersonSearch notification has not executed status Accepted successfully for test webHook. The error code is 401.", "failed log error"); }