Beispiel #1
0
        public void LinqDirect()
        {
            var l = from i in Enumerable.Range(1, 10) where i > 5 select i * i;

            // Write as the derived runtime type, but then read back as just an IEnumerable.
            SerializerConsistencyHepers.Test(l, tSourceWrite: l.GetType(), tSourceRead: typeof(IEnumerable <int>));
        }
Beispiel #2
0
        public void ClassWithIenumerableAndDataContract()
        {
            var widget = new ClassWithIenumerable2 {
                Property = "something"
            };

            SerializerConsistencyHepers.Test(widget); // XML fails to serialize
        }
Beispiel #3
0
        public void NormalClass()
        {
            var source = new NormalClass {
                FirstName = "John", LastName = "Smith", Item = "Socks"
            };

            SerializerConsistencyHepers.Test(source);
        }
Beispiel #4
0
        public void NullEmptyWhitespaceString()
        {
            NormalClass source = new NormalClass {
                FirstName = string.Empty, LastName = null, Item = "   "
            };

            SerializerConsistencyHepers.Test(source);
        }
Beispiel #5
0
        public void Linq()
        {
            var l = from i in Enumerable.Range(1, 10) where i > 5 select i * i;

            // Runtime type of a linq expression is some derived Linq type which we can't deserialize to.
            // So explicitly call out IEnumerable<T>
            SerializerConsistencyHepers.Test(l, typeof(IEnumerable <int>));
        }
Beispiel #6
0
        public void PartialContract()
        {
            var c = new PartialDataContract {
                PropertyWithAttribute = "one", PropertyWithoutAttribute = "false"
            };

            SerializerConsistencyHepers.Test(c);
        }
Beispiel #7
0
        public void ArrayInterfaces()
        {
            string[] array = new string[] { "First", "Second", "Last" };

            SerializerConsistencyHepers.Test(array, typeof(IList <string>));
            SerializerConsistencyHepers.Test(array, typeof(ICollection <string>));
            SerializerConsistencyHepers.Test(array, typeof(IEnumerable <string>));
        }
Beispiel #8
0
        public void ClassWithFields()
        {
            var c1 = new ClassWithFields {
                Property = "prop"
            };

            c1.SetField("field");
            SerializerConsistencyHepers.Test(c1);
        }
Beispiel #9
0
        public void Dictionary()
        {
            var dict = new Dictionary <string, int>();

            dict["one"] = 1;
            dict["two"] = 2;

            SerializerConsistencyHepers.Test(dict);
        }
Beispiel #10
0
        public void PrivateProperty()
        {
            var source2 = new PrivateProperty {
                FirstName = "John", LastName = "Smith"
            };

            source2.SetItem("shoes");
            SerializerConsistencyHepers.Test(source2);
        }
Beispiel #11
0
        public void DerivedProperties()
        {
            // If the static type is the base object, will we see the runtime type and pick derived properties
            BaseClass source = new DerivedClass {
                Property = "base", DerivedProperty = "derived"
            };

            source.SetField("private");
            SerializerConsistencyHepers.Test(source, typeof(BaseClass));
        }
Beispiel #12
0
        public void InheritedProperties()
        {
            // Will we pick up inherited properties from a base object?
            BaseClass source = new DerivedClass {
                Property = "base", DerivedProperty = "derived"
            };

            source.SetField("private");
            SerializerConsistencyHepers.Test(source, typeof(DerivedClass));
        }
Beispiel #13
0
        public void NewPropertiesHideBaseClass()
        {
            DerivedClassWithNew source = new DerivedClassWithNew {
                Property = "derived"
            };
            BaseClass baseClass = (BaseClass)source;

            baseClass.Property = "base";

            SerializerConsistencyHepers.Test(source, typeof(DerivedClassWithNew));
        }
Beispiel #14
0
        public void ExplicitInterfaceProps()
        {
            ClassWithExplicitInterface source = new ClassWithExplicitInterface {
                PublicProp = "public"
            };
            Interface1 i1 = source;

            i1.Foo = "interface!";

            SerializerConsistencyHepers.Test(source);
            SerializerConsistencyHepers.Test(source, typeof(Interface1));
        }
Beispiel #15
0
        public void StaticProps()
        {
            ClassWithStaticProperties source = new ClassWithStaticProperties();

            SerializerConsistencyHepers.Test(source);
        }
Beispiel #16
0
        public void Array()
        {
            string[] array = new string[] { "First", "Second", "Last" };

            SerializerConsistencyHepers.Test(array);
        }
Beispiel #17
0
        public void TestAnonymousType()
        {
            var anonymous = new { X = 10, Y = 15 };

            SerializerConsistencyHepers.Test(anonymous); // XML fails to write anonymous types
        }