public void RoundTrip() { var data = new TestData { TestBool = true, TestByteArray = new byte[] { 0x00, 0x02, 0x04, 0x05, 0x01 }, TestDouble = 7.0, TestByte = 0xff, TestDateTime = new DateTime(2089, 9, 27), TestInt = 7, TestList = new List<int> { 4, 55, 4, 6, 7 }, TestLong = 777, TestShort = 456, TestString = "Hello World!", TestChar = 'R', TestDecimal = 100, TestsByte = 0x05, TestuInt = 80, DontGo = 42, Children = new List<SubTestData> { new SubTestData { Name = "one" }, new SubTestData { Name = "two" } } }; foreach (var serializer in Serializers) { using (var stream = new MemoryStream()) { serializer.Serialize(stream, data); stream.Position = 0; var result = serializer.Deserialize<TestData>(stream); VerifyEqual(data, result); } using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { serializer.Serialize(writer, data); writer.Flush(); stream.Position = 0; using (var reader = new StreamReader(stream)) { var result = serializer.Deserialize<TestData>(reader); VerifyEqual(data, result); } } var str = serializer.Serialize(data); var result2 = serializer.Deserialize<TestData>(str); VerifyEqual(data, result2); var clone = serializer.DeepClone(data); VerifyEqual(data, clone); } }
private void VerifyEqual(TestData data, TestData result) { Assert.Equal(data.Children, result.Children); Assert.NotEqual(data.DontGo, result.DontGo); Assert.Equal(data.TestBool, result.TestBool); Assert.Equal(data.TestByte, result.TestByte); Assert.Equal(data.TestByteArray, result.TestByteArray); Assert.Equal(data.TestChar, result.TestChar); Assert.Equal(data.TestDateTime, result.TestDateTime); Assert.Equal(data.TestDecimal, result.TestDecimal); Assert.Equal(data.TestDouble, result.TestDouble); Assert.Equal(data.TestInt, result.TestInt); Assert.Equal(data.TestList, result.TestList); Assert.Equal(data.TestLong, result.TestLong); Assert.Equal(data.TestShort, result.TestShort); Assert.Equal(data.TestString, result.TestString); Assert.Equal(data.TestuInt, result.TestuInt); }