private static SerializationFactory CreateFactory(Type t)
        {
            var fields = DeepEquality.GetAllFields(t)
                         //.OrderBy(fi => (int)fi.GetManagedOffset()) // [StructLayout.Sequential] doesn't work with this
                         .OrderBy(fi => (int)Marshal.OffsetOf(t, fi.Name))
                         .ToList();

            var rmeth = new DynamicMethod(t.Name + "_r", null, new[] { typeof(object), typeof(BinaryReader) }, true);
            var wmeth = new DynamicMethod(t.Name + "_w", null, new[] { typeof(object), typeof(BinaryWriter) }, true);

            {
                var il     = rmeth.GetILGenerator();
                var target = il.DeclareLocal(t);
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Castclass, t);
                il.Emit(OpCodes.Stloc, target);

                foreach (var field in fields)
                {
                    il.Emit(OpCodes.Ldloc, target);
                    il.Emit(OpCodes.Ldarg_1);
                    MethodInfo m;
                    if (!readhandlers.TryGetValue(field.FieldType, out m))
                    {
                        throw new InvalidOperationException("(R) Can't handle nested type " + field.FieldType);
                    }
                    il.Emit(OpCodes.Callvirt, m);
                    il.Emit(OpCodes.Stfld, field);
                }
                il.Emit(OpCodes.Ret);
            }
            {
                var il     = wmeth.GetILGenerator();
                var target = il.DeclareLocal(t);
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Castclass, t);
                il.Emit(OpCodes.Stloc, target);

                foreach (var field in fields)
                {
                    il.Emit(OpCodes.Ldarg_1);
                    il.Emit(OpCodes.Ldloc, target);
                    il.Emit(OpCodes.Ldfld, field);
                    MethodInfo m;
                    if (!writehandlers.TryGetValue(field.FieldType, out m))
                    {
                        throw new InvalidOperationException("(W) Can't handle nested type " + field.FieldType);
                    }
                    il.Emit(OpCodes.Callvirt, m);
                }
                il.Emit(OpCodes.Ret);
            }

            return(new SerializationFactory
            {
                Type = t,
                Read = (Reader)rmeth.CreateDelegate(typeof(Reader)),
                Write = (Writer)wmeth.CreateDelegate(typeof(Writer))
            });
        }
Esempio n. 2
0
        public void AreDeeplyEqualShouldWorkCorrectlyWithSameReferences()
        {
            var firstObject = new NestedModel {
                Integer = 1, String = "Text"
            };
            var secondObject = new NestedModel {
                Integer = 1, String = "Text", Nested = firstObject
            };

            firstObject.Nested = secondObject;

            Assert.True(DeepEquality.AreDeeplyEqual(firstObject, secondObject));
        }
Esempio n. 3
0
        public void AreDeeplyEqualShouldReportCorrectly()
        {
            var firstObject = new NestedModel()
            {
                Integer = 1, String = "Text"
            };
            var secondObject = new NestedModel()
            {
                Integer = 2, String = "Text"
            };

            Assert.False(DeepEquality.AreDeeplyEqual(firstObject, secondObject, out var result));
            Assert.Equal("Difference occurs at 'NestedModel.Integer'. Expected a value of '1', but in fact it was '2'", result.ToString());
        }
