Ejemplo n.º 1
0
        private static void AssertObject <T> (T value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <T>(serialized);

            // Although this method can't 100% prove the deserialized value is equal to the original unserialized object,
            // the probability of a false positive is very low - according with the other tests -.
            var serializedDeserialized = serializer.Serialize(deserialized);

            serializedDeserialized.Should().Equal(serialized);
        }
Ejemplo n.º 2
0
        public void GenericList()
        {
            var serializer = new Core.Serializer(new LoadedAssembliesGenericTypesProvider());
            var value      = new List <GenericBaseClass>
            {
                new GenericBaseClass(), new GenericBaseInheritedClass(), new GenericBaseInheritedInheritedClass()
            };

            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <List <GenericBaseClass> >(serialized);

            deserialized.Should().SatisfyRespectively
            (
                first =>
            {
                first.Should().BeOfType <GenericBaseClass>();
                first.Field1.Should().Be(value[0].Field1);
            },
                second =>
            {
                var casted = second as GenericBaseInheritedClass;
                casted.Should().NotBeNull();
                casted.Field3.Should().Be((value[1] as GenericBaseInheritedClass).Field3);
            },
                third =>
            {
                var casted = third as GenericBaseInheritedInheritedClass;
                casted.Should().NotBeNull();
                casted.Field4.Should().Be((value[2] as GenericBaseInheritedInheritedClass).Field4);
            }
            );

            AssertObject(value);
        }
Ejemplo n.º 3
0
        public void Bool(bool value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <bool>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 4
0
        public void String(string value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <string>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 5
0
        public void Char(char value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <char>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 6
0
        public void Enum(EnumData value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <EnumData>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 7
0
        public void Int(int value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <int>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 8
0
        public void Float(float value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <float>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 9
0
        public void UShort(ushort value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <ushort>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 10
0
        public void Byte(byte value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <byte>(serialized);

            deserialized.Should().Be(value);
        }
Ejemplo n.º 11
0
        private static void AssertList <T> (List <T> value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <List <T> >(serialized);

            Assert.True(ListComparer(value, deserialized));
        }
Ejemplo n.º 12
0
        private static void AssertDictionary <T1, T2> (Dictionary <T1, T2> value)
        {
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <Dictionary <T1, T2> >(serialized);

            Assert.True(DictionaryComparer(value, deserialized));
        }
Ejemplo n.º 13
0
        public void Guid(string GuidString)
        {
            var guid         = System.Guid.Parse(GuidString);
            var serializer   = new Core.Serializer();
            var serialized   = serializer.Serialize(guid);
            var deserialized = serializer.Deserialize <Guid>(serialized);

            deserialized.Should().Be(guid);
        }
Ejemplo n.º 14
0
        private static void Main(string[] args)
        {
            var valueToSerialize = (ushort)12;
            var serializer       = new Core.Serializer();
            var serialized       = serializer.Serialize(valueToSerialize);
            var deserialized     = serializer.Deserialize <ushort>(serialized);

            Console.WriteLine(deserialized);

            //new ComplexObject().ThreeLevelObject();
        }
Ejemplo n.º 15
0
        public void PostDeserializationCast()
        {
            var serializer = new Core.Serializer(new LoadedAssembliesGenericTypesProvider());
            var value      = new GenericBaseInheritedInheritedClass();

            var serialized   = serializer.Serialize(value);
            var deserialized = serializer.Deserialize <GenericBaseClass>(serialized);
            var deserializedCastedAsGenericBaseInherited          = deserialized as GenericBaseInheritedClass;
            var deserializedCastedAsGenericBaseInheritedInherited = deserialized as GenericBaseInheritedInheritedClass;

            deserializedCastedAsGenericBaseInherited.Should().NotBeNull();
            deserializedCastedAsGenericBaseInheritedInherited.Should().NotBeNull();
            deserializedCastedAsGenericBaseInherited.Field3.Should().Be(value.Field3);
            deserializedCastedAsGenericBaseInheritedInherited.Field4.Should().Be(value.Field4);

            AssertObject(value);
        }