public async Task when_WebApiConflictException_raised_it_should_return_Conflict_http_status_code()
        {
            var conflictController = new ConflictController();

            var result = conflictController.GetConflict();

            var middleware =
                TestHelper.BuildWebApiErrorHandlingMiddleware(innerHttpContext => throw new EntityException());

            var context = new DefaultHttpContext();

            context.Response.Body = new MemoryStream();


            await middleware.Invoke(context);

            context.Response.Body.Seek(0,
                                       SeekOrigin.Begin);
            var reader     = new StreamReader(context.Response.Body);
            var streamText = reader.ReadToEnd();


            var expected = JToken.Parse(result.SerializeToJson());
            var actual   = JToken.Parse(streamText);


            Assert.Equal(HttpStatusCode.Conflict,
                         context.Response.StatusCode.AsEnum <HttpStatusCode>());

            Assert.True(JToken.DeepEquals(actual,
                                          expected));
        }
Example #2
0
        public async Task when_exception_without_webapi_attribute_raised_it_should_rethrow()
        {
            var conflictController = new ConflictController();

            var result = conflictController.GetConflict();

            var middleware =
                TestHelper.BuildWebApiErrorHandlingMiddleware(innerHttpContext => throw new ArgumentException());

            var context = new DefaultHttpContext();

            context.Response.Body = new MemoryStream();


            async Task Act()
            {
                await middleware.Invoke(context);
            }

            await Assert.ThrowsAsync <ArgumentException>(Act);
        }