示例#1
0
        public void MissingParameters400Result()
        {
            var mockFactory = new Mock <IHttpClientFactory>();

            mockFactory
            .Setup(m => m.CreateClient(It.IsAny <string>()))
            .Returns(new HttpClient(new StubMessageHandler("{\"result\": \"I don't know\"}")));
            var controller       = new ExampleController(mockFactory.Object);
            var resultTask       = controller.GetDefinition(new Dictionary <string, string>());
            var result           = resultTask.Result;
            var badRequestResult = Assert.IsType <BadRequestResult>(result);
            // if particular response body is required, check it here
        }
示例#2
0
        public void BadUpstreamResponse502Result()
        {
            var mockFactory = new Mock <IHttpClientFactory>();

            mockFactory
            .Setup(m => m.CreateClient(It.IsAny <string>()))
            .Returns(new HttpClient(new StubMessageHandler("{\"result\": \"I don't know\"}", HttpStatusCode.BadRequest)));
            var controller = new ExampleController(mockFactory.Object);
            var resultTask = controller.GetDefinition(new Dictionary <string, string> {
                { "w", "set" }
            });
            var result       = resultTask.Result;
            var objectResult = Assert.IsType <ObjectResult>(result);

            Assert.Equal((int)HttpStatusCode.BadGateway, objectResult.StatusCode);
            // if particular response body is required, check it here
        }