public async Task Invoke_WhenNoExceptionThrown_MiddlewareTakesNoAction()
        {
            var objectUnderTest = new ExceptionHandler(DoNothing);
            var inputContext    = new StubHttpContext();

            await objectUnderTest.Invoke(inputContext);

            //No exception thrown
        }
        public async Task Invoke_WhenNonGatewayExceptionThrown_ExceptionNotCaught()
        {
            var objectUnderTest = new ExceptionHandler(ThrowException);
            var inputContext    = new StubHttpContext();

            await objectUnderTest.Invoke(inputContext);

            //Expect exception
        }
示例#3
0
        public async Task Invoke_WhenNonGatewayExceptionThrown_ExceptionNotCaught()
        {
            var objectUnderTest = new ExceptionHandler(ThrowException);
            var inputContext    = new StubHttpContext();

            await objectUnderTest.Invoke(inputContext).ConfigureAwait(continueOnCapturedContext: false);

            //Expect exception
        }
        public async Task Invoke_WhenGatewayExceptionThrown_ErrorWrittenToResponse()
        {
            var objectUnderTest = new ExceptionHandler(ThrowFakeGatewayException);
            var inputContext    = new StubHttpContext();

            await objectUnderTest.Invoke(inputContext);

            Assert.AreEqual(FakeGatewayStatusCode, inputContext.Response.StatusCode);
            Assert.AreEqual("{\"error\":\"Test Gateway Exception\"}", ((StubHttpResponse)inputContext.Response).ReadBody());
            Assert.AreEqual("application/json", inputContext.Response.ContentType);
        }