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)); }
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); }
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); }