public void Basic() { using (var context = new UnitTestContext(this)) { var obj = new BaseTypeSample(); obj.SampleName = "ABC"; obj.DoubleElement = 1.0; string xmlString = obj.ToXml(); string className = obj.GetType().Name; context.Log.Verify("Original", xmlString); var copy = new BaseTypeSample(); var copyWriter = new DataTreeWriter(copy); copyWriter.WriteStartDocument(className); ((ITreeSerializable)obj).SerializeTo(copyWriter); copyWriter.WriteEndDocument(className); string copyString = copy.ToXml(); context.Log.Verify("Copy", copyString); context.Log.Assert(xmlString == copyString, "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."); } }