Esempio n. 4
0
 public void AreDeeplyEqualShouldReportCorrectlyWithPrimitiveAndStructTypes()
 {
     Assert.False(DeepEquality.AreDeeplyEqual(1, 0, out var result));
     Assert.Equal("Expected a value of '1', but in fact it was '0'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(1, null, out result));
     Assert.Equal("Expected a value of '1', but in fact it was null", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(null, 1, out result));
     Assert.Equal("Expected a value of null, but in fact it was '1'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual("test1", "test2", out result));
     Assert.Equal("Expected a value of 'test1', but in fact it was 'test2'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(1, "1", out result));
     Assert.Equal("Expected a value of Int32 type, but in fact it was String", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new DateTime(2015, 10, 19), new DateTime(2015, 10, 20), out result));
     Assert.Equal("Difference occurs at 'DateTime.== (Equality Operator)'. Expected a value of '10/19/2015 00:00:00', but in fact it was '10/20/2015 00:00:00'", result.ToString());
 }
Esempio n. 5
0
        public void AreDeeplyEqualShouldWorkCorrectlyWithEnumerations()
        {
            // Enum with default values.
            Assert.True(DeepEquality.AreDeeplyEqual(DateTimeKind.Unspecified, DateTimeKind.Unspecified));
            Assert.False(DeepEquality.AreDeeplyEqual(DateTimeKind.Local, DateTimeKind.Utc));

            // Enum with overridden values.
            Assert.True(DeepEquality.AreDeeplyEqual(AttributeTargets.Delegate, AttributeTargets.Delegate));
            Assert.False(DeepEquality.AreDeeplyEqual(AttributeTargets.Assembly, AttributeTargets.All));
            Assert.False(DeepEquality.AreDeeplyEqual(AttributeTargets.Assembly, AttributeTargets.Module));

            // Enum with default and overriden values.
            Assert.True(DeepEquality.AreDeeplyEqual(CustomEnum.DefaultConstant, CustomEnum.DefaultConstant));
            Assert.False(DeepEquality.AreDeeplyEqual(CustomEnum.DefaultConstant, CustomEnum.ConstantWithCustomValue));
            Assert.False(DeepEquality.AreDeeplyEqual(CustomEnum.DefaultConstant, CustomEnum.CombinedConstant));
        }
Esempio n. 6
0
        public void AreDeeplyEqualShouldReportCorrectlyWithDictionaries()
        {
            var firstDictionary = new Dictionary <string, string>
            {
                { "Key", "Value" },
                { "AnotherKey", "Value" },
            };

            var secondDictionary = new Dictionary <string, string>
            {
                { "Key", "Value" },
                { "AnotherKey", "AnotherValue" },
            };

            Assert.False(DeepEquality.AreDeeplyEqual(firstDictionary, secondDictionary, out var result));
            Assert.Equal("Difference occurs at 'Dictionary<String, String>[AnotherKey].Value'. Expected a value of 'Value', but in fact it was 'AnotherValue'", result.ToString());

            var firstDictionaryWithObject = new Dictionary <string, NestedModel>
            {
                { "Key", new NestedModel {
                      Integer = 1, String = "Text", Enum = CustomEnum.ConstantWithCustomValue
                  } },
                { "AnotherKey", new NestedModel {
                      Integer = 2, String = "Text"
                  } }
            };

            var secondDictionaryWithObject = new Dictionary <string, NestedModel>
            {
                { "Key", new NestedModel {
                      Integer = 1, String = "Text",
                  } },
                { "AnotherKey", new NestedModel {
                      Integer = 2, String = "AnotherText"
                  } }
            };

            Assert.False(DeepEquality.AreDeeplyEqual(firstDictionaryWithObject, secondDictionaryWithObject, out result));
            Assert.Equal("Difference occurs at 'Dictionary<String, NestedModel>[Key].Value.Enum'. Expected a value of 'ConstantWithCustomValue', but in fact it was 'DefaultConstant'", result.ToString());
        }
        public static void Test()
        {
            var item1 = new TestEntity
            {
                Name           = "xx2",
                Birthday       = "1986",
                Description    = "ddd",
                IgnoreProperty = 1
            };

            var item2 = new TestEntity
            {
                Name           = "xX2",
                Birthday       = "1986",
                Description    = "ddd",
                IgnoreProperty = 2
            };

            Console.WriteLine(DeepEquality.DeepEquals(item1, item2, StringComparison.OrdinalIgnoreCase));

            Console.WriteLine(DeepEquality.DeepEquals(item1, item2, StringComparison.Ordinal));
        }
Esempio n. 8
0
        public void AreDeeplyEqualShouldReportCorrectlyWithNestedObjects()
        {
            var firstObject = new NestedModel {
                Integer = 1, String = "Text"
            };
            var secondObject = new NestedModel {
                Integer = 2, String = "Text"
            };

            Assert.False(DeepEquality.AreDeeplyEqual(firstObject, secondObject, out var result));
            Assert.Equal("Difference occurs at 'NestedModel.Integer'. Expected a value of '1', but in fact it was '2'", result.ToString());

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new NestedModel
            {
                Integer = 1,
                String  = "test",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test2", Nested = new NestedModel {
                        Integer = 3, String = "test3"
                    }
                }
            },
                             new NestedModel
            {
                Integer = 1,
                String  = "test",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test1", Nested = new NestedModel {
                        Integer = 3, String = "test3"
                    }
                }
            }, out result));

            Assert.Equal("Difference occurs at 'NestedModel.Nested.String'. Expected a value of 'test2', but in fact it was 'test1'", result.ToString());
        }
