Exemplo n.º 1
0
 public static bool IsEqual(this SealedObjectWithIntStringFields @this, SealedObjectWithIntStringFields other)
 {
     return(@this != null &&
            other != null &&
            @this.Member1 == other.Member1 &&
            @this.Member2 == other.Member2 &&
            @this.Member3 == other.Member3);
 }
Exemplo n.º 2
0
        public static void IsEqual(this SealedObjectWithIntStringFields @this, SealedObjectWithIntStringFields other, bool isSamePlatform)
        {
            if (@this == null && other == null)
            {
                return;
            }

            Assert.NotNull(@this);
            Assert.NotNull(other);
            Assert.Equal(@this.Member1, other.Member1);
            Assert.Equal(@this.Member2, other.Member2);
            Assert.Equal(@this.Member3, other.Member3);
        }
Exemplo n.º 3
0
        public static IEnumerable <object> SerializableObjects()
        {
            // Primitive types
            yield return(byte.MinValue);

            yield return(byte.MaxValue);

            yield return(sbyte.MinValue);

            yield return(sbyte.MaxValue);

            yield return(short.MinValue);

            yield return(short.MaxValue);

            yield return(int.MinValue);

            yield return(int.MaxValue);

            yield return(uint.MinValue);

            yield return(uint.MaxValue);

            yield return(long.MinValue);

            yield return(long.MaxValue);

            yield return(ulong.MinValue);

            yield return(ulong.MaxValue);

            yield return(char.MinValue);

            yield return(char.MaxValue);

            yield return(float.MinValue);

            yield return(float.MaxValue);

            yield return(double.MinValue);

            yield return(double.MaxValue);

            yield return(decimal.MinValue);

            yield return(decimal.MaxValue);

            yield return(decimal.MinusOne);

            yield return(true);

            yield return(false);

            yield return("");

            yield return("c");

            yield return("\u4F60\u597D");

            yield return("some\0data\0with\0null\0chars");

            yield return("<>&\"\'");

            yield return(" < ");

            yield return("minchar" + char.MinValue + "minchar");

            // Enum values
            yield return(DayOfWeek.Monday);

            yield return(DateTimeKind.Local);

            // Nullables
            yield return((int?)1);

            yield return((StructWithIntField?)new StructWithIntField()
            {
                X = 42
            });

            // Other core serializable types
            yield return(IntPtr.Zero);

            yield return(UIntPtr.Zero);

            yield return(DateTime.Now);

            yield return(DateTimeOffset.Now);

            yield return(DateTimeKind.Local);

            yield return(TimeSpan.FromDays(7));

            yield return(new Version(1, 2, 3, 4));

            yield return(new Guid("0CACAA4D-C6BD-420A-B660-2F557337CA89"));

            yield return(new AttributeUsageAttribute(AttributeTargets.Class));

            yield return(new List <int>());

            yield return(new List <int>()
            {
                1, 2, 3, 4, 5
            });

            yield return(new Dictionary <int, string>()
            {
                { 1, "test" }, { 2, "another test" }
            });

            yield return(Tuple.Create(1));

            yield return(Tuple.Create(1, "2"));

            yield return(Tuple.Create(1, "2", 3u));

            yield return(Tuple.Create(1, "2", 3u, 4L));

            yield return(Tuple.Create(1, "2", 3u, 4L, 5.6));

            yield return(Tuple.Create(1, "2", 3u, 4L, 5.6, 7.8f));

            yield return(Tuple.Create(1, "2", 3u, 4L, 5.6, 7.8f, 9m));

            yield return(Tuple.Create(1, "2", 3u, 4L, 5.6, 7.8f, 9m, Tuple.Create(10)));

            yield return(new KeyValuePair <int, byte>(42, 84));

            // Arrays of primitive types
            yield return(Enumerable.Range(0, 256).Select(i => (byte)i).ToArray());

            yield return(new int[] { });

            yield return(new int[] { 1 });

            yield return(new int[] { 1, 2, 3, 4, 5 });

            yield return(new char[] { 'a', 'b', 'c', 'd', 'e' });

            yield return(new string[] { });

            yield return(new string[] { "hello", "world" });

            yield return(new short[] { short.MaxValue });

            yield return(new long[] { long.MaxValue });

            yield return(new ushort[] { ushort.MaxValue });

            yield return(new uint[] { uint.MaxValue });

            yield return(new ulong[] { ulong.MaxValue });

            yield return(new bool[] { true, false });

            yield return(new double[] { 1.2 });

            yield return(new float[] { 1.2f, 3.4f });

            // Arrays of other types
            yield return(new object[] { });

            yield return(new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() });

            yield return(new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday });

            yield return(new Point[] { new Point(1, 2), new Point(3, 4) });

            yield return(new ObjectWithArrays
            {
                IntArray = new int[0],
                StringArray = new string[] { "hello", "world" },
                ByteArray = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 },
                JaggedArray = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6, 7 } },
                MultiDimensionalArray = new int[, ] {
                    { 1, 2 }, { 3, 4 }, { 5, 6 }
                },
                TreeArray = new Tree <int>[] { new Tree <int>(1, new Tree <int>(2, null, null), new Tree <int>(3, null, null)) }
            });

            yield return(new object[] { new int[, ] {
                                            { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 12, 13, 14, 15 }
                                        } });

            yield return(new object[] { new int[, , ] {
                                            { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 12, 13, 14, 15 } }
                                        } });

            yield return(new object[] { new int[, , , , ] {
                                            { { { { 1 } } } }
                                        } });

            yield return(new ArraySegment <int>(new int[] { 1, 2, 3, 4, 5 }, 1, 2));

            yield return(Enumerable.Range(0, 10000).Select(i => (object)i).ToArray());

            yield return(new object[200]); // fewer than 256 nulls

            yield return(new object[300]); // more than 256 nulls

            // Non-vector arrays
            yield return(Array.CreateInstance(typeof(uint), new[] { 5 }, new[] { 1 }));

            yield return(Array.CreateInstance(typeof(int), new[] { 0, 0, 0 }, new[] { 0, 0, 0 }));

            var arr = Array.CreateInstance(typeof(string), new[] { 1, 2 }, new[] { 3, 4 });

            arr.SetValue("hello", new[] { 3, 5 });
            yield return(arr);

            // Various globalization types
            yield return(CultureInfo.CurrentCulture);

            yield return(CultureInfo.InvariantCulture);

            // Internal specialized equality comparers
            yield return(EqualityComparer <byte> .Default);

            yield return(EqualityComparer <int> .Default);

            yield return(EqualityComparer <string> .Default);

            yield return(EqualityComparer <int?> .Default);

            yield return(EqualityComparer <double?> .Default);

            yield return(EqualityComparer <object> .Default);

            yield return(EqualityComparer <Int32Enum> .Default);

            // Custom object
            var sealedObjectWithIntStringFields = new SealedObjectWithIntStringFields();

            yield return(sealedObjectWithIntStringFields);

            yield return(new SealedObjectWithIntStringFields()
            {
                Member1 = 42, Member2 = null, Member3 = "84"
            });

            // Custom object with fields pointing to the same object
            yield return(new ObjectWithIntStringUShortUIntULongAndCustomObjectFields
            {
                Member1 = 10,
                Member2 = "hello",
                _member3 = "hello",
                Member4 = sealedObjectWithIntStringFields,
                Member4shared = sealedObjectWithIntStringFields,
                Member5 = new SealedObjectWithIntStringFields(),
                Member6 = "Hello World",
                str1 = "hello < world",
                str2 = "<",
                str3 = "< world",
                str4 = "hello < world",
                u16 = ushort.MaxValue,
                u32 = uint.MaxValue,
                u64 = ulong.MaxValue,
            });

            // Simple type without a default ctor
            var point = new Point(1, 2);

            yield return(point);

            // Graph without cycles
            yield return(new Tree <int>(42, null, null));

            yield return(new Tree <int>(1, new Tree <int>(2, new Tree <int>(3, null, null), null), null));

            yield return(new Tree <Colors>(Colors.Red, null, new Tree <Colors>(Colors.Blue, null, new Tree <Colors>(Colors.Green, null, null))));

            yield return(new Tree <int>(1, new Tree <int>(2, new Tree <int>(3, null, null), new Tree <int>(4, null, null)), new Tree <int>(5, null, null)));

            // Graph with cycles
            Graph <int> a = new Graph <int> {
                Value = 1
            };

            yield return(a);

            Graph <int> b = new Graph <int> {
                Value = 2, Links = new[] { a }
            };

            yield return(b);

            Graph <int> c = new Graph <int> {
                Value = 3, Links = new[] { a, b }
            };

            yield return(c);

            Graph <int> d = new Graph <int> {
                Value = 3, Links = new[] { a, b, c }
            };

            yield return(d);

            a.Links = new[] { b, c, d }; // complete the cycle
            yield return(a);

            // Structs
            yield return(new EmptyStruct());

            yield return(new StructWithIntField {
                X = 42
            });

            yield return(new StructWithStringFields {
                String1 = "hello", String2 = "world"
            });

            yield return(new StructContainingOtherStructs {
                Nested1 = new StructWithStringFields {
                    String1 = "a", String2 = "b"
                }, Nested2 = new StructWithStringFields {
                    String1 = "3", String2 = "4"
                }
            });

            yield return(new StructContainingArraysOfOtherStructs());

            yield return(new StructContainingArraysOfOtherStructs {
                Nested = new StructContainingOtherStructs[0]
            });

            var s = new StructContainingArraysOfOtherStructs
            {
                Nested = new[]
                {
                    new StructContainingOtherStructs {
                        Nested1 = new StructWithStringFields {
                            String1 = "a", String2 = "b"
                        }, Nested2 = new StructWithStringFields {
                            String1 = "3", String2 = "4"
                        }
                    },
                    new StructContainingOtherStructs {
                        Nested1 = new StructWithStringFields {
                            String1 = "e", String2 = "f"
                        }, Nested2 = new StructWithStringFields {
                            String1 = "7", String2 = "8"
                        }
                    },
                }
            };

            yield return(s);

            yield return(new object[] { s, new StructContainingArraysOfOtherStructs?(s) });

            // ISerializable
            yield return(new BasicISerializableObject(1, "2"));

            yield return(new DerivedISerializableWithNonPublicDeserializationCtor(1, "2"));

            // Various other special cases
            yield return(new TypeWithoutNamespace());
        }