public void Compare_MultipleSources_SignleDestination_OneMatch() { List <MergeTestObject> src, dst; src = new List <MergeTestObject>(); dst = new List <MergeTestObject>(); // match 1 - 2 conflicts src.Add(new MergeTestObject() { Property1 = 1, Property2 = 2, Property3 = "foo" }); dst.Add(new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "bar" }); // 'match' 2 - 0 conflicts src.Add(new MergeTestObject() { Property1 = 2, Property2 = 2, Property3 = "foo" }); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.Compare(src, dst); Assert.AreEqual(2, mergeResults.Count()); Assert.AreEqual(2, mergeResults.First(r => r.Instance.Property1 == 1).Conflicts.Count()); Assert.AreEqual(0, mergeResults.First(r => r.Instance.Property1 == 2).Conflicts.Count()); }
public void Compare_GeneratesOneConflictPerProperty() { var instance1 = new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "foo" }; var instance2 = new MergeTestObject() { Property1 = 2, Property2 = 2, Property3 = "bar" }; var merger = MergerHelper.CreateMerger(); var conflicts = merger.CompareAlgorithm.Compare(instance1, instance2); Assert.AreEqual(3, conflicts.Count()); Assert.IsNotNull(conflicts.FirstOrDefault(c => c.PropertyName == "Property1")); Assert.IsNotNull(conflicts.FirstOrDefault(c => c.PropertyName == "Property2")); Assert.IsNotNull(conflicts.FirstOrDefault(c => c.PropertyName == "Property3")); }
public void MergeMissingAndCompare_MergesMissingValue() { List <MergeTestObject> src, dst; src = new List <MergeTestObject>(); dst = new List <MergeTestObject>(); // match 1 - 0 conflicts (AutoMerge resolves the Property3 conflict) src.Add(new MergeTestObject() { Property1 = 1, Property3 = "foo" }); dst.Add(new MergeTestObject() { Property1 = 1, Property3 = null }); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.MergeMissingAndCompare(src, dst); var result = mergeResults.First(); Assert.AreEqual(0, result.Conflicts.Count()); Assert.AreEqual("foo", result.Instance.Property3); }
public void Merge_NoConflicts() { List <MergeTestObject> src, dst; src = new List <MergeTestObject>(); dst = new List <MergeTestObject>(); var source = new MergeTestObject() { Property1 = 1, Property3 = "foo" }; var destination = new MergeTestObject() { Property1 = 2, Property3 = "bar" }; // match 1 - 1 conflicts src.Add(source); dst.Add(destination); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.Merge(src, dst); Assert.IsTrue(mergeResults.All(r => !r.Conflicts.Any())); }
public void Compare_ConflictsHaveCorrectValues() { var instance1 = new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "foo" }; var instance2 = new MergeTestObject() { Property1 = 2, Property2 = 2, Property3 = "bar" }; var merger = MergerHelper.CreateMerger(); var conflicts = merger.CompareAlgorithm.Compare(instance1, instance2); var conflict = conflicts.First(c => c.PropertyName == "Property1"); Assert.AreEqual(instance1.Property1.ToString(), conflict.SourceValue); Assert.AreEqual(instance2.Property1.ToString(), conflict.DestinationValue); conflict = conflicts.First(c => c.PropertyName == "Property2"); Assert.AreEqual(instance1.Property2.ToString(), conflict.SourceValue); Assert.AreEqual(instance2.Property2.ToString(), conflict.DestinationValue); conflict = conflicts.First(c => c.PropertyName == "Property3"); Assert.AreEqual(instance1.Property3.ToString(), conflict.SourceValue); Assert.AreEqual(instance2.Property3.ToString(), conflict.DestinationValue); }
public void Merge_OverwritesAllValues() { List <MergeTestObject> src, dst; src = new List <MergeTestObject>(); dst = new List <MergeTestObject>(); var source = new MergeTestObject() { Property1 = 1, Property3 = "foo" }; var destination = new MergeTestObject() { Property1 = 2, Property3 = "bar" }; // match 1 - 1 conflicts src.Add(source); dst.Add(destination); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.Merge(src, dst); var result = mergeResults.First(); Assert.AreEqual(source.Property1, destination.Property1); Assert.AreEqual(source.Property2, destination.Property2); Assert.AreEqual(source.Property3, destination.Property3); }
public void MergeMissingAndCompare_DoesNotOverwriteExistingValue() { List <MergeTestObject> src, dst; src = new List <MergeTestObject>(); dst = new List <MergeTestObject>(); // match 1 - 1 conflicts src.Add(new MergeTestObject() { Property1 = 1, Property3 = "foo" }); dst.Add(new MergeTestObject() { Property1 = 1, Property3 = "bar" }); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.MergeMissingAndCompare(src, dst); var result = mergeResults.First(); Assert.AreEqual(1, result.Conflicts.Count()); Assert.AreEqual("bar", result.Instance.Property3); }
public void CalculateMatchScore_SameInstanceReturnsMaxPoints() { var instance1 = new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "foo" }; var merger = MergerHelper.CreateMerger(); Assert.AreEqual(int.MaxValue, merger.MatchAlgorithm.CalclateMatchIndex(instance1, instance1)); }
public void CalculateMatchScore_ReturnsZeroForNoMatch() { var instance1 = new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "foo" }; var instance2 = new MergeTestObject() { Property1 = 2, Property2 = 2, Property3 = "bar" }; var merger = MergerHelper.CreateMerger(); Assert.AreEqual(0, merger.MatchAlgorithm.CalclateMatchIndex(instance1, instance2)); }
public void IgnoreProperty_IgnoredPropertiesDontHaveConflicts() { var instance1 = new MergeTestObject() { Property1 = 1, }; var instance2 = new MergeTestObject() { Property1 = 2, }; var merger = MergerHelper.CreateMerger(); merger.CompareAlgorithm.IgnoreProperty(o => o.Property1); var conflicts = merger.CompareAlgorithm.Compare(instance1, instance2); Assert.IsFalse(conflicts.Any()); }
public void ForProperty_DiscoveredPropertiesAreOverridenWithForProperty() { var instance1 = new MergeTestObject() { Property3 = "foo" }; var instance2 = new MergeTestObject() { Property3 = "FOO" }; var merger = MergerHelper.CreateMerger(); // ignore case will result in no conflicts merger.CompareAlgorithm.ForProperty(o => o.Property3, new SoftStringEqualityComparer(StringComparisonOptions.CaseInsensitive)); var conflicts = merger.CompareAlgorithm.Compare(instance1, instance2); Assert.IsFalse(conflicts.Any()); }
public void CalculateMatchScore_UsesSpecifiedEqualityComparer() { // we'll compare mismatched cases using StringComparer.OrdinalIgnoreCase (specified in MergerHelper.CreateMerger) var instance1 = new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "foo" }; var instance2 = new MergeTestObject() { Property1 = 2, Property2 = 2, Property3 = "FOO" }; var merger = MergerHelper.CreateMerger(); Assert.AreEqual(MergerHelper.Property3Score, merger.MatchAlgorithm.CalclateMatchIndex(instance1, instance2)); }
public void Compare_IdenticalObjects_ReturnsOneResultWithNoConflicts() { List <MergeTestObject> source, src, destination, dst; src = source = new List <MergeTestObject>(); dst = destination = new List <MergeTestObject>(); src.Add(new MergeTestObject() { Property1 = 1, Property2 = 2, Property3 = "foo" }); dst.Add(new MergeTestObject() { Property1 = 1, Property2 = 2, Property3 = "foo" }); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.Compare(src, dst); Assert.AreEqual(1, mergeResults.Count()); Assert.AreEqual(0, mergeResults.First().Conflicts.Count()); }
public void Compare_MatchedObjects_ReturnsOneResultWithConflicts() { List <MergeTestObject> src, dst; src = new List <MergeTestObject>(); dst = new List <MergeTestObject>(); src.Add(new MergeTestObject() { Property1 = 1, Property2 = 2, Property3 = "foo" }); dst.Add(new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "bar" }); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.Compare(src, dst); Assert.AreEqual(1, mergeResults.Count()); Assert.AreEqual(2, mergeResults.First().Conflicts.Count()); // Property2 and Property3 don't match }
public void Compare_UnmatchedObjects_ReturnsTwoResultWithNoConflicts() { List <MergeTestObject> src, dst; src = new List <MergeTestObject>(); dst = new List <MergeTestObject>(); // no match src.Add(new MergeTestObject() { Property1 = 1, Property2 = 2, Property3 = "foo" }); dst.Add(new MergeTestObject() { Property1 = 2, Property2 = 1, Property3 = "bar" }); var merger = MergerHelper.CreateMerger(); var mergeResults = merger.Compare(src, dst); Assert.AreEqual(2, mergeResults.Count()); Assert.IsTrue(mergeResults.All(r => r.Conflicts.Count() == 0)); }
public void CalculateMatchScore_ReturnsCorrectMatchScoreTotal() { var instance1 = new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "foo" }; var instance2 = new MergeTestObject() { Property1 = 1, Property2 = 1, Property3 = "foo" }; var merger = MergerHelper.CreateMerger(); var totalScore = MergerHelper.Property1Score + MergerHelper.Property2Score + MergerHelper.Property3Score; Assert.AreEqual(totalScore, merger.MatchAlgorithm.CalclateMatchIndex(instance1, instance2)); }
public void ParameterValidation_IgnoreProperty_ThrowsWhenParamterIsNotPropertyAccess() { var merger = MergerHelper.CreateMerger(); merger.CompareAlgorithm.IgnoreProperty(o => o.NotProperty); }