Exemple #1
0
        public void Shouldnt_Desserialize_Unknown_Type()
        {
            Serializer.RegisterTypes(new Dictionary <ushort, Type>()
            {
                [100] = typeof(TestCustomClass)
            });
            var testObj = new TestCustomClass {
                IntField = 45345, StrField = "Test 1"
            };
            Action serializer = () =>
            {
                using (var stream = new MemoryStream())
                {
                    Serializer.Serialize(stream, testObj);
                    Serializer.Clear();
                    stream.Seek(0, SeekOrigin.Begin);
                    Serializer.Deserialize(stream);
                }
            };

#if !NET40
            var message = "Unknown type id";
#endif
            var ex = Assert.Throws <ArgumentOutOfRangeException>(serializer);
#if !NET40
            Assert.Contains(message, ex.Message);
#endif
        }
Exemple #2
0
        public void Should_Serialize_Type_By_Id()
        {
            Serializer.RegisterTypes(new Dictionary <ushort, Type>()
            {
                [64] = typeof(TestCustomClass)
            });
            var testObj = new TestCustomClass {
                IntField = 45345, StrField = "Test 1"
            };

            using (var stream = new MemoryStream())
            {
                Serializer.Serialize(stream, testObj);
                stream.Seek(0, SeekOrigin.Begin);
                var result = Serializer.Deserialize(stream);
                Assert.IsType(testObj.GetType(), result);
                Assert.Equal(result, testObj);
            }
        }
Exemple #3
0
        public void Shouldnt_Serialize_Unknown_Type()
        {
            var testObj = new TestCustomClass {
                IntField = 45345, StrField = "Test 1"
            };
            Action serializer = () =>
            {
                using (var stream = new MemoryStream())
                {
                    Serializer.Serialize(stream, testObj);
                }
            };

#if !NET40
            var message = "Serialization is not supported for the type";
#endif
            var ex = Assert.Throws <NotSupportedException>(serializer);
#if !NET40
            Assert.StartsWith(message, ex.Message);
#endif
        }