@@ -51,6 +51,31 @@ public void ProblemDetailsInvalidModelStateResponse_ReturnsBadRequestWithProblem
51
51
Assert . Equal ( "https://tools.ietf.org/html/rfc7231#section-6.5.1" , problemDetails . Type ) ;
52
52
}
53
53
54
+ [ Fact ]
55
+ public void ProblemDetailsInvalidModelStateResponse_UsesUserConfiguredLink ( )
56
+ {
57
+ // Arrange
58
+ var link = "http://mylink" ;
59
+ var actionContext = new ActionContext
60
+ {
61
+ HttpContext = new DefaultHttpContext { TraceIdentifier = "42" } ,
62
+ } ;
63
+
64
+ var factory = GetInvalidModelStateResponseFactory ( options => options . ClientErrorMapping [ 400 ] . Link = link ) ;
65
+
66
+ // Act
67
+ var result = factory ( actionContext ) ;
68
+
69
+ // Assert
70
+ var badRequest = Assert . IsType < BadRequestObjectResult > ( result ) ;
71
+ Assert . Equal ( new [ ] { "application/problem+json" , "application/problem+xml" } , badRequest . ContentTypes . OrderBy ( c => c ) ) ;
72
+
73
+ var problemDetails = Assert . IsType < ValidationProblemDetails > ( badRequest . Value ) ;
74
+ Assert . Equal ( 400 , problemDetails . Status ) ;
75
+ Assert . Equal ( "One or more validation errors occurred." , problemDetails . Title ) ;
76
+ Assert . Equal ( link , problemDetails . Type ) ;
77
+ }
78
+
54
79
[ Fact ]
55
80
public void ProblemDetailsInvalidModelStateResponse_SetsTraceId ( )
56
81
{
@@ -92,12 +117,16 @@ public void ProblemDetailsInvalidModelStateResponse_SetsTraceIdFromRequest_IfAct
92
117
Assert . Equal ( "42" , problemDetails . Extensions [ "traceId" ] ) ;
93
118
}
94
119
95
- private static Func < ActionContext , IActionResult > GetInvalidModelStateResponseFactory ( )
120
+ private static Func < ActionContext , IActionResult > GetInvalidModelStateResponseFactory ( Action < ApiBehaviorOptions > configure = null )
96
121
{
97
122
var options = new ApiBehaviorOptions ( ) ;
98
123
var setup = new ApiBehaviorOptionsSetup ( ) ;
99
124
100
125
setup . Configure ( options ) ;
126
+ if ( configure != null )
127
+ {
128
+ configure ( options ) ;
129
+ }
101
130
102
131
var factory = options . InvalidModelStateResponseFactory ;
103
132
return factory ;
0 commit comments