public void Should_IncludeOnly_DeepPath2() { var provider = new DiffProvider(); var obj1 = new Person { Id = 1, Author = new Author { FirstName = "John", LastName = "Smith", Address = new Address { City = "Los Angeles", Country = "USA" } }, Gender = Genders.Male, Tagline = "Student", }; var obj2 = new Person { Id = 2, Author = new Author { FirstName = "Jane", LastName = "Doe", Address = new Address { City = "Beijing", Country = "China" } }, Gender = Genders.Female, Tagline = "Graduate", }; var diff = provider.ComputeDiff <Person>(obj1, obj2, ComparisonOptions.All | ComparisonOptions.IncludeList, x => x.Author.Address.City, x => x.Author.Address.Country); Assert.AreEqual(2, diff.Count); Assert.AreEqual(".Author.Address.City", diff.First().Path); Assert.AreEqual(".Author.Address.Country", diff.Skip(1).First().Path); }
public void ShouldDetect_Array_NoDifferences() { var provider = new DiffProvider(); var obj1 = new TestObject { IntArray = new int[] { 0, 0, 5, 0, 0 } }; var obj2 = new TestObject { IntArray = new int[] { 0, 0, 5, 0, 0 } }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(0, diff.Count); }
public void ShouldDetect_NullableShorts_AreSame() { var provider = new DiffProvider(); var obj1 = new TestObject { NullableShortValue = 7 }; var obj2 = new TestObject { NullableShortValue = 7 }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(0, diff.Count); }
public void ShouldDetect_Dates_AreSame() { var provider = new DiffProvider(); var obj1 = new TestObject { DateValue = new DateTime(2018, 05, 05, 1, 1, 1) }; var obj2 = new TestObject { DateValue = new DateTime(2018, 05, 05, 1, 1, 1) }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(0, diff.Count); }
public void ShouldDetect_Strings_AreSame() { var provider = new DiffProvider(); var obj1 = new TestObject { StringValue = "Once upon a time there was a little boy named Peter." }; var obj2 = new TestObject { StringValue = "Once upon a time there was a little boy named Peter." }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(0, diff.Count); }
public void ShouldDetect_SBytes_AreNotSame() { var provider = new DiffProvider(); var obj1 = new TestObject { SByteValue = 7 }; var obj2 = new TestObject { SByteValue = 4 }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); }
public void ShouldDetect_Bools_AreSame() { var provider = new DiffProvider(); var obj1 = new TestObject { BoolValue = true }; var obj2 = new TestObject { BoolValue = true }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(0, diff.Count); }
public void If_BaseType_Is_Abstract_And_Both_Objects_Implement_Then_Should_Emit_Whole_Object_If_Types_Different() { var provider = new DiffProvider(); var obj1 = new TypeWithAbstractProperty { Id = "1", AbstractProp = new AbstractImplementation1() }; var obj2 = new TypeWithAbstractProperty { Id = "1", AbstractProp = new AbstractImplementation2() }; var diff = provider.ComputeDiff(obj1, obj2, ComparisonOptions.All | ComparisonOptions.AllowCompareDifferentObjects); Assert.AreEqual(1, diff.Count); }
public void ShouldDetect_Array_OutOfOrder_DifferentCount() { var provider = new DiffProvider(); var obj1 = new TestObject { IntArray = new int[] { 1, 2, 3, 4, 5 } }; var obj2 = new TestObject { IntArray = new int[] { 2, 5, 4, 3, 1, 3 } }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2, ComparisonOptions.All | ComparisonOptions.AllowCollectionsToBeOutOfOrder); Assert.AreEqual(1, diff.Count); }
public void ShouldDetect_NullableDecimals_AreNotSame() { var provider = new DiffProvider(); var obj1 = new TestObject { NullableDecimalValue = 7.0M }; var obj2 = new TestObject { NullableDecimalValue = 4.0M }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); }
public void ShouldNotBeEqual_EmptyList_Null() { var provider = new DiffProvider(); var obj1 = new TestObject { IntCollection = new List <int> { } }; var obj2 = new TestObject { IntCollection = null }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2, ComparisonOptions.All); Assert.AreEqual(1, diff.Count); }
public void Should_IncludeOnly_DeepPath() { var provider = new DiffProvider(); var obj1 = new DeepObject(); var obj2 = new DeepObject(); obj2.DeepChildObject.Id = 999; obj2.DeepChildObject.DeepChild2Object.DeepChild3Object.Name = "Test"; var diff = provider.ComputeDiff <DeepObject>(obj1, obj2, ComparisonOptions.All | ComparisonOptions.IncludeList, x => x.DeepChildObject.DeepChild2Object.DeepChild3Object.Name); Assert.AreEqual(1, diff.Count); Assert.AreEqual(".DeepChildObject.DeepChild2Object.DeepChild3Object.Name", diff.First().Path); }
public void ShouldDetect_NullableInt_SubtractionDeltaWithValue() { var provider = new DiffProvider(); var obj1 = new TestObject { NullableIntValue = 7 }; var obj2 = new TestObject { NullableIntValue = 2 }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(-5, diff.First().Delta); }
public void ShouldDetect_NullableDecimal_SubtractionDelta() { var provider = new DiffProvider(); var obj1 = new TestObject { NullableDecimalValue = 7M }; var obj2 = new TestObject { NullableDecimalValue = null }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(-7M, diff.First().Delta); }
public void ShouldDetect_NullableDate_Delta() { var provider = new DiffProvider(); var obj1 = new TestObject { NullableDateValue = new DateTime(2018, 05, 05, 1, 1, 1) }; var obj2 = new TestObject { NullableDateValue = new DateTime(2018, 05, 05, 1, 1, 1) + TimeSpan.FromMinutes(15) }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(TimeSpan.FromMinutes(15), diff.First().Delta); }
public void ShouldDetect_NullableDecimal_AdditionDeltaWithValue() { var provider = new DiffProvider(); var obj1 = new TestObject { NullableDecimalValue = 1M }; var obj2 = new TestObject { NullableDecimalValue = 5M }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(4M, diff.First().Delta); }
public void ShouldDetect_NullableGuids_AreSame() { var provider = new DiffProvider(); // guids are treated as word detection var obj1 = new TestObject { NullableGuidValue = new Guid("00000000-0000-0000-0000-000000000001") }; var obj2 = new TestObject { NullableGuidValue = new Guid("00000000-0000-0000-0000-000000000001") }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(0, diff.Count); }
public void ShouldDetect_Short_AdditionDelta() { var provider = new DiffProvider(); var obj1 = new TestObject { ShortValue = 1 }; var obj2 = new TestObject { ShortValue = 5 }; var diff = provider.ComputeDiff(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(4, diff.First().Delta); }
public void ShouldDetect_NullableInt_AdditionDelta() { var provider = new DiffProvider(); var obj1 = new TestObject { NullableIntValue = null }; var obj2 = new TestObject { NullableIntValue = 5 }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(5, diff.First().Delta); }
public void ShouldDetect_Double_SubtractionDelta() { var provider = new DiffProvider(); var obj1 = new TestObject { DoubleValue = 7.0 }; var obj2 = new TestObject { DoubleValue = 2.0 }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(-5.0, diff.First().Delta); }
public void ShouldDetect_Hashtable_Differences() { var provider = new DiffProvider(); var obj1 = new System.Collections.Hashtable(); obj1.Add(1, "Test"); obj1.Add(3, "Test"); var obj2 = new System.Collections.Hashtable(); obj2.Add(1, "Test"); obj2.Add(2, "Test"); var diff = provider.ComputeDiff(obj1, obj2, ComparisonOptions.All, "._keys", "._buckets"); Assert.Greater(diff.Count, 0); }
public void ShouldDetect_Hashtable_NoDifferences() { var provider = new DiffProvider(); var obj1 = new System.Collections.Hashtable(); obj1.Add(1, "Test"); obj1.Add(2, "Test"); var obj2 = new System.Collections.Hashtable(); obj2.Add(1, "Test"); obj2.Add(2, "Test"); var diff = provider.ComputeDiff(obj1, obj2); Assert.AreEqual(0, diff.Count); }
public void ShouldDetect_Array_Differences() { var provider = new DiffProvider(); var obj1 = new TestObject { IntArray = new int[] { 0, 0, 5, 0, 0 } }; var obj2 = new TestObject { IntArray = new int[] { 0, 0, 2, 0, 0 } }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreEqual(-3, diff.First().Delta); Assert.AreEqual(2, diff.First().ArrayIndex); }
public void ShouldDetect_Hashtable_CountDifferences2() { var provider = new DiffProvider(); var obj1 = new System.Collections.Hashtable(); obj1.Add(1, "Test"); obj1.Add(2, "Test"); obj1.Add(3, "Test"); var obj2 = new System.Collections.Hashtable(); obj2.Add(1, "Test"); obj2.Add(2, "Test"); var diff = provider.ComputeDiff(obj1, obj2); Assert.Greater(diff.Count, 0); }
public void ShouldNotDetect_TimeSpanDifference_WithoutTypeConverter() { var provider = new DiffProvider(); var obj1 = new NonTypeConverterObject(1) { StartTime = "04:05:00" }; var obj2 = new NonTypeConverterObject(1) { StartTime = "04:06:00" }; var diff = provider.ComputeDiff(obj1, obj2); Assert.AreEqual(1, diff.Count); Assert.AreNotEqual(TimeSpan.FromMinutes(1), diff.First().Delta); }
public void ShouldDetect_ReadOnlyCollection_OutOfOrder_AreDifferent() { var provider = new DiffProvider(); var list = new List <EqualsObject> { new EqualsObject(1, "Testing 1"), new EqualsObject(2, "Testing 2"), }; var list2 = new List <EqualsObject> { new EqualsObject(1, "Testing 1"), new EqualsObject(3, "Testing 3"), }; var obj1 = new ReadOnlyCollectionObject(list); var obj2 = new ReadOnlyCollectionObject(list2); var diff = provider.ComputeDiff <ReadOnlyCollectionObject>(obj1, obj2, ComparisonOptions.All | ComparisonOptions.IncludeList | ComparisonOptions.AllowCollectionsToBeOutOfOrder | ComparisonOptions.AllowEqualsOverride, x => x.Collection); Assert.Greater(diff.Count, 0); }
public void ShouldDetect_List_CountDifferences2() { var provider = new DiffProvider(); var obj1 = new TestObject { IntCollection = new List <int> { 0, 0, 5, 0, 0 } }; var obj2 = new TestObject { IntCollection = new List <int> { 0, 0, 5, 0, 0, 0 } }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); }
public void ShouldDetect_Dictionary_CountDifferences2() { var provider = new DiffProvider(); var obj1 = new TestObject { IntDictionary = new Dictionary <int, string> { { 0, "1" }, { 1, "2" }, { 2, "3" }, { 3, "4" }, { 4, "5" } } }; var obj2 = new TestObject { IntDictionary = new Dictionary <int, string> { { 0, "1" }, { 1, "2" }, { 2, "3" }, { 3, "4" }, { 4, "5" }, { 5, "6" } } }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); }
public void ShouldDetect_Guids_AreDifferent() { var provider = new DiffProvider(); // guids are treated as word detection var obj1 = new TestObject { GuidValue = new Guid("00000000-0000-0000-0000-000000000001") }; var obj2 = new TestObject { GuidValue = new Guid("00000000-0000-0000-0000-00000000000a") }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); var deltas = ((DifferenceWords.WordDifferences)diff.First().Delta); Assert.AreEqual("00000000000a", deltas.Additions.First()); Assert.AreEqual("000000000001", deltas.Deletions.First()); }
public void ShouldDetect_Strings_AreDifferent() { var provider = new DiffProvider(); var obj1 = new TestObject { StringValue = "Once upon a time there was a little boy named Peter." }; var obj2 = new TestObject { StringValue = "Once upon a time there was a little girl named Paula." }; var diff = provider.ComputeDiff <TestObject>(obj1, obj2); Assert.AreEqual(1, diff.Count); var deltas = ((DifferenceWords.WordDifferences)diff.First().Delta); Assert.AreEqual("girl", deltas.Additions.First()); Assert.AreEqual("Paula", deltas.Additions.Skip(1).First()); Assert.AreEqual("boy", deltas.Deletions.First()); Assert.AreEqual("Peter", deltas.Deletions.Skip(1).First()); }