public async Task CheckWebhookCall(EventHandlerConfig config, MessageData messageData, string expectedUri, string expectedContent) { var mockHttpHandler = new MockHttpMessageHandler(); var mockWebHookRequestWithCallback = mockHttpHandler.When(HttpMethod.Post, expectedUri) .WithContentType("application/json", expectedContent) .Respond(HttpStatusCode.OK, "application/json", "{\"msg\":\"Hello World\"}"); var httpClient = mockHttpHandler.ToHttpClient(); var mockAuthHandler = new Mock <IAcquireTokenHandler>(); var mockBigBrother = new Mock <IBigBrother>(); var mockHandlerFactory = new Mock <IEventHandlerFactory>(); mockHandlerFactory.Setup(s => s.CreateWebhookHandler(config.CallbackConfig.Name)).Returns( new GenericWebhookHandler( mockAuthHandler.Object, new RequestBuilder(), mockBigBrother.Object, httpClient, config.CallbackConfig)); var webhookResponseHandler = new WebhookResponseHandler( mockHandlerFactory.Object, mockAuthHandler.Object, new RequestBuilder(), mockBigBrother.Object, httpClient, config); await webhookResponseHandler.Call(messageData); mockAuthHandler.Verify(e => e.GetToken(It.IsAny <HttpClient>()), Times.Exactly(1)); Assert.Equal(1, mockHttpHandler.GetMatchCount(mockWebHookRequestWithCallback)); }
public async Task BadCheckMultiRouteSelection(EventHandlerConfig config, MessageData messageData, string expectedWebHookUri, string expectedContent) { var mockHttpHandler = new MockHttpMessageHandler(); var multiRouteCall = mockHttpHandler.When(HttpMethod.Post, expectedWebHookUri) .WithContentType("application/json; charset=utf-8", expectedContent) .Respond(HttpStatusCode.OK, "application/json", "{\"msg\":\"Hello World\"}"); var httpClient = mockHttpHandler.ToHttpClient(); var mockAuthHandler = new Mock <IAcquireTokenHandler>(); var mockBigBrother = new Mock <IBigBrother>(); var mockHandlerFactory = new Mock <IEventHandlerFactory>(); mockHandlerFactory.Setup(s => s.CreateWebhookHandler(config.CallbackConfig.Name)).Returns( new GenericWebhookHandler( mockAuthHandler.Object, new RequestBuilder(), mockBigBrother.Object, httpClient, config.CallbackConfig)); var webhookResponseHandler = new WebhookResponseHandler( mockHandlerFactory.Object, mockAuthHandler.Object, new RequestBuilder(), mockBigBrother.Object, httpClient, config); await Assert.ThrowsAsync <Exception>(async() => await webhookResponseHandler.Call(messageData)); }