Esempio n. 9
0
 public void AreDeeplyEqualShouldWorkCorrectlyWithPrimitiveAndStructTypes()
 {
     Assert.True(DeepEquality.AreDeeplyEqual(1, 1));
     Assert.True(DeepEquality.AreDeeplyEqual(null, null));
     Assert.True(DeepEquality.AreDeeplyEqual("test", "test"));
     Assert.True(DeepEquality.AreDeeplyEqual('a', 'a'));
     Assert.True(DeepEquality.AreDeeplyEqual(1.1, 1.1));
     Assert.True(DeepEquality.AreDeeplyEqual(1.0m, (decimal)1));
     Assert.True(DeepEquality.AreDeeplyEqual(1L, (long)1));
     Assert.True(DeepEquality.AreDeeplyEqual(1.1m, 1.1m));
     Assert.True(DeepEquality.AreDeeplyEqual(true, true));
     Assert.True(DeepEquality.AreDeeplyEqual(new DateTime(2015, 10, 19), new DateTime(2015, 10, 19)));
     Assert.False(DeepEquality.AreDeeplyEqual(1, 0));
     Assert.False(DeepEquality.AreDeeplyEqual(1, null));
     Assert.False(DeepEquality.AreDeeplyEqual("test1", "test2"));
     Assert.False(DeepEquality.AreDeeplyEqual("Test", "test"));
     Assert.False(DeepEquality.AreDeeplyEqual('a', 'b'));
     Assert.False(DeepEquality.AreDeeplyEqual(1.1, 1.2));
     Assert.False(DeepEquality.AreDeeplyEqual(1.1m, 1.2m));
     Assert.False(DeepEquality.AreDeeplyEqual(true, false));
     Assert.False(DeepEquality.AreDeeplyEqual(1, "1"));
     Assert.False(DeepEquality.AreDeeplyEqual(new DateTime(2015, 10, 19), new DateTime(2015, 10, 20)));
 }
Esempio n. 10
0
 public void AreDeeplyEqualShouldReportCorrectlyWithEnumerations()
 {
     Assert.False(DeepEquality.AreDeeplyEqual(DateTimeKind.Local, DateTimeKind.Utc, out var result));
     Assert.Equal("Expected a value of 'Local', but in fact it was 'Utc'", result.ToString());
 }
