@@ -88,6 +88,23 @@ public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptio
88
88
}
89
89
}
90
90
91
+ [ Fact ]
92
+ public async Task WriteAsJsonAsyncGeneric_CustomStatusCode_StatusCodeUnchanged ( )
93
+ {
94
+ // Arrange
95
+ var body = new MemoryStream ( ) ;
96
+ var context = new DefaultHttpContext ( ) ;
97
+ context . Response . Body = body ;
98
+
99
+ // Act
100
+ context . Response . StatusCode = StatusCodes . Status418ImATeapot ;
101
+ await context . Response . WriteAsJsonAsync ( 1 ) ;
102
+
103
+ // Assert
104
+ Assert . Equal ( JsonConstants . JsonContentTypeWithCharset , context . Response . ContentType ) ;
105
+ Assert . Equal ( StatusCodes . Status418ImATeapot , context . Response . StatusCode ) ;
106
+ }
107
+
91
108
[ Fact ]
92
109
public async Task WriteAsJsonAsyncGeneric_WithContentType_JsonResponseWithCustomContentType ( )
93
110
{
@@ -223,6 +240,23 @@ public async Task WriteAsJsonAsync_ObjectWithStrings_CamcelCaseAndNotEscaped()
223
240
Assert . Equal ( @"{""stringProperty"":""激光這兩個字是甚麼意思""}" , data ) ;
224
241
}
225
242
243
+ [ Fact ]
244
+ public async Task WriteAsJsonAsync_CustomStatusCode_StatusCodeUnchanged ( )
245
+ {
246
+ // Arrange
247
+ var body = new MemoryStream ( ) ;
248
+ var context = new DefaultHttpContext ( ) ;
249
+ context . Response . Body = body ;
250
+
251
+ // Act
252
+ context . Response . StatusCode = StatusCodes . Status418ImATeapot ;
253
+ await context . Response . WriteAsJsonAsync ( 1 , typeof ( int ) ) ;
254
+
255
+ // Assert
256
+ Assert . Equal ( JsonConstants . JsonContentTypeWithCharset , context . Response . ContentType ) ;
257
+ Assert . Equal ( StatusCodes . Status418ImATeapot , context . Response . StatusCode ) ;
258
+ }
259
+
226
260
public class TestObject
227
261
{
228
262
public string ? StringProperty { get ; set ; }
0 commit comments