Skip to content

Commit 05c2513

Browse files
author
Matthew Thornton
committed
Add test for domain exception filter for case when custom mapper returns null.
1 parent 10e7aba commit 05c2513

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

test/Winton.DomainModelling.AspNetCore.Tests/DomainExceptionFilterTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ public sealed class OnException : DomainExceptionFilterTests
3838
}
3939
};
4040

41+
[Fact]
42+
private void ShouldDefaultToBadRequestResultIfCustomMapperReturnsNull()
43+
{
44+
var exceptionContext =
45+
new ExceptionContext(
46+
new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
47+
new List<IFilterMetadata>())
48+
{
49+
Exception = new DomainException("Foo")
50+
};
51+
var filter = new DomainExceptionFilter((exception, response) => null);
52+
53+
filter.OnException(exceptionContext);
54+
55+
exceptionContext.Result.Should().BeEquivalentTo(
56+
new BadRequestObjectResult(new ErrorResponse(new DomainException("Foo"))));
57+
}
58+
4159
[Fact]
4260
private void ShouldNotSetResultIfNotATypeOfDomainException()
4361
{

0 commit comments

Comments
 (0)