Skip to content

Commit 940a211

Browse files
committed
Added OfType method tests in JsonSerializerTestBuilderTests (#148)
1 parent f6915d1 commit 940a211

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public void ContainingConverterShouldThrowExceptionWithIncorrectValue()
368368
}
369369

370370
[Fact]
371-
public void ContainingConverterOfTypeShouldNotThrowExceptionWithCorrectValue()
371+
public void ContainingConverterOfTypeShouldNotThrowExceptionWithCorrectValueForGeneric()
372372
{
373373
var jsonSerializerSettings = TestObjectFactory.GetJsonSerializerSettings();
374374
var jsonConverter = new CustomJsonConverter();
@@ -385,7 +385,24 @@ public void ContainingConverterOfTypeShouldNotThrowExceptionWithCorrectValue()
385385
}
386386

387387
[Fact]
388-
public void ContainingConverterOfTypeShouldThrowExceptionWithIncorrectValue()
388+
public void ContainingConverterOfTypeShouldNotThrowExceptionWithCorrectValue()
389+
{
390+
var jsonSerializerSettings = TestObjectFactory.GetJsonSerializerSettings();
391+
var jsonConverter = new CustomJsonConverter();
392+
jsonSerializerSettings.Converters.Add(jsonConverter);
393+
394+
MyController<MvcController>
395+
.Instance()
396+
.WithoutValidation()
397+
.Calling(c => c.JsonWithSpecificSettingsAction(jsonSerializerSettings))
398+
.ShouldReturn()
399+
.Json(json => json
400+
.WithJsonSerializerSettings(s =>
401+
s.ContainingConverterOfType(typeof(CustomJsonConverter))));
402+
}
403+
404+
[Fact]
405+
public void ContainingConverterOfTypeShouldThrowExceptionWithIncorrectValueForGeneric()
389406
{
390407
var jsonSerializerSettings = TestObjectFactory.GetJsonSerializerSettings();
391408

@@ -404,6 +421,26 @@ public void ContainingConverterOfTypeShouldThrowExceptionWithIncorrectValue()
404421
"When calling JsonWithSpecificSettingsAction action in MvcController expected JSON result serializer settings to have converter of CustomJsonConverter type, but such was not found.");
405422
}
406423

424+
[Fact]
425+
public void ContainingConverterOfTypeShouldThrowExceptionWithIncorrectValue()
426+
{
427+
var jsonSerializerSettings = TestObjectFactory.GetJsonSerializerSettings();
428+
429+
Test.AssertException<JsonResultAssertionException>(
430+
() =>
431+
{
432+
MyController<MvcController>
433+
.Instance()
434+
.WithoutValidation()
435+
.Calling(c => c.JsonWithSpecificSettingsAction(jsonSerializerSettings))
436+
.ShouldReturn()
437+
.Json(json => json
438+
.WithJsonSerializerSettings(s =>
439+
s.ContainingConverterOfType(typeof(CustomJsonConverter))));
440+
},
441+
"When calling JsonWithSpecificSettingsAction action in MvcController expected JSON result serializer settings to have converter of CustomJsonConverter type, but such was not found.");
442+
}
443+
407444
[Fact]
408445
public void ContainingConvertersShouldNotThrowExceptionWithCorrectValue()
409446
{

0 commit comments

Comments
 (0)