Skip to content

Commit 573f207

Browse files
committed
Added more unit tests for JsonSerializerSettingsTestBuilder.
1 parent 56b1ab6 commit 573f207

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/MyTested.AspNetCore.Mvc.Controllers.Views.ActionResults.Test/BuildersTests/ActionResultsTests/JsonTests/JsonSerializerTestBuilderTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,39 @@ public void WithContractResolverShouldThrowExceptionWithIncorrectValue()
222222
"When calling JsonWithSettingsAction action in MvcController expected JSON result serializer settings to have the same contract resolver as the provided one, but in fact it was different.");
223223
}
224224

225+
[Fact]
226+
public void WithContractResolverOfTypeShouldNotThrowException()
227+
{
228+
var jsonSerializerSettings = TestObjectFactory.GetJsonSerializerSettings();
229+
230+
MyController<MvcController>
231+
.Instance()
232+
.Calling(c => c.JsonWithSpecificSettingsAction(jsonSerializerSettings))
233+
.ShouldReturn()
234+
.Json(json => json
235+
.WithJsonSerializerSettings(s =>
236+
s.WithContractResolverOfType(typeof(CamelCasePropertyNamesContractResolver))));
237+
}
238+
239+
[Fact]
240+
public void WithContractResolverOfTypeShouldThrowException()
241+
{
242+
var jsonSerializerSettings = TestObjectFactory.GetJsonSerializerSettings();
243+
244+
Test.AssertException<JsonResultAssertionException>(
245+
() =>
246+
{
247+
MyController<MvcController>
248+
.Instance()
249+
.Calling(c => c.JsonWithSpecificSettingsAction(jsonSerializerSettings))
250+
.ShouldReturn()
251+
.Json(json => json
252+
.WithJsonSerializerSettings(s =>
253+
s.WithContractResolverOfType(typeof(IContractResolver))));
254+
},
255+
"When calling JsonWithSpecificSettingsAction action in MvcController expected JSON result serializer settings to have IContractResolver, but in fact found CamelCasePropertyNamesContractResolver.");
256+
}
257+
225258
[Fact]
226259
public void WithoutContractResolverOfTypeShouldThrowException()
227260
{

0 commit comments

Comments
 (0)