Beispiel #1
0
        public void ObjectWithAttibute_Normal_Test()
        {
            var init = new ObjectWithAttribute();

            init.Initialize();
            ObjectWithAttribute final;

            using (var mem = new MemoryStream())
            {
                _bois.Serialize(init, mem);

                mem.Seek(0, SeekOrigin.Begin);

                final = _bois.Deserialize <ObjectWithAttribute>(mem);
            }
            init.AcceptChar.Should().Be(final.AcceptChar);

            AssertionHelper.AssertMembersAreEqual(final.ForeColor, new Color());

            init.Language.Should().Be(final.Language);
            final.PassedTimeSpan.Should().Be(new TimeSpan());
            init.TestDate.Should().Be(final.TestDate);
            init.TestGuid.Should().Be(final.TestGuid);
            final.Text1.Should().Be(null);
            init.TextField2.Should().Be(final.TextField2);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
                }
            }
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
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);
        }
Beispiel #14
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);
        }