@@ -43,6 +43,38 @@ public async Task ExecuteAsync_UsesDefaults_ForProblemDetails()
43
43
Assert . Equal ( StatusCodes . Status500InternalServerError , responseDetails . Status ) ;
44
44
}
45
45
46
+ [ Fact ]
47
+ public async Task ExecuteAsync_UsesDefaultsFromProblemDetailsServoce_ForProblemDetails ( )
48
+ {
49
+ // Arrange
50
+ var details = new ProblemDetails ( ) ;
51
+
52
+ var result = new ProblemHttpResult ( details ) ;
53
+ var stream = new MemoryStream ( ) ;
54
+ var services = CreateServiceCollection ( )
55
+ . AddProblemDetails ( options => options . CustomizeProblemDetails = x => x . ProblemDetails . Type = null )
56
+ . BuildServiceProvider ( ) ;
57
+ var httpContext = new DefaultHttpContext ( )
58
+ {
59
+ RequestServices = services ,
60
+ Response =
61
+ {
62
+ Body = stream ,
63
+ } ,
64
+ } ;
65
+
66
+ // Act
67
+ await result . ExecuteAsync ( httpContext ) ;
68
+
69
+ // Assert
70
+ Assert . Equal ( StatusCodes . Status500InternalServerError , httpContext . Response . StatusCode ) ;
71
+ stream . Position = 0 ;
72
+ var responseDetails = JsonSerializer . Deserialize < ProblemDetails > ( stream , SerializerOptions ) ;
73
+ Assert . Null ( responseDetails . Type ) ;
74
+ Assert . Equal ( "An error occurred while processing your request." , responseDetails . Title ) ;
75
+ Assert . Equal ( StatusCodes . Status500InternalServerError , responseDetails . Status ) ;
76
+ }
77
+
46
78
[ Fact ]
47
79
public async Task ExecuteAsync_UsesDefaults_ForValidationProblemDetails ( )
48
80
{
@@ -217,11 +249,17 @@ public void ProblemResult_Implements_IContentTypeHttpResult_Correctly()
217
249
Assert . Equal ( "application/problem+json" , result . ContentType ) ;
218
250
}
219
251
220
- private static IServiceProvider CreateServices ( )
252
+ private static IServiceCollection CreateServiceCollection ( )
221
253
{
222
254
var services = new ServiceCollection ( ) ;
223
255
services . AddTransient ( typeof ( ILogger < > ) , typeof ( NullLogger < > ) ) ;
224
256
services . AddSingleton < ILoggerFactory > ( NullLoggerFactory . Instance ) ;
257
+ return services ;
258
+ }
259
+
260
+ private static IServiceProvider CreateServices ( )
261
+ {
262
+ var services = CreateServiceCollection ( ) ;
225
263
226
264
return services . BuildServiceProvider ( ) ;
227
265
}
0 commit comments