コード例 #1
0
        public async Task AddMappingDuplicateThrowsInvalidOperationException(
            EntityNotFoundException expectedException,
            HttpResponseMessageBuilder builder,
            ResourceNotFoundApiModel apiModel)
        {
            var addMappings = new Action <HttpResponseExceptionConfiguration>(
                configuration =>
            {
                configuration.AddMapping(
                    HttpStatusCode.NotFound,
                    (r, c) => expectedException);

                configuration.AddMapping(
                    HttpStatusCode.NotFound,
                    (r, c) => expectedException);
            });

            var mapper = new TestHttpResponseExceptionMapper(addMappings);

            var httpResponseMessage = builder
                                      .WithStatusCode(HttpStatusCode.NotFound)
                                      .WithJson(apiModel)
                                      .Build();

            await Assert.ThrowsAsync <InvalidOperationException>(
                () => mapper.GetException(httpResponseMessage));
        }
コード例 #2
0
        public async Task UpdateMappingUpdatesException(
            EntityNotFoundException expectedException,
            EntityNotFoundException exceptionReplacement,
            HttpResponseMessageBuilder builder,
            ResourceNotFoundApiModel apiModel)
        {
            var addMappings = new Action <HttpResponseExceptionConfiguration>(
                configuration =>
            {
                configuration.AddMapping(
                    HttpStatusCode.NotFound,
                    (r, c) => expectedException);

                configuration.UpdateMapping(
                    HttpStatusCode.NotFound,
                    (r, c) => exceptionReplacement);
            });

            var mapper = new TestHttpResponseExceptionMapper(addMappings);

            var httpResponseMessage = builder
                                      .WithStatusCode(HttpStatusCode.NotFound)
                                      .WithJson(apiModel)
                                      .Build();

            var exception = await mapper.GetException(httpResponseMessage);

            Assert.Equal(exceptionReplacement, exception);
        }
コード例 #3
0
        public async Task RemoveMappingRemovesTheExceptionAndReturnsDefaultException(
            EntityNotFoundException expectedException,
            HttpResponseMessageBuilder builder,
            ResourceNotFoundApiModel apiModel)
        {
            var addMappings = new Action <HttpResponseExceptionConfiguration>(
                configuration =>
            {
                configuration.AddMapping(
                    HttpStatusCode.NotFound,
                    (r, c) => expectedException);

                configuration.RemoveMapping(HttpStatusCode.NotFound);
            });

            var mapper = new TestHttpResponseExceptionMapper(addMappings);

            var httpResponseMessage = builder
                                      .WithStatusCode(HttpStatusCode.NotFound)
                                      .WithJson(apiModel)
                                      .Build();

            var exception = await mapper.GetException(httpResponseMessage);

            Assert.Equal(mapper.DefaultException, exception);
        }