Exemplo n.º 1
0
        public void WriteArray_DateTimeNormal()
        {
            ResetStream();
            var init = new DateTime[] { DateTime.MinValue, DateTime.MaxValue, DateTime.Now };

            bion.WriteArray(bionWriter, init);
            ResetStream();

            var final = (DateTime[])bion.ReadArray(bionReader, typeof(DateTime[]));

            AssertionHelper.AssetArrayEqual <DateTime>(init, final);
        }
Exemplo n.º 2
0
        public void WriteArray_ColorNormal()
        {
            ResetStream();
            var init = new Color[] { Color.Gainsboro, Color.DarkBlue };

            bion.WriteArray(bionWriter, init);
            ResetStream();

            var final = (Color[])bion.ReadArray(bionReader, typeof(Color[]));

            AssertionHelper.AssetArrayEqual <Color>(init, final);
        }
Exemplo n.º 3
0
        /// <summary>
        /// ArrayList is not supported, IGNORE this test
        /// </summary>
        public void WriteArray_ArrayListNormal()
        {
            ResetStream();
            var init = new ArrayList {
                new Version(1, 2, 3, 4), Color.DarkBlue, "test1", 99.200022
            };

            bion.WriteArray(bionWriter, init);
            ResetStream();

            var final = (ArrayList)bion.ReadArray(bionReader, typeof(ArrayList));

            AssertionHelper.AssetArrayEqual(init, final);
        }
Exemplo n.º 4
0
        public void StructType1_NormalTest()
        {
            var         init = StructType1.InitializeThis();
            StructType1 final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <StructType1>(mem);
            }

            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemplo n.º 5
0
        public void ObjectWithPrivateSetter_Normal()
        {
            var init = new ObjectWithPrivateSetter();

            init.Initialize();
            ObjectWithPrivateSetter final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <ObjectWithPrivateSetter>(mem);
            }
            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemplo n.º 6
0
        public void ArraySingleType1_NormalTest()
        {
            var init = new ArraySingleType1();

            init.Initialize();
            ArraySingleType1 final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <ArraySingleType1>(mem);
            }
            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemplo n.º 7
0
        public void StructType1_NullableVariable()
        {
            StructType1?init = StructType1.InitializeThis();
            StructType1?final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <StructType1?>(mem);
            }

            Assert.IsNotNull(final);
            AssertionHelper.AssertMembersAreEqual(init.Value, final.Value);
        }
Exemplo n.º 8
0
        public void PrimitiveTypes1Test()
        {
            var init = new PrimitiveTypes1();

            init.Initialize();
            PrimitiveTypes1 final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <PrimitiveTypes1>(mem);
            }
            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemplo n.º 9
0
        public void BasicTypes2NullableTest()
        {
            var init = new BasicTypes2Nullable();

            init.Initialize();
            BasicTypes2Nullable final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <BasicTypes2Nullable>(mem);
            }
            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemplo n.º 10
0
        public void HierarchyObjects2_ChildTest()
        {
            var init = new HierarchyObjects2.KidClass();

            init.Initialize();
            HierarchyObjects2.KidClass final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <HierarchyObjects2.KidClass>(mem);
            }

            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemplo n.º 11
0
        public void StructContainerNullable_Normal()
        {
            var init = new StructContainerNullable();

            init.Initialize();
            StructContainerNullable final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <StructContainerNullable>(mem);
            }

            Assert.IsNotNull(final);
            AssertionHelper.AssertMembersAreEqual(init, final);
        }
Exemplo n.º 12
0
        public void ThreadSafe_NormalTest()
        {
            var boisThreaded = new BoisSerializer();
            var init         = new PrimitiveTypes1();

            init.Initialize();
            PrimitiveTypes1 final;

            using (var iniToDeserialMem = new MemoryStream())
            {
                boisThreaded.Serialize(init, iniToDeserialMem);
                iniToDeserialMem.Seek(0, SeekOrigin.Begin);

                int done  = 0;
                var tasks = new Thread[500];
                for (int i = 0; i < tasks.Length; i++)
                {
                    var th = new Thread(
                        () =>
                    {
                        Thread.Sleep(50);
                        using (var mem = new MemoryStream())
                        {
                            boisThreaded.Serialize(init, mem);
                            mem.Seek(0, SeekOrigin.Begin);
                            final = boisThreaded.Deserialize <PrimitiveTypes1>(mem);
                        }
                        Interlocked.Increment(ref done);
                        AssertionHelper.AssertMembersAreEqual(init, final);
                    });
                    th.IsBackground = true;
                    th.Name         = "ThreadSafe_Test_" + i;
                    tasks[i]        = th;
                }
                foreach (var task in tasks)
                {
                    task.Start();
                }

                while (done < tasks.Length)
                {
                    Thread.Sleep(10);
                }
            }
        }
Exemplo n.º 13
0
        public void HierarchyObjects2Test()
        {
            var init = new HierarchyObjects2();

            init.Initialize();
            HierarchyObjects2 final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <HierarchyObjects2>(mem);
            }

            AssertionHelper.AssertMembersAreEqual(init.KidNull, final.KidNull);
            AssertionHelper.AssertMembersAreEqual(init.KidValue, final.KidValue);
            init.KidNull.Should().Be.EqualTo(final.KidNull);
        }
Exemplo n.º 14
0
        public void HierarchyWithStruct_NormalTest()
        {
            var init = new HierarchyWithStruct();

            init.Initialize();
            HierarchyWithStruct final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <HierarchyWithStruct>(mem);
            }
            Assert.IsNull(final.STypeNull);
            AssertionHelper.AssertMembersAreEqual(init.SType, final.SType);
            AssertionHelper.AssertMembersAreEqual(init.STypeNullable.Value, final.STypeNullable.Value);
            init.LastName.Should().Be.EqualTo(final.LastName);
            init.AcceptableAges.Should().Have.SameSequenceAs(final.AcceptableAges);
        }
Exemplo n.º 15
0
        public void HierarchyObjects1Test()
        {
            var init = new HierarchyObjects1();

            init.Initialize();
            HierarchyObjects1 final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);
                mem.Seek(0, SeekOrigin.Begin);
                final = _bois.Deserialize <HierarchyObjects1>(mem);
            }

            AssertionHelper.AssertMembersAreEqual(init.Child1, final.Child1);
            AssertionHelper.AssertMembersAreEqual(init.Child2, final.Child2);
            init.Name.Should().Be.EqualTo(final.Name);
            init.AcceptableAges.Should().Have.SameSequenceAs(final.AcceptableAges);
            init.LastName.Should().Be.EqualTo(final.LastName);
        }
Exemplo n.º 16
0
        public void BasicTypesDateTimeTest_XmlSerializer()
        {
            var serial = new System.Xml.Serialization.XmlSerializer(typeof(BasicTypesDateTime));
            var init   = new BasicTypesDateTime();

            init.Initialize();
            BasicTypesDateTime final;

            using (var mem = new MemoryStream())
                using (var r = new StreamReader(mem))
                {
                    serial.Serialize(mem, init);

                    mem.Seek(0, SeekOrigin.Begin);
                    var xml = r.ReadToEnd();

                    mem.Seek(0, SeekOrigin.Begin);
                    final = (BasicTypesDateTime)serial.Deserialize(mem);
                }
            AssertionHelper.AssertMembersAreEqual(init, final);
        }