Esempio n. 11
0
 public void AreDeeplyEqualShouldReportCorrectlyWithNormalObjects()
 {
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), "test", out var result));
     Assert.Equal("Expected a value of Object type, but in fact it was String", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), AttributeTargets.All, out result));
     Assert.Equal("Expected a value of Object type, but in fact it was AttributeTargets", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(AttributeTargets.All, new object(), out result));
     Assert.Equal("Expected a value of AttributeTargets type, but in fact it was Object", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(DateTime.Now, "test", out result));
     Assert.Equal("Expected a value of DateTime type, but in fact it was String", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual("test", DateTime.Now, out result));
     Assert.Equal("Expected a value of String type, but in fact it was DateTime", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(true, new object(), out result));
     Assert.Equal("Expected a value of Boolean type, but in fact it was Object", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual("test", new object(), out result));
     Assert.Equal("Expected a value of String type, but in fact it was Object", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), true, out result));
     Assert.Equal("Expected a value of Object type, but in fact it was Boolean", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 3 } }, new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 4 } }, out result));
     Assert.Equal("Difference occurs at 'AnonymousType<Int32, String, Byte[]>.Nested[2]'. Expected a value of '3', but in fact it was '4'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 2
     }, new RequestModel {
         Integer = 1
     }, out result));
     Assert.Equal("Difference occurs at 'RequestModel.Integer'. Expected a value of '2', but in fact it was '1'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), new RequestModel {
         Integer = 1
     }, out result));
     Assert.Equal("Expected a value of Object type, but in fact it was RequestModel", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 2
     }, new object(), out result));
     Assert.Equal("Expected a value of RequestModel type, but in fact it was Object", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 2, NonRequiredString = "test"
     }, new RequestModel {
         Integer = 1
     }, out result));
     Assert.Equal("Difference occurs at 'RequestModel.Integer'. Expected a value of '2', but in fact it was '1'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new GenericComparableModel {
         Integer = 1, String = "test"
     }, new GenericComparableModel {
         Integer = 2, String = "test"
     }, out result));
     Assert.Equal("Difference occurs at 'GenericComparableModel.CompareTo().Integer'. Expected a value of '1', but in fact it was '2'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new ComparableModel {
         Integer = 1, String = "test"
     }, new ComparableModel {
         Integer = 2, String = "test"
     }, out result));
     Assert.Equal("Difference occurs at 'ComparableModel.CompareTo().Integer'. Expected a value of '1', but in fact it was '2'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new EqualsModel {
         Integer = 1, String = "test"
     }, new EqualsModel {
         Integer = 2, String = "test"
     }, out result));
     Assert.Equal("Difference occurs at 'EqualsModel.Equals()'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new EqualityOperatorModel {
         Integer = 1, String = "test"
     }, new EqualityOperatorModel {
         Integer = 2, String = "test"
     }, out result));
     Assert.Equal("Difference occurs at 'EqualityOperatorModel.== (Equality Operator)'", result.ToString());
     Assert.False(DeepEquality.AreDeeplyEqual(new ComparableModel {
         Integer = 1, String = "test"
     }, new RequestModel(), out result));
     Assert.Equal("Expected a value of ComparableModel type, but in fact it was RequestModel", result.ToString());
 }
