Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void TestSerializationCslaBinaryReaderWriterList()
        {
            var test = new BinaryReaderWriterTestClassList();
            BinaryReaderWriterTestClassList 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 = (BinaryReaderWriterTestClassList)MobileFormatter.DeserializeFromDTO(deserialized);
            }

            Assert.AreEqual(test.Count, result.Count);
            for (int i = 0; i < test.Count; i++)
            {
                Assert.AreEqual(test[i].CharTest, result[i].CharTest);
                Assert.AreEqual(test[i].DateTimeOffsetTest, result[i].DateTimeOffsetTest);
                Assert.AreEqual(test[i].DateTimeTest, result[i].DateTimeTest);
                Assert.AreEqual(test[i].DecimalTest, result[i].DecimalTest);
                Assert.AreEqual(test[i].DoubleTest, result[i].DoubleTest);
                Assert.AreEqual(test[i].EnumTest, result[i].EnumTest);
                Assert.AreEqual(test[i].GuidTest, result[i].GuidTest);
                Assert.AreEqual(test[i].Int16Test, result[i].Int16Test);
                Assert.AreEqual(test[i].Int32Test, result[i].Int32Test);
                Assert.AreEqual(test[i].Int64Test, result[i].Int64Test);
                Assert.AreEqual(test[i].SByteTest, result[i].SByteTest);
                Assert.AreEqual(test[i].SingleTest, result[i].SingleTest);
                Assert.AreEqual(test[i].StringTest, result[i].StringTest);
                Assert.AreEqual(test[i].TimeSpanTest, result[i].TimeSpanTest);
                Assert.AreEqual(test[i].UInt16Test, result[i].UInt16Test);
                Assert.AreEqual(test[i].UInt32Test, result[i].UInt32Test);
                Assert.AreEqual(test[i].UInt64Test, result[i].UInt64Test);

                Assert.AreEqual(test[i].EmptySmartDateTest, result[i].EmptySmartDateTest);
                Assert.AreEqual(test[i].EmptySmartDateTest.FormatString, result[i].EmptySmartDateTest.FormatString);
                Assert.AreEqual(test[i].EmptySmartDateTest.EmptyIsMin, result[i].EmptySmartDateTest.EmptyIsMin);
                Assert.AreEqual(test[i].EmptySmartDateTest.IsEmpty, result[i].EmptySmartDateTest.IsEmpty);
                Assert.AreEqual(test[i].EmptySmartDateTest.Date, result[i].EmptySmartDateTest.Date);

                Assert.AreEqual(test[i].FilledSmartDateTest, result[i].FilledSmartDateTest);
                Assert.AreEqual(test[i].FilledSmartDateTest.FormatString, result[i].FilledSmartDateTest.FormatString);
                Assert.AreEqual(test[i].FilledSmartDateTest.EmptyIsMin, result[i].FilledSmartDateTest.EmptyIsMin);
                Assert.AreEqual(test[i].FilledSmartDateTest.IsEmpty, result[i].FilledSmartDateTest.IsEmpty);
                Assert.AreEqual(test[i].FilledSmartDateTest.Date, result[i].FilledSmartDateTest.Date);
            }
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        public void TestSerializationCslaBinaryReaderWriter()
        {
            IDataPortal <BinaryReaderWriterTestClass> dataPortal = _testDIContext.CreateDataPortal <BinaryReaderWriterTestClass>();

            var test = BinaryReaderWriterTestClass.NewBinaryReaderWriterTestClass(dataPortal);
            BinaryReaderWriterTestClass result;

            test.Setup();
            ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();

            MobileFormatter  formatter  = new MobileFormatter(applicationContext);
            var              serialized = formatter.SerializeToDTO(test);
            CslaBinaryWriter writer     = new CslaBinaryWriter(applicationContext);

            byte[] data;
            using (var stream = new MemoryStream())
            {
                writer.Write(stream, serialized);
                data = stream.ToArray();
            }

            CslaBinaryReader reader = new CslaBinaryReader(applicationContext);

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

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

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

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

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