public void XmlSerial_IgnoredAttributesShouldNotBeSerialized() { var child = new Class2BeSerialized() { Name = "child", }; var data = new Class2BeSerialized() { Name = "MyName", NameSystemAttribute = "NameSystemAttribute invisible", NameRule = "NameRule invisible", NamePrivateAttribute = "NamePrivateAttribute invisible", Complex = child, ComplexSystemAttribute = child, ComplexPrivateAttribute = child, ComplexRule = child, IgnoredType = new Class2BeIgnored { Name = "Ignored" } }; /* * <Complex name="Root" type="Polenter.Serialization.IgnoredAttributeTests+Class2BeSerialized, SharpSerializer.Tests"> * <Properties> * <Simple name="Name" value="MyName" /> * <Complex name="Complex"> * <Properties> * <Simple name="Name" value="child" /> * <Null name="Complex" /> * </Properties> * </Complex> * </Properties> * </Complex> */ XmlDocument doc = Save(data); // these are serialized Assert.AreEqual(1, doc.SelectNodes("//Simple[@name='Name' and @value='MyName']").Count, "Name=MyName"); Assert.AreEqual(1, doc.SelectNodes("//Complex[@name='Complex']").Count, "Complex"); // these are not serialized Assert.AreEqual(0, doc.SelectNodes("//Simple[@name='NameRule']").Count, "NameRule"); Assert.AreEqual(0, doc.SelectNodes("//Simple[@name='NameSystemAttribute']").Count, "NameSystemAttribute"); Assert.AreEqual(0, doc.SelectNodes("//Simple[@name='NamePrivateAttribute']").Count, "NamePrivateAttribute"); Assert.AreEqual(0, doc.SelectNodes("//Complex[@name='ComplexRule']").Count, "ComplexRule"); Assert.AreEqual(0, doc.SelectNodes("//Complex[@name='ComplexSystemAttribute']").Count, "ComplexSystemAttribute"); Assert.AreEqual(0, doc.SelectNodes("//Complex[@name='ComplexPrivateAttribute']").Count, "ComplexPrivateAttribute"); Assert.AreEqual(0, doc.SelectNodes("//Complex[@name='IgnoredType']").Count, "IgnoredType"); }
public void XmlSerial_IgnoredAttributesShouldNotBeSerialized() { var child = new Class2BeSerialized() { Name = "child", }; var data = new Class2BeSerialized() { Name = "MyName", NameSystemAttribute = "NameSystemAttribute invisible", NameRule = "NameRule invisible", NamePrivateAttribute = "NamePrivateAttribute invisible", Complex = child, ComplexSystemAttribute = child, ComplexPrivateAttribute = child, ComplexRule = child, }; /* <Complex name="Root" type="Polenter.Serialization.IgnoredAttributeTests+Class2BeSerialized, SharpSerializer.Tests"> <Properties> <Simple name="Name" value="MyName" /> <Complex name="Complex"> <Properties> <Simple name="Name" value="child" /> <Null name="Complex" /> </Properties> </Complex> </Properties> </Complex> */ XmlDocument doc = Save(data); // these are serialized Assert.AreEqual(1, doc.SelectNodes("//Simple[@name='Name' and @value='MyName']").Count, "Name=MyName"); Assert.AreEqual(1, doc.SelectNodes("//Complex[@name='Complex']").Count, "Complex"); // these are not serialized Assert.AreEqual(0, doc.SelectNodes("//Simple[@name='NameRule']").Count, "NameRule"); Assert.AreEqual(0, doc.SelectNodes("//Simple[@name='NameSystemAttribute']").Count, "NameSystemAttribute"); Assert.AreEqual(0, doc.SelectNodes("//Simple[@name='NamePrivateAttribute']").Count, "NamePrivateAttribute"); Assert.AreEqual(0, doc.SelectNodes("//Complex[@name='ComplexRule']").Count, "ComplexRule"); Assert.AreEqual(0, doc.SelectNodes("//Complex[@name='ComplexSystemAttribute']").Count, "ComplexSystemAttribute"); Assert.AreEqual(0, doc.SelectNodes("//Complex[@name='ComplexPrivateAttribute']").Count, "ComplexPrivateAttribute"); }