Esempio n. 1
0
        public void DynamicSerializer_WriteReadCoveredType()
        {
            DynamicSerializer s = new DynamicSerializer();

            s.AddReaderWriter(typeof(ITestInterface),
                              new DataWriter(typeof(ITestInterface), WriteTestInterface),
                              new DataReader(typeof(ITestInterface), ReadTestInterface), true);

            Random         r = new Random();
            ITestInterface m = new TestImplemented();

            m.Data = "Hello world";

            DataBuffer b = new DataBuffer();

            s.Write(b, typeof(TestImplemented), m);

            b.Seek(0);
            var mresult = s.Read <ITestInterface>(b);

            Assert.IsNotNull(mresult);
            Assert.IsNotNull(mresult.Data);
            Assert.IsFalse(mresult.Data == "");
            Assert.AreEqual(m.Data, mresult.Data);
        }
Esempio n. 2
0
        public void DynamicSerializer_AddReaderWriter_CanReadWrite()
        {
            DynamicSerializer s = new DynamicSerializer();

            Assert.IsFalse(s.CanReadWrite(typeof(TestModelWithConstructor)));

            s.AddReaderWriter <TestModelWithConstructor>(
                new DataWriter(s, typeof(TestModelWithConstructor)),
                new DataReader(s, typeof(TestModelWithConstructor), () => new TestModelWithConstructor("")));

            Assert.IsTrue(s.CanReadWrite(typeof(TestModelWithConstructor)));

            TestModelWithConstructor m = new TestModelWithConstructor("Hello world");

            DataBuffer b = new DataBuffer();

            s.Write <TestModelWithConstructor>(b, m);

            b.Seek(0);
            var result = s.Read <TestModelWithConstructor>(b);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data, m.Data);
        }