File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed
Src/FluentAssertions.Json
Tests/FluentAssertions.Json.Specs Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ namespace FluentAssertions.Json
1212 public static class ObjectAssertionsExtensions
1313 {
1414 /// <summary>
15- /// Asserts that an object can be serialized and deserialized using the JSON serializer and that it stills retains
15+ /// Asserts that an object can be serialized and deserialized using the JSON serializer and that it still retains
1616 /// the values of all members.
1717 /// </summary>
1818 /// <param name="assertions"></param>
Original file line number Diff line number Diff line change 1- namespace FluentAssertions . Json . Specs . Models
1+ using System ;
2+ using Newtonsoft . Json ;
3+
4+ namespace FluentAssertions . Json . Specs . Models
25{
36 // ReSharper disable UnusedMember.Global
47
@@ -8,6 +11,12 @@ public class AddressDto
811 public string AddressLine2 { get ; set ; }
912 public string AddressLine3 { get ; set ; }
1013 }
14+
15+ public class DerivedFromAddressDto : AddressDto
16+ {
17+ [ JsonIgnore ]
18+ public DateTime LastUpdated { get ; set ; }
19+ }
1120 // ReSharper restore UnusedMember.Global
1221
1322}
Original file line number Diff line number Diff line change @@ -108,9 +108,7 @@ public void Should_fail_when_instance_is_null()
108108 // assert
109109 act . Should ( )
110110 . Throw < Xunit . Sdk . XunitException > ( because : "This is consistent with BeBinarySerializable() and BeDataContractSerializable()" )
111- . Which . Message
112- . Should ( ) . Contain ( "value is null" )
113- . And . Contain ( "Please provide a value for the assertion" ) ;
111+ . WithMessage ( "*value is null*Please provide a value for the assertion*" ) ;
114112 }
115113
116114 [ Fact ]
@@ -127,9 +125,20 @@ public void Should_fail_when_subject_is_not_same_type_as_the_specified_generic_t
127125 . Which . Message
128126 . Should ( ) . Contain ( "is not assignable to" )
129127 . And . Contain ( nameof ( SimplePocoWithPrimitiveTypes ) ) ;
130- ;
131128 }
132129
130+ [ Fact ]
131+ public void Should_fail_when_derived_type_is_not_serializable_when_presented_as_base_class ( )
132+ {
133+ // arrange
134+ AddressDto target = _fixture . Create < DerivedFromAddressDto > ( ) ;
135+
136+ // act
137+ Action act = ( ) => target . Should ( ) . BeJsonSerializable ( ) ;
138+
139+ // assert
140+ act . Should ( ) . Throw < Xunit . Sdk . XunitException > ( "The derived class is not serializable due to a JsonIgnore attribute" ) ;
141+ }
133142 }
134143
135144}
You can’t perform that action at this time.
0 commit comments