public void SerializeAndDeserialaizeObjectWithOneIntPublicMember()
        {
            var simpleObject = new SampleClass()
            {
                simpleMember = Five
            };
            var result = SerializeAndDeserialize(simpleObject);

            Assert.AreEqual(Five, result.simpleMember);
        }
        public void ReadPublicStringFieldValuefromStream()
        {
            const int five         = 5;
            const int six          = 6;
            string    blabla       = "blabla";
            var       simpleObject = new SampleClass {
                stringField = blabla
            };
            var info = (ObjectInfo)WriteObjectAndReadInfo(simpleObject);

            Assert.AreEqual(blabla, info.Fields["stringField"].GetInstance(null));
        }
        public void HandleCrossReference()
        {
            string       anotherOneBustToDust = "anotherOneBustToDust";
            AnotherClass anotherClass         = new AnotherClass {
                Name = anotherOneBustToDust
            };
            var simpleObject = new SampleClass {
                simpleMember = Five, seconedMember = Six, stringField = Somthing, AnotherClassField = anotherClass, IntProp = Seven, AnotherClassRef = anotherClass
            };
            var result = SerializeAndDeserialize(simpleObject);

            Assert.AreSame(result.AnotherClassField, result.AnotherClassRef);
        }
        public void SerializeAndDeserialaizeObjectWithClassPublicField()
        {
            string       anotherOneBustToDust = "anotherOneBustToDust";
            AnotherClass anotherClass         = new AnotherClass {
                Name = anotherOneBustToDust
            };
            var simpleObject = new SampleClass {
                simpleMember = Five, seconedMember = Six, stringField = Somthing, AnotherClassField = anotherClass
            };
            var result = SerializeAndDeserialize(simpleObject);

            Assert.AreEqual(anotherOneBustToDust, result.AnotherClassField.Name);
        }
        public void SerializeAndDeserialaizeIntProperty()
        {
            string       anotherOneBustToDust = "anotherOneBustToDust";
            AnotherClass anotherClass         = new AnotherClass {
                Name = anotherOneBustToDust
            };
            var simpleObject = new SampleClass {
                simpleMember = Five, seconedMember = Six, stringField = Somthing, AnotherClassField = anotherClass, IntProp = Seven
            };
            var result = SerializeAndDeserialize(simpleObject);

            Assert.AreEqual(7, result.IntProp);
        }
        public void WriteStringFieldValue()
        {
            string blabla = "blabla";
            var    o      = new SampleClass {
                stringField = blabla
            };
            Action <BinaryReader> asssert = br =>
            {
                var result = ReadSimpleObject(br);
                Assert.AreEqual(blabla, result.stringField);
            };

            TestWriter(o, asssert);
        }
        public void ReadIntArray()
        {
            const int five = 5;
            const int six  = 6;

            int[] expected     = { 1, 2, 3, 4, 5 };
            var   simpleObject = new SampleClass {
                arr = expected
            };
            var info  = (ObjectInfo)WriteObjectAndReadInfo(simpleObject);
            var value = (ArrayInfo)info.Fields["arr"];

            Assert.IsTrue(expected.SequenceEqual(value.Array.Select(o => (int)o.GetInstance(null))));
        }
 public void WriteFullyQualifiedName()
 {
     using (MemoryStream ms = new MemoryStream())
         using (BinaryWriter bw = new BinaryWriter(ms))
             using (ObjectWriter target = new ObjectWriter(bw))
             {
                 var o = new SampleClass();
                 target.Write(o);
                 ms.Seek(0, SeekOrigin.Begin);
                 BinaryReader br            = new BinaryReader(ms);
                 var          objectTypeStr = br.ReadString();
                 var          fullName      = typeof(SampleClass).AssemblyQualifiedName;
                 Assert.AreEqual(fullName, objectTypeStr);
             }
 }
        public void WriteSimpleProperty()
        {
            var o = new SampleClass {
                stringField = "mystr", IntProp = 7
            };
            Action <BinaryReader> assert = br =>
            {
                ReadSimpleObject(br);
                br.ReadString();
                var propResult = br.ReadInt32();
                Assert.AreEqual(7, propResult);
            };

            TestWriter(o, assert);
        }
        public void ReadStringArray()
        {
            const int five = 5;
            const int six  = 6;

            string[] expected     = { "1", "2", "3", "4", "5" };
            var      simpleObject = new SampleClass {
                strArr = expected
            };
            var info  = (ObjectInfo)WriteObjectAndReadInfo(simpleObject);
            var value = (ArrayInfo)info.Fields["strArr"];


            Assert.IsTrue(expected.SequenceEqual(value.Array.Select(o => (string)o.GetInstance(null))));
        }
        public void WriteIntMemberValue()
        {
            const int five = 5;
            var       o    = new SampleClass {
                simpleMember = five
            };
            Action <BinaryReader> verify = br =>
            {
                var objectTypeStr = br.ReadString();
                var memberName    = br.ReadString();
                var memberValue   = br.ReadInt32();
                Assert.AreEqual(five, memberValue);
            };

            TestWriter(o, verify);
        }
 public void CreateSimpleObjectWithIntMember()
 {
     using (Stream stream = new MemoryStream())
         using (ObjectWriter wr = new ObjectWriter(new BinaryWriter(stream)))
             using (BinaryReader br = new BinaryReader(stream))
             {
                 const int five         = 5;
                 var       simpleObject = new SampleClass {
                     simpleMember = five
                 };
                 wr.Write(simpleObject);
                 stream.Seek(0, SeekOrigin.Begin);
                 ObjectReader target = new ObjectReader(br);
                 var          result = target.Read <SampleClass>();
                 Assert.AreEqual(five, result.simpleMember);
             }
 }
        public void ReadPublicIntFieldValuefromStream()
        {
            InfoReader ir = new InfoReader();

            using (Stream stream = new MemoryStream())
                using (ObjectWriter wr = new ObjectWriter(new BinaryWriter(stream)))
                    using (BinaryReader br = new BinaryReader(stream))
                    {
                        const int five         = 5;
                        var       simpleObject = new SampleClass {
                            simpleMember = five
                        };
                        wr.Write(simpleObject);
                        stream.Seek(0, SeekOrigin.Begin);
                        var info = ir.Read <SampleClass>(br) as ObjectInfo;
                        Assert.AreEqual(five, info.Fields["simpleMember"].GetInstance(null));
                    }
        }
        public void ReadFieldReference()
        {
            const int    five         = 5;
            const int    six          = 6;
            string       blabla       = "blabla";
            AnotherClass refClass     = new AnotherClass();
            var          simpleObject = new SampleClass {
                stringField = blabla, AnotherClassField = refClass, AnotherClassRef = refClass
            };
            var info  = (ObjectInfo)WriteObjectAndReadInfo(simpleObject);
            var value = info.Fields["AnotherClassRef"];

            Assert.IsInstanceOfType(value, typeof(ReferenceInfo));

            int refKey = ((ReferenceInfo)value).RefKey;

            Assert.AreEqual(1, refKey);
        }
        public void ReadObjectArray()
        {
            const int five = 5;
            const int six  = 6;

            int[] expectedSequence = { five, six };
            var   first            = new SampleClass {
                simpleMember = five
            };
            var sec = new SampleClass {
                simpleMember = six
            };
            var info = (ArrayInfo)WriteObjectAndReadInfo(new[] { first, sec });

            Assert.AreSame(info.ElementType, typeof(SampleClass));

            var result = info.Array.Cast <ObjectInfo>().Select(o => o.Fields["simpleMember"].GetInstance(null)).Cast <int>();

            Assert.IsTrue(result.SequenceEqual(expectedSequence));
        }
        public void WriteStringArray()
        {
            string[] expected = { "1", "2", "3", "4", "5" };
            var      obj      = new SampleClass {
                stringField = "mystr", strArr = expected
            };
            Action <BinaryReader> assert = br =>
            {
                ReadSimpleObject(br);

                AssertFieldName <SampleClass>(x => x.strArr, br);
                var arrLength = br.ReadInt32();
                Assert.AreEqual(5, arrLength);

                string[] result = new string[5];
                for (int i = 0; i < 5; i++)
                {
                    result[i] = br.ReadString();
                }
                Assert.IsTrue(expected.SequenceEqual(result));
            };

            TestWriter(obj, assert);
        }
        public void WriteIntArray()
        {
            int[] expected = { 1, 2, 3, 4, 5 };
            var   obj      = new SampleClass {
                stringField = "mystr", arr = expected
            };
            Action <BinaryReader> assert = br =>
            {
                ReadSimpleObject(br);

                AssertFieldName <SampleClass>(x => x.arr, br);
                var arrLength = br.ReadInt32();
                Assert.AreEqual(5, arrLength);

                int[] result = new int[5];
                for (int i = 0; i < 5; i++)
                {
                    result[i] = br.ReadInt32();
                }
                Assert.IsTrue(expected.SequenceEqual(result));
            };

            TestWriter(obj, assert);
        }
 public void Init()
 {
     _sampleClass = new SampleClass {
         stringField = "mystr", AnotherClassField = new AnotherClass(), IntProp = 7
     };
 }