public void SerializeToBinary()
    {
      ChildBusinessList result;
      var list = ChildBusinessList.GetEditableRootList(1);

      System.IO.File.Delete("c:\\temp\\test3.xml");

      Assert.AreEqual(typeof(ChildType1), list[0].GetType());
      Assert.AreEqual(typeof(ChildType2), list[1].GetType());

      var serialized = MobileFormatter.SerializeToDTO(list);
      var writer = new CslaBinaryWriter();
      var streamOut = new System.IO.FileStream("c:\\temp\\test3.xml", FileMode.OpenOrCreate);
      writer.Write(streamOut, serialized);
      streamOut.Close();

      Thread.Sleep(500);

      var streamIn = new System.IO.FileStream("c:\\temp\\test3.xml", FileMode.Open);
      var reader = new CslaBinaryReader();
      var deserialized = reader.Read(streamIn);
      result = (ChildBusinessList)MobileFormatter.DeserializeFromDTO(deserialized);

      Assert.AreEqual(list.Count, result.Count);
    }
Beispiel #2
0
		public void TestSerializationCslaBinaryReaderWriter()
		{
			UnitTestContext context = GetContext();

			var test = new BinaryReaderWriterTestClass();
			BinaryReaderWriterTestClass result;
			test.Setup();
			var serialized = MobileFormatter.SerializeToDTO(test);
			CslaBinaryWriter writer = new CslaBinaryWriter();
			byte[] data;
			using (var stream = new MemoryStream())
			{
				writer.Write(stream, serialized);
				data = stream.ToArray();
			}

			CslaBinaryReader reader = new CslaBinaryReader();
			using (var stream = new MemoryStream(data))
			{
				var deserialized = reader.Read(stream);
				result = (BinaryReaderWriterTestClass)MobileFormatter.DeserializeFromDTO(deserialized);
			}
			context.Assert.AreEqual(test.BoolTest, result.BoolTest);
			context.Assert.AreEqual(test.ByteArrayTest.Length, result.ByteArrayTest.Length);
			for (int i = 0; i < test.ByteArrayTest.Length; i++)
			{
				context.Assert.AreEqual(test.ByteArrayTest[i], result.ByteArrayTest[i]);
			}

			context.Assert.AreEqual(test.ByteTest, result.ByteTest);
			context.Assert.AreEqual(test.CharArrayTest.Length, result.CharArrayTest.Length);
			for (int i = 0; i < test.CharArrayTest.Length; i++)
			{
				context.Assert.AreEqual(test.CharArrayTest[i], result.CharArrayTest[i]);
			}

			context.Assert.AreEqual(test.CharTest, result.CharTest);
			context.Assert.AreEqual(test.DateTimeOffsetTest, result.DateTimeOffsetTest);
			context.Assert.AreEqual(test.DateTimeTest, result.DateTimeTest);
			context.Assert.AreEqual(test.DecimalTest, result.DecimalTest);
			context.Assert.AreEqual(test.DoubleTest, result.DoubleTest);
			context.Assert.AreEqual(test.EnumTest, result.EnumTest);
			context.Assert.AreEqual(test.GuidTest, result.GuidTest);
			context.Assert.AreEqual(test.Int16Test, result.Int16Test);
			context.Assert.AreEqual(test.Int32Test, result.Int32Test);
			context.Assert.AreEqual(test.Int64Test, result.Int64Test);
			context.Assert.AreEqual(test.SByteTest, result.SByteTest);
			context.Assert.AreEqual(test.SingleTest, result.SingleTest);
			context.Assert.AreEqual(test.StringTest, result.StringTest);
			context.Assert.AreEqual(test.TimeSpanTest, result.TimeSpanTest);
			context.Assert.AreEqual(test.UInt16Test, result.UInt16Test);
			context.Assert.AreEqual(test.UInt32Test, result.UInt32Test);
			context.Assert.AreEqual(test.UInt64Test, result.UInt64Test);
			context.Assert.AreEqual(test.NullableButSetInt, result.NullableButSetInt);
			context.Assert.IsNull(test.NullableInt);
			context.Assert.IsNull(result.NullableInt);

			context.Assert.AreEqual(test.EmptySmartDateTest, result.EmptySmartDateTest);
			context.Assert.AreEqual(test.EmptySmartDateTest.FormatString, result.EmptySmartDateTest.FormatString);
			context.Assert.AreEqual(test.EmptySmartDateTest.EmptyIsMin, result.EmptySmartDateTest.EmptyIsMin);
			context.Assert.AreEqual(test.EmptySmartDateTest.IsEmpty, result.EmptySmartDateTest.IsEmpty);
			context.Assert.AreEqual(test.EmptySmartDateTest.Date, result.EmptySmartDateTest.Date);

			context.Assert.AreEqual(test.FilledSmartDateTest, result.FilledSmartDateTest);
			context.Assert.AreEqual(test.FilledSmartDateTest.FormatString, result.FilledSmartDateTest.FormatString);
			context.Assert.AreEqual(test.FilledSmartDateTest.EmptyIsMin, result.FilledSmartDateTest.EmptyIsMin);
			context.Assert.AreEqual(test.FilledSmartDateTest.IsEmpty, result.FilledSmartDateTest.IsEmpty);
			context.Assert.AreEqual(test.FilledSmartDateTest.Date, result.FilledSmartDateTest.Date);

			context.Assert.Success();
			context.Complete();
		}