Esempio n. 12
0
 public static bool NeedsReboot(VectrexSyncSettings x, VectrexSyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 13
0
 public static bool NeedsReboot(Ares64Settings x, Ares64Settings y) => !DeepEquality.DeepEquals(x, y);
Esempio n. 14
0
        public void AreDeeplyEqualShouldWorkCorrectlyWithDictionaries()
        {
            var firstDictionary = new Dictionary <string, string>
            {
                { "Key", "Value" },
                { "AnotherKey", "AnotherValue" },
            };

            var secondDictionary = new Dictionary <string, string>
            {
                { "Key", "Value" },
                { "AnotherKey", "AnotherValue" },
            };

            Assert.True(DeepEquality.AreDeeplyEqual(firstDictionary, secondDictionary));

            firstDictionary = new Dictionary <string, string>
            {
                { "Key", "Value" },
                { "AnotherKey", "Value" },
            };

            secondDictionary = new Dictionary <string, string>
            {
                { "Key", "Value" },
                { "AnotherKey", "AnotherValue" },
            };

            Assert.False(DeepEquality.AreDeeplyEqual(firstDictionary, secondDictionary));

            var firstDictionaryWithObject = new Dictionary <string, NestedModel>
            {
                { "Key", new NestedModel {
                      Integer = 1, String = "Text", Enum = CustomEnum.ConstantWithCustomValue
                  } },
                { "AnotherKey", new NestedModel {
                      Integer = 2, String = "AnotherText"
                  } }
            };

            var secondDictionaryWithObject = new Dictionary <string, NestedModel>
            {
                { "Key", new NestedModel {
                      Integer = 1, String = "Text", Enum = CustomEnum.ConstantWithCustomValue
                  } },
                { "AnotherKey", new NestedModel {
                      Integer = 2, String = "AnotherText"
                  } }
            };

            Assert.True(DeepEquality.AreDeeplyEqual(firstDictionaryWithObject, secondDictionaryWithObject));

            firstDictionaryWithObject = new Dictionary <string, NestedModel>
            {
                { "Key", new NestedModel {
                      Integer = 1, String = "Text", Enum = CustomEnum.ConstantWithCustomValue
                  } },
                { "AnotherKey", new NestedModel {
                      Integer = 2, String = "Text"
                  } }
            };

            secondDictionaryWithObject = new Dictionary <string, NestedModel>
            {
                { "Key", new NestedModel {
                      Integer = 1, String = "Text",
                  } },
                { "AnotherKey", new NestedModel {
                      Integer = 2, String = "AnotherText"
                  } }
            };

            Assert.False(DeepEquality.AreDeeplyEqual(firstDictionaryWithObject, secondDictionaryWithObject));
        }
Esempio n. 15
0
 public static bool NeedsReboot(AmstradCPCSyncSettings x, AmstradCPCSyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 16
0
 public static bool NeedsReboot(NESControlSettings x, NESControlSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
 public static bool NeedsReboot(ZXSpectrumSyncSettings x, ZXSpectrumSyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 18
0
 public static bool NeedsReboot(GambatteSyncSettings x, GambatteSyncSettings y)
 {
     return !DeepEquality.DeepEquals(x, y);
 }
Esempio n. 19
0
        public void AreDeeplyEqualShouldWorkCorrectlyWithCollections()
        {
            Assert.True(DeepEquality.AreDeeplyEqual(
                            new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1, String = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Enum = CustomEnum.CombinedConstant, Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                },
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Enum = CustomEnum.CombinedConstant, Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            },
                            new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1, String = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Enum = CustomEnum.CombinedConstant, Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                },
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Enum = CustomEnum.CombinedConstant, Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            }));

            var listOfNestedModels = new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Enum    = CustomEnum.ConstantWithCustomValue,
                    Nested  =
                        new NestedModel
                    {
                        Integer = 2,
                        String  = "test2",
                        Enum    = CustomEnum.ConstantWithCustomValue,
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                },
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Enum    = CustomEnum.ConstantWithCustomValue,
                    Nested  =
                        new NestedModel
                    {
                        Integer = 2,
                        String  = "test2",
                        Enum    = CustomEnum.ConstantWithCustomValue,
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            };

            var arrayOfNestedModels = new[]
            {
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Enum    = CustomEnum.ConstantWithCustomValue,
                    Nested  =
                        new NestedModel
                    {
                        Integer = 2,
                        String  = "test2",
                        Enum    = CustomEnum.ConstantWithCustomValue,
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                },
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Enum    = CustomEnum.ConstantWithCustomValue,
                    Nested  =
                        new NestedModel
                    {
                        Integer = 2,
                        String  = "test2",
                        Enum    = CustomEnum.ConstantWithCustomValue,
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            };

            Assert.True(DeepEquality.AreDeeplyEqual(listOfNestedModels, arrayOfNestedModels));

            Assert.True(DeepEquality.AreDeeplyEqual(
                            new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            },
                            new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            }));

            Assert.True(DeepEquality.AreDeeplyEqual(
                            new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            },
                            new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new[]
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            }));

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1, String = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }, new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            },
                             new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1, String = "test2",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }, new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            }));

            listOfNestedModels = new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  =
                        new NestedModel
                    {
                        Integer = 2,
                        String  = "test2",
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                },
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  =
                        new NestedModel
                    {
                        Integer = 2,
                        String  = "test2",
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            };

            arrayOfNestedModels = new[]
            {
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  =
                        new NestedModel
                    {
                        Integer = 2,
                        String  = "test2",
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                },
                new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  =
                        new NestedModel
                    {
                        Integer = 4,
                        String  = "test2",
                        Nested  = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            };

            Assert.False(DeepEquality.AreDeeplyEqual(listOfNestedModels, arrayOfNestedModels));

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            },
                             new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 5, String = "test3"
                            }
                        }
                    }
                }
            }));

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            },
                             new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new[]
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test3", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            }));

            Assert.True(DeepEquality.AreDeeplyEqual(new List <int> {
                1, 2, 3
            }, new[] { 1, 2, 3 }));
            Assert.False(DeepEquality.AreDeeplyEqual(new List <int> {
                1, 2, 3, 4
            }, new[] { 1, 2, 3 }));
            Assert.False(DeepEquality.AreDeeplyEqual(new List <int>(), new object()));
            Assert.False(DeepEquality.AreDeeplyEqual(new object(), new List <int>()));
        }
