@@ -12,7 +12,6 @@ namespace PartialResponse.AspNetCore.Mvc.Formatters.Json
1212{
1313 public class PartialJsonOutputFormatterTests
1414 {
15- private readonly PartialJsonOutputFormatter formatter ;
1615 private readonly HttpContext httpContext = Mock . Of < HttpContext > ( ) ;
1716 private readonly HttpRequest httpRequest = Mock . Of < HttpRequest > ( ) ;
1817 private readonly HttpResponse httpResponse = Mock . Of < HttpResponse > ( ) ;
@@ -32,8 +31,6 @@ public PartialJsonOutputFormatterTests()
3231 Mock . Get ( this . httpContext )
3332 . SetupGet ( httpContext => httpContext . Response )
3433 . Returns ( this . httpResponse ) ;
35-
36- this . formatter = new PartialJsonOutputFormatter ( new JsonSerializerSettings ( ) , Mock . Of < ArrayPool < char > > ( ) ) ;
3734 }
3835
3936 [ Fact ]
@@ -49,9 +46,10 @@ public async Task TheWriteResponseBodyAsyncMethodShouldReturnStatusCode400IfFiel
4946 . Returns ( "foo/" ) ;
5047
5148 var writeContext = new OutputFormatterWriteContext ( this . httpContext , ( stream , encoding ) => new StringWriter ( this . body ) , typeof ( object ) , new { } ) ;
49+ var formatter = new PartialJsonOutputFormatter ( new JsonSerializerSettings ( ) , Mock . Of < ArrayPool < char > > ( ) , false ) ;
5250
5351 // Act
54- await this . formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
52+ await formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
5553
5654 // Assert
5755 Mock . Get ( this . httpResponse )
@@ -71,9 +69,10 @@ public async Task TheWriteResponseBodyAsyncMethodShouldNotWriteBodyIfFieldsMalfo
7169 . Returns ( "foo/" ) ;
7270
7371 var writeContext = new OutputFormatterWriteContext ( this . httpContext , ( stream , encoding ) => new StringWriter ( this . body ) , typeof ( object ) , new { } ) ;
72+ var formatter = new PartialJsonOutputFormatter ( new JsonSerializerSettings ( ) , Mock . Of < ArrayPool < char > > ( ) , false ) ;
7473
7574 // Act
76- await this . formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
75+ await formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
7776
7877 // Assert
7978 Assert . Equal ( 0 , this . body . Length ) ;
@@ -90,9 +89,10 @@ public async Task TheWriteResponseBodyAsyncMethodShouldNotApplyFieldsIfNotSuppli
9089 var value = new { foo = "bar" } ;
9190
9291 var writeContext = new OutputFormatterWriteContext ( this . httpContext , ( stream , encoding ) => new StringWriter ( this . body ) , typeof ( object ) , value ) ;
92+ var formatter = new PartialJsonOutputFormatter ( new JsonSerializerSettings ( ) , Mock . Of < ArrayPool < char > > ( ) , false ) ;
9393
9494 // Act
95- await this . formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
95+ await formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
9696
9797 // Assert
9898 Assert . Equal ( "{\" foo\" :\" bar\" }" , this . body . ToString ( ) ) ;
@@ -113,12 +113,61 @@ public async Task TheWriteResponseBodyAsyncMethodShouldApplyFieldsIfSupplied()
113113 var value = new { foo = "bar" , baz = "qux" } ;
114114
115115 var writeContext = new OutputFormatterWriteContext ( this . httpContext , ( stream , encoding ) => new StringWriter ( this . body ) , typeof ( object ) , value ) ;
116+ var formatter = new PartialJsonOutputFormatter ( new JsonSerializerSettings ( ) , Mock . Of < ArrayPool < char > > ( ) , false ) ;
117+
118+ // Act
119+ await formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
120+
121+ // Assert
122+ Assert . Equal ( "{\" foo\" :\" bar\" }" , this . body . ToString ( ) ) ;
123+ }
124+
125+ [ Fact ]
126+ public async Task TheWriteResponseBodyAsyncMethodShouldIgnoreCase ( )
127+ {
128+ // Arrange
129+ Mock . Get ( this . queryCollection )
130+ . Setup ( queryCollection => queryCollection . ContainsKey ( "fields" ) )
131+ . Returns ( true ) ;
132+
133+ Mock . Get ( this . queryCollection )
134+ . SetupGet ( queryCollection => queryCollection [ "fields" ] )
135+ . Returns ( "FOO" ) ;
136+
137+ var value = new { foo = "bar" } ;
138+
139+ var writeContext = new OutputFormatterWriteContext ( this . httpContext , ( stream , encoding ) => new StringWriter ( this . body ) , typeof ( object ) , value ) ;
140+ var formatter = new PartialJsonOutputFormatter ( new JsonSerializerSettings ( ) , Mock . Of < ArrayPool < char > > ( ) , true ) ;
116141
117142 // Act
118- await this . formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
143+ await formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
119144
120145 // Assert
121146 Assert . Equal ( "{\" foo\" :\" bar\" }" , this . body . ToString ( ) ) ;
122147 }
148+
149+ [ Fact ]
150+ public async Task TheWriteResponseBodyAsyncMethodShouldNotIgnoreCase ( )
151+ {
152+ // Arrange
153+ Mock . Get ( this . queryCollection )
154+ . Setup ( queryCollection => queryCollection . ContainsKey ( "fields" ) )
155+ . Returns ( true ) ;
156+
157+ Mock . Get ( this . queryCollection )
158+ . SetupGet ( queryCollection => queryCollection [ "fields" ] )
159+ . Returns ( "FOO" ) ;
160+
161+ var value = new { foo = "bar" } ;
162+
163+ var writeContext = new OutputFormatterWriteContext ( this . httpContext , ( stream , encoding ) => new StringWriter ( this . body ) , typeof ( object ) , value ) ;
164+ var formatter = new PartialJsonOutputFormatter ( new JsonSerializerSettings ( ) , Mock . Of < ArrayPool < char > > ( ) , false ) ;
165+
166+ // Act
167+ await formatter . WriteResponseBodyAsync ( writeContext , Encoding . UTF8 ) ;
168+
169+ // Assert
170+ Assert . Equal ( "{}" , this . body . ToString ( ) ) ;
171+ }
123172 }
124173}
0 commit comments