public void TestOmitComplexWithoutOmitToXElement() { var omitComplexWithoutOmitClass = OmitComplexWithoutOmitClassImpl; omitComplexWithoutOmitClass.NullSimpleSingleSerializationClass = null; var result = omitComplexWithoutOmitClass.ExportAsXElement(); Assert.True(XNode.DeepEquals(XElement.Parse(ComparisonValues.OmitComplexWithoutOmit), result)); var deserialized = OmitComplexWithoutOmitClass.Import(result); // We know, that there is a default instance of the NullSimpleSingleSerializationClass, since it was not omitted // (see comment in the test case above). By explicitely setting it back to null, it should equal. deserialized.NullSimpleSingleSerializationClass = null; Assert.True(omitComplexWithoutOmitClass.DeepEquals(deserialized, nameof(IZenonSerializable.ObjectStatus))); }
public void TestOmitComplexWithoutOmitToString() { var omitComplexWithoutOmitClass = OmitComplexWithoutOmitClassImpl; omitComplexWithoutOmitClass.NullSimpleSingleSerializationClass = null; var result = omitComplexWithoutOmitClass.ExportAsString(); Assert.Equal(ComparisonValues.OmitComplexWithoutOmit, result); var deserialized = OmitComplexWithoutOmitClass.Import(XElement.Parse(result)); // Those cannot be the same, since if a type is not omitted when being null, then it is added to the XML. // Example: MyType { MyNestedType = null } --> <MyType><MyNestedType/></MyType> // Reading it back: MyNestedType will not be null, but an unmodified default instance of MyNestedType Assert.False(omitComplexWithoutOmitClass.DeepEquals(deserialized, nameof(IZenonSerializable.ObjectStatus))); // Here, the NullSimpleSingleSerializationClass entry is also ignored, therefore the contents should match again. Assert.True(omitComplexWithoutOmitClass.DeepEquals( deserialized, nameof(IZenonSerializable.ObjectStatus), nameof(OmitComplexWithoutOmitClass.NullSimpleSingleSerializationClass))); }