Esempio n. 20
0
 public static bool NeedsReboot(A2600SyncSettings x, A2600SyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 21
0
 public static bool NeedsReboot(GPGXSettings x, GPGXSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 22
0
 public static bool NeedsReboot(ColecoSyncSettings x, ColecoSyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 23
0
 public static bool NeedsReboot(MAMESyncSettings x, MAMESyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x.DriverSettings, y.DriverSettings));
 }
Esempio n. 24
0
 public void AreDeeplyEqualsShouldWorkCorrectlyWithNormalObjects()
 {
     Assert.True(DeepEquality.AreDeeplyEqual(new object(), new object()));
     Assert.True(DeepEquality.AreDeeplyEqual((object)5, (object)5));
     Assert.True(DeepEquality.AreDeeplyEqual((object)5, 5));
     Assert.True(DeepEquality.AreDeeplyEqual(new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 3 } }, new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 3 } }));
     Assert.True(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 1
     }, new RequestModel {
         Integer = 1
     }));
     Assert.True(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 1, NonRequiredString = "test"
     }, new RequestModel {
         Integer = 1, NonRequiredString = "test"
     }));
     Assert.True(DeepEquality.AreDeeplyEqual(new GenericComparableModel {
         Integer = 1, String = "test"
     }, new GenericComparableModel {
         Integer = 1, String = "another"
     }));
     Assert.True(DeepEquality.AreDeeplyEqual(new ComparableModel {
         Integer = 1, String = "test"
     }, new ComparableModel {
         Integer = 1, String = "another"
     }));
     Assert.True(DeepEquality.AreDeeplyEqual(new EqualsModel {
         Integer = 1, String = "test"
     }, new EqualsModel {
         Integer = 1, String = "another"
     }));
     Assert.True(DeepEquality.AreDeeplyEqual(new EqualityOperatorModel {
         Integer = 1, String = "test"
     }, new EqualityOperatorModel {
         Integer = 1, String = "another"
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), "test"));
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), AttributeTargets.All));
     Assert.False(DeepEquality.AreDeeplyEqual(AttributeTargets.All, new object()));
     Assert.True(DeepEquality.AreDeeplyEqual(AttributeTargets.All, (object)AttributeTargets.All));
     Assert.True(DeepEquality.AreDeeplyEqual((object)AttributeTargets.All, AttributeTargets.All));
     Assert.False(DeepEquality.AreDeeplyEqual(DateTime.Now, "test"));
     Assert.False(DeepEquality.AreDeeplyEqual("test", DateTime.Now));
     Assert.False(DeepEquality.AreDeeplyEqual(true, new object()));
     Assert.False(DeepEquality.AreDeeplyEqual("test", new object()));
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), true));
     Assert.False(DeepEquality.AreDeeplyEqual(new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 3 } }, new { Integer = 1, String = "Test", Nested = new byte[] { 1, 2, 4 } }));
     Assert.False(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 2
     }, new RequestModel {
         Integer = 1
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new object(), new RequestModel {
         Integer = 1
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 2
     }, new object()));
     Assert.False(DeepEquality.AreDeeplyEqual(new RequestModel {
         Integer = 2, NonRequiredString = "test"
     }, new RequestModel {
         Integer = 1
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new GenericComparableModel {
         Integer = 1, String = "test"
     }, new GenericComparableModel {
         Integer = 2, String = "test"
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new ComparableModel {
         Integer = 1, String = "test"
     }, new ComparableModel {
         Integer = 2, String = "test"
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new EqualsModel {
         Integer = 1, String = "test"
     }, new EqualsModel {
         Integer = 2, String = "test"
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new EqualityOperatorModel {
         Integer = 1, String = "test"
     }, new EqualityOperatorModel {
         Integer = 2, String = "test"
     }));
     Assert.False(DeepEquality.AreDeeplyEqual(new ComparableModel {
         Integer = 1, String = "test"
     }, new RequestModel()));
 }
Esempio n. 25
0
        public void AreDeeplyEqualShouldReportCorrectlyWithCollections()
        {
            Assert.False(DeepEquality.AreDeeplyEqual(new List <int> {
                1, 2, 3, 4
            }, new[] { 1, 2, 3 }, out var result));
            Assert.Equal("Difference occurs at 'List<Int32>.Count'. Expected a value of '4', but in fact it was '3'", result.ToString());

            Assert.False(DeepEquality.AreDeeplyEqual(new List <int> {
                1, 2, 3, 4
            }, new[] { 1, 2, 3, 5 }, out result));
            Assert.Equal("Difference occurs at 'List<Int32>[3]'. Expected a value of '4', but in fact it was '5'", result.ToString());

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }
                }
            },
                             new NestedCollection
            {
                Integer = 1,
                String  = "test",
                Nested  = new List <NestedModel>
                {
                    new NestedModel
                    {
                        Integer = 1, String = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 3, String = "test3"
                            }
                        }
                    }, new NestedModel
                    {
                        Integer = 1,
                        String  = "test1",
                        Nested  = new NestedModel {
                            Integer = 2, String = "test2", Nested = new NestedModel {
                                Integer = 5, String = "test3"
                            }
                        }
                    }
                }
            }, out result));

            Assert.Equal("Difference occurs at 'NestedCollection.Nested[1].Nested.Nested.Integer'. Expected a value of '3', but in fact it was '5'", result.ToString());

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1, String = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test4"
                        }
                    }
                }, new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            },
                             new List <NestedModel>
            {
                new NestedModel
                {
                    Integer = 1, String = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }, new NestedModel
                {
                    Integer = 1,
                    String  = "test1",
                    Nested  = new NestedModel {
                        Integer = 2, String = "test2", Nested = new NestedModel {
                            Integer = 3, String = "test3"
                        }
                    }
                }
            }, out result));

            Assert.Equal("Difference occurs at 'List<NestedModel>[0].Nested.Nested.String'. Expected a value of 'test4', but in fact it was 'test3'", result.ToString());
        }
Esempio n. 26
0
 public static bool NeedsReboot(SyncSettings x, SyncSettings y)
 {
     // the core can handle dynamic plugging and unplugging, but that changes
     // the controllerdefinition, and we're not ready for that
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 27
0
 public static bool NeedsReboot(GBLinkSyncSettings x, GBLinkSyncSettings y)
 {
     return(!DeepEquality.DeepEquals(x, y));
 }
Esempio n. 28
0
        public void AreDeeplyEqualsShouldWorkCorrectlyWithNestedObjects()
        {
            Assert.True(DeepEquality.AreDeeplyEqual(
                            new NestedModel
            {
                Integer = 1,
                String  = "test1",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test2", Nested = new NestedModel {
                        Integer = 3, String = "test3"
                    }
                }
            },
                            new NestedModel
            {
                Integer = 1,
                String  = "test1",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test2", Nested = new NestedModel {
                        Integer = 3, String = "test3"
                    }
                }
            }));

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new NestedModel
            {
                Integer = 1,
                String  = "test",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test2", Nested = new NestedModel {
                        Integer = 3, String = "test3"
                    }
                }
            },
                             new NestedModel
            {
                Integer = 1,
                String  = "test",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test1", Nested = new NestedModel {
                        Integer = 3, String = "test3"
                    }
                }
            }));

            Assert.False(DeepEquality.AreDeeplyEqual(
                             new NestedModel
            {
                Integer = 1,
                String  = "test1",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test2", Nested = new NestedModel {
                        Integer = 3, String = "test2"
                    }
                }
            },
                             new NestedModel
            {
                Integer = 1,
                String  = "test1",
                Enum    = CustomEnum.ConstantWithCustomValue,
                Nested  = new NestedModel {
                    Integer = 2, String = "test2", Nested = new NestedModel {
                        Integer = 3, String = "test3"
                    }
                }
            }));
        }