public void Complete() { using (var context = new UnitTestContext(this)) { var obj = new DerivedTypeSample(); obj.SampleName = "AAA"; obj.DoubleElement = 1.0; obj.IntElement = 1; obj.KeyElement = new BaseTypeSampleKey(); obj.KeyElement.SampleName = "BBB"; obj.NonNullableIntList = new List <int>(); obj.NonNullableIntList.Add(100); obj.NonNullableIntList.Add(200); obj.NullableIntList = new List <int?>(); obj.NullableIntList.Add(100); obj.NullableIntList.Add(null); obj.NullableIntList.Add(300); obj.StringList = new List <string>(); obj.StringList.Add("AAAA"); obj.StringList.Add("BBBB"); obj.KeyList = new List <BaseTypeSampleKey>(); var keyListElement1 = new BaseTypeSampleKey(); obj.KeyList.Add(keyListElement1); keyListElement1.SampleName = "BBB"; var keyListElement2 = new BaseTypeSampleKey(); keyListElement2.SampleName = "BBB"; obj.KeyList.Add(keyListElement2); obj.DataElement = new ElementTypeSample(); obj.DataElement.SampleName = "CCC"; obj.DataElement.DoubleElement = 2.0; obj.DataList = new List <ElementTypeSample>(); var dataListItem1 = new ElementTypeSample(); dataListItem1.SampleName = "DDD"; dataListItem1.DoubleElement = 3.0; obj.DataList.Add(dataListItem1); var dataListItem2 = new ElementTypeSample(); dataListItem2.SampleName = "DDD"; dataListItem2.DoubleElement = 4.0; obj.DataList.Add(dataListItem2); string xmlString = obj.ToXml(); string className = obj.GetType().Name; context.Log.Verify("Original", xmlString); var deserialized = new DerivedTypeSample(); deserialized.ParseXml(xmlString); string deserializedString = deserialized.ToXml(); context.Log.Verify("Copy", deserializedString); context.Log.Assert(xmlString == deserializedString, "Serialization roundtrip assert."); } }
public void Complete() { using (var context = new UnitTestContext(this)) { var obj = new DerivedTypeSample(); obj.SampleName = "AAA"; obj.DoubleElement = 1.0; obj.IntElement = 1; obj.KeyElement = new BaseTypeSampleKey(); obj.KeyElement.SampleName = "BBB"; obj.NonNullableIntList = new List <int>(); obj.NonNullableIntList.Add(100); obj.NonNullableIntList.Add(200); obj.NullableIntList = new List <int?>(); obj.NullableIntList.Add(100); obj.NullableIntList.Add(null); obj.NullableIntList.Add(300); obj.StringList = new List <string>(); obj.StringList.Add("AAAA"); obj.StringList.Add("BBBB"); obj.KeyList = new List <BaseTypeSampleKey>(); var keyListElement1 = new BaseTypeSampleKey(); keyListElement1.SampleName = "BBB"; obj.KeyList.Add(keyListElement1); var keyListElement2 = new BaseTypeSampleKey(); keyListElement2.SampleName = "BBB"; obj.KeyList.Add(keyListElement2); obj.DataElement = new ElementTypeSample(); obj.DataElement.SampleName = "CCC"; obj.DataElement.DoubleElement = 2.0; obj.DataList = new List <ElementTypeSample>(); var dataListItem1 = new ElementTypeSample(); dataListItem1.SampleName = "DDD"; dataListItem1.DoubleElement = 3.0; obj.DataList.Add(dataListItem1); var dataListItem2 = new ElementTypeSample(); dataListItem2.SampleName = "DDD"; dataListItem2.DoubleElement = 4.0; obj.DataList.Add(dataListItem2); string className = obj.GetType().Name; var copy = new DerivedTypeSample(); var copyWriter = new DataTreeWriter(copy); copyWriter.WriteStartDocument(className); ((ITreeSerializable)obj).SerializeTo(copyWriter); copyWriter.WriteEndDocument(className); string xmlString = obj.ToXml(); context.Log.Verify("Original", xmlString); string copyString = copy.ToXml(); context.Log.Verify("Copy", copyString); context.Log.Assert(xmlString == copyString, "Serialization roundtrip assert."); } }