private static ISyncAgent <int?, Event> CreateSyncAgent() { return(SyncAgent <int?, Event> .Create() .SetComparerAgent(ComparerAgent <int?, Event> .Create() .SetKeySelector(x => x.Id) .SetCompareItemFunc((s, d) => { if (s.Title == d.Title && s.ModifiedDate == d.ModifiedDate) { return MatchComparisonResultType.Same; } else if (s.ModifiedDate < d.ModifiedDate) { return MatchComparisonResultType.NewerDestination; } else if (s.ModifiedDate > d.ModifiedDate) { return MatchComparisonResultType.NewerSource; } else { return MatchComparisonResultType.Conflict; } }))); }
public async Task Compare_String_NonEmptyLists_WithCaseInsensitiveComparer() { List <string> source = new List <string> { "Tom", "Tim", "bob", "Zoo" } , destination = new List <string> { "Bob", "Sam", "Tim" }; var comparisonResult = await ComparerAgent <string> .Create() .SetKeySelector(x => x?.ToLower()) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEquivalentTo(new List <string> { "Tom", "Zoo" }); comparisonResult.ItemsInDestinationOnly.Should().BeEquivalentTo(new List <string> { "Sam" }); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <string> > { new MatchComparisonResult <string> { Source = "Tim", Destination = "Tim", ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <string> { Source = "bob", Destination = "Bob", ComparisonResult = MatchComparisonResultType.Conflict } }); }
public async Task Compare_String_WithCaseInsensitiveKeySelector_AndTwoNullableItemsOnly() { List <string> source = new List <string> { null, null } , destination = new List <string> { null, null }; var comparisonResult = await ComparerAgent <string> .Create() .SetKeySelector(x => x?.ToLower()) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEmpty(); comparisonResult.ItemsInDestinationOnly.Should().BeEmpty(); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <string> > { new MatchComparisonResult <string> { Source = null, Destination = null, ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <string> { Source = null, Destination = null, ComparisonResult = MatchComparisonResultType.Same } }); }
public async Task Compare_String_WithCaseSensitiveComparer_AndNullableItems() { List <string> source = new List <string> { null, "Tim", "bob", null } , destination = new List <string> { "Bob", null, "Tim" }; var comparisonResult = await ComparerAgent <string> .Create() .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEquivalentTo(new List <string> { null, "bob" }); comparisonResult.ItemsInDestinationOnly.Should().BeEquivalentTo(new List <string> { "Bob" }); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <string> > { new MatchComparisonResult <string> { Source = null, Destination = null, ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <string> { Source = "Tim", Destination = "Tim", ComparisonResult = MatchComparisonResultType.Same } }); }
public async Task Compare_String_WithCaseInsensitiveCompareItemFunc_AndTwoNullableItemsOnly() { List <string> source = new List <string> { null, null } , destination = new List <string> { null, null }; var comparisonResult = await ComparerAgent <string> .Create() .SetCompareItemFunc((s, d) => string.Equals(s, d, StringComparison.OrdinalIgnoreCase) ? MatchComparisonResultType.Same : MatchComparisonResultType.Conflict) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEmpty(); comparisonResult.ItemsInDestinationOnly.Should().BeEmpty(); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <string> > { new MatchComparisonResult <string> { Source = null, Destination = null, ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <string> { Source = null, Destination = null, ComparisonResult = MatchComparisonResultType.Same } }); }
public async Task Compare_ClassWithNullableKey_HasDuplicatesInSource() { List <Person> source = new List <Person> { new Person { Id = 1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = 1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = null, FirstName = "Abby", LastName = "Smith", DOB = null }, new Person { Id = null, FirstName = "Abby", LastName = "Smith", DOB = null }, new Person(), new Person(), new Person { Id = 3, FirstName = "Joe", LastName = "jim", DOB = null }, new Person { Id = 3, FirstName = "Joe", LastName = "jim", DOB = null } } , destination = new List <Person> { new Person { Id = 3, FirstName = "Joe", LastName = "Jim", DOB = null }, new Person { Id = 1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = 2, FirstName = "Tom", LastName = "Tim", DOB = null } }; var comparisonResult = await ComparerAgent <int?, Person> .Create() .SetKeySelector(person => person.Id) .SetCompareItemFunc((s, d) => (s.Id == d.Id && s.FirstName == d.FirstName && s.LastName == d.LastName && s.DOB == d.DOB) ? MatchComparisonResultType.Same : MatchComparisonResultType.Conflict) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEquivalentTo(new List <Person> { source[1], source[2], source[3], source[4], source[5], source[7] }); comparisonResult.ItemsInDestinationOnly.Should().BeEquivalentTo(new List <Person> { destination[2] }); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <Person> > { new MatchComparisonResult <Person> { Source = source[0], Destination = destination[1], ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <Person> { Source = source[6], Destination = destination[0], ComparisonResult = MatchComparisonResultType.Conflict }, }); }
public async Task Compare_Int_EquivalentLists() { List <int> source = new List <int> { 10, 30, 20 } , destination = new List <int> { 20, 10, 30 }; var comparisonResult = await ComparerAgent <int> .Create() .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEmpty(); comparisonResult.ItemsInDestinationOnly.Should().BeEmpty(); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <int> > { new MatchComparisonResult <int> { Source = 10, Destination = 10, ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <int> { Source = 20, Destination = 20, ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <int> { Source = 30, Destination = 30, ComparisonResult = MatchComparisonResultType.Same } }); }
public async Task SyncAgentWithValidSyncProvidersShouldSync() { ListSyncProvider <int> source = new ListSyncProvider <int> { Items = new List <int> { 5, 4, 9 } } , destination = new ListSyncProvider <int> { Items = new List <int> { 6, 10, 5 } }; var syncAgent = SyncAgent <int> .Create() .Configure((c) => c.SyncMode.SyncModePreset = SyncModePreset.MirrorToDestination) .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SetDestinationProvider(destination); await syncAgent.SyncAsync(CancellationToken.None).ConfigureAwait(false); source.Items.Should().BeEquivalentTo(new List <int> { 5, 4, 9 }); destination.Items.Should().BeEquivalentTo(source.Items); syncAgent.ToString().Should().Be($"{nameof(syncAgent.Configurations)}: {{{syncAgent.Configurations}}}"); }
protected static ISyncAgent <string, string> CreateSyncAgent(SortedSet <string> sourceItems, SortedSet <string> destinationItems) { return(SyncAgent <string> .Create() .SetComparerAgent(ComparerAgent <string> .Create() .SetKeySelector(x => x?.ToLower()) .SetCompareItemFunc((s, d) => s == d ? MatchComparisonResultType.Same : MatchComparisonResultType.Conflict)) .SetSourceProvider(sourceItems) .SetDestinationProvider(destinationItems)); }
public void Compare_Int_NoDestinationProvider() { List <int> source = new List <int>(); Func <Task> act = async() => await ComparerAgent <int> .Create() .SetSourceProvider(source) .CompareAsync(CancellationToken.None).ConfigureAwait(false); act.Should().Throw <NullReferenceException>().WithMessage($"The {nameof(ComparerAgent<int>.DestinationProvider)} cannot be null."); }
public void ComparerAgentShouldHaveValidString() { List <int> source = new List <int>() , destination = new List <int>(); var comparerAgent = ComparerAgent <int> .Create() .SetSourceProvider(source) .SetDestinationProvider(destination); comparerAgent.ToString().Should().Be($"{nameof(comparerAgent.Configurations)}: {{{comparerAgent.Configurations}}}"); }
public async Task Compare_ClassWithCompoundKey_NonEmptyLists() { List <PersonHobby> source = new List <PersonHobby> { new PersonHobby { PersonId = 10, HobbyId = 100, LoveScale = 1 }, new PersonHobby { PersonId = 10, HobbyId = 101, LoveScale = null }, new PersonHobby { PersonId = 10, HobbyId = 102, LoveScale = 2 }, new PersonHobby { PersonId = 20, HobbyId = 100, LoveScale = 3 }, new PersonHobby() } , destination = new List <PersonHobby> { new PersonHobby { PersonId = 10, HobbyId = 100, LoveScale = 1 }, new PersonHobby { PersonId = 30, HobbyId = 101, LoveScale = null }, new PersonHobby { PersonId = 20, HobbyId = 100, LoveScale = 4 }, }; var comparisonResult = await ComparerAgent <Tuple <int?, int?>, PersonHobby> .Create() .SetKeySelector(x => new Tuple <int?, int?>(x.PersonId, x.HobbyId)) .SetCompareItemFunc((s, d) => (s.PersonId == d.PersonId && s.HobbyId == d.HobbyId && s.LoveScale == d.LoveScale) ? MatchComparisonResultType.Same : MatchComparisonResultType.Conflict) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEquivalentTo(new List <PersonHobby> { source[1], source[2], source[4] }); comparisonResult.ItemsInDestinationOnly.Should().BeEquivalentTo(new List <PersonHobby> { destination[1] }); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <PersonHobby> > { new MatchComparisonResult <PersonHobby> { Source = source[0], Destination = destination[0], ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <PersonHobby> { Source = source[3], Destination = destination[2], ComparisonResult = MatchComparisonResultType.Conflict }, }); }
public async Task SyncWithExternalComparerAgent(SyncModePreset syncModePreset) { var syncAgent = CreateSyncAgent(); SortedSetSyncProvider <Event> source = new SortedSetSyncProvider <Event> { Items = CreateSourceEventSortedSet() } , destination = new SortedSetSyncProvider <Event> { Items = CreateDestinationEventSortedSet() }; var comparisonResult = await ComparerAgent <int?, Event> .Create() .Configure((c) => { c.AllowDuplicateKeys = RuleAllowanceType.None; c.AllowDuplicateItems = RuleAllowanceType.None; c.AllowNullableItems = RuleAllowanceType.None; }) .SetKeySelector(x => x.Id) .SetCompareItemFunc((s, d) => { if (s.Title == d.Title && s.ModifiedDate == d.ModifiedDate) { return(MatchComparisonResultType.Same); } else if (s.ModifiedDate < d.ModifiedDate) { return(MatchComparisonResultType.NewerDestination); } else if (s.ModifiedDate > d.ModifiedDate) { return(MatchComparisonResultType.NewerSource); } else { return(MatchComparisonResultType.Conflict); } }) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None); await syncAgent .Configure((c) => c.SyncMode.SyncModePreset = syncModePreset) .SetComparerAgent(null) .SetSourceProvider((ISyncProvider <Event>)source) .SetDestinationProvider((ISyncProvider <Event>)destination) .SyncAsync(comparisonResult, CancellationToken.None).ConfigureAwait(false); source.Items.Should().BeEquivalentTo(destination.Items); }
public async Task Compare_Int_EmptyLists() { List <int> source = new List <int>() , destination = new List <int>(); var comparisonResult = await ComparerAgent <int> .Create() .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEmpty(); comparisonResult.ItemsInDestinationOnly.Should().BeEmpty(); comparisonResult.Matches.Should().BeEmpty(); }
public void Compare_ClassWithNullableKey_PreventDuplicatesInSourceUsingItemEqualityComparer() { List <Person> source = new List <Person> { new Person { Id = 1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = 1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = null, FirstName = "Abby", LastName = "Smith", DOB = null }, new Person { Id = null, FirstName = "Abby", LastName = "Smith", DOB = null }, new Person(), new Person(), new Person(), new Person { Id = null, FirstName = "Abby", LastName = "Smith", DOB = null }, new Person { Id = 3, FirstName = "Joe", LastName = "jim", DOB = null }, new Person { Id = null, FirstName = "Abby", LastName = "Smith", DOB = null } } , destination = new List <Person> { new Person { Id = 3, FirstName = "Joe", LastName = "Jim", DOB = null }, new Person { Id = 1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = 2, FirstName = "Tom", LastName = "Tim", DOB = null } }; Func <Task> act = async() => await ComparerAgent <int?, Person> .Create() .Configure((c) => c.AllowDuplicateItems = RuleAllowanceType.None) .SetKeySelector(person => person.Id) .SetCompareItemFunc((s, d) => (s.Id == d.Id && s.FirstName == d.FirstName && s.LastName == d.LastName && s.DOB == d.DOB) ? MatchComparisonResultType.Same : MatchComparisonResultType.Conflict) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); act.Should().Throw <ArgumentException>().WithMessage("Duplicated items are not allowed in the source list, 6 items were found."); }
public void Sync_SortedSet_DestinationSyncProviderIsSetToNullableSet() { SortedSet <int> source = new SortedSet <int> { 6, 10, 5 } , destination = null; Func <Task> act = async() => await SyncAgent <int> .Create() .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SetDestinationProvider(destination) .SyncAsync(CancellationToken.None).ConfigureAwait(false); act.Should().Throw <NullReferenceException>().WithMessage("The destination items cannot be null."); }
public async Task Sync_MirrorToSource_Int_WithEmptyLists() { List <int> source = new List <int>() , destination = new List <int>(); await SyncAgent <int> .Create() .Configure((c) => c.SyncMode.SyncModePreset = SyncModePreset.MirrorToSource) .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SetDestinationProvider(destination) .SyncAsync(CancellationToken.None).ConfigureAwait(false); source.Should().BeEmpty(); destination.Should().BeEmpty(); }
public void Compare_Int_NullableCompareItemFunc() { List <int> source = new List <int>() , destination = new List <int>(); var comparerAgent = ComparerAgent <int> .Create() .SetSourceProvider(source) .SetDestinationProvider(destination); comparerAgent.CompareItemFunc = null; Func <Task> act = async() => await comparerAgent .CompareAsync(CancellationToken.None).ConfigureAwait(false); act.Should().ThrowAsync <NullReferenceException>().WithMessage($"The {nameof(ComparerAgent<int>.CompareItemFunc)} cannot be null."); }
public void Sync_DestinationSyncProviderNotSet() { List <int> source = new List <int> { 5, 4, 9 } , destination = new List <int> { 6, 10, 5 }; Func <Task> act = async() => await SyncAgent <int> .Create() .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SyncAsync(CancellationToken.None).ConfigureAwait(false); act.Should().Throw <NullReferenceException>().WithMessage($"The {nameof(SyncAgent<int>.DestinationProvider)} cannot be null."); }
public void Compare_ClassWithNullableKey_PreventNegativeIdsInDestination() { List <Person> source = new List <Person> { new Person { Id = 3, FirstName = "Joe", LastName = "Jim", DOB = null }, new Person { Id = 1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = 2, FirstName = "Tom", LastName = "Tim", DOB = null } } , destination = new List <Person> { new Person { Id = -1, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) }, new Person { Id = -2, FirstName = "Tom", LastName = "Smith", DOB = new DateTime(2000, 1, 1) } }; Func <Task> act = async() => await ComparerAgent <int?, Person> .Create() .SetValidateItemsAction((s, d) => { int count = s.Count(x => x.Id < 0); if (count > 0) { throw new ArgumentException(string.Format("Negative Ids are invalid in the source list, {0} item{1} {2} found." , count, count == 1 ? "" : "s", count == 1 ? "was" : "were")); } count = d.Count(x => x.Id < 0); if (count > 0) { throw new ArgumentException(string.Format("Negative Ids are invalid in the destination list, {0} item{1} {2} found." , count, count == 1 ? "" : "s", count == 1 ? "was" : "were")); } }) .SetKeySelector(person => person.Id) .SetCompareItemFunc((s, d) => (s.Id == d.Id && s.FirstName == d.FirstName && s.LastName == d.LastName && s.DOB == d.DOB) ? MatchComparisonResultType.Same : MatchComparisonResultType.Conflict) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); act.Should().Throw <ArgumentException>().WithMessage("Negative Ids are invalid in the destination list, 2 items were found."); }
public void Compare_Int_PreventDuplicatesInSource() { List <int> source = new List <int> { 10, 10 } , destination = new List <int> { 20, 20 }; Func <Task> act = async() => await ComparerAgent <int> .Create() .Configure((c) => c.AllowDuplicateKeys = RuleAllowanceType.Destination) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); act.Should().ThrowAsync <ArgumentException>().WithMessage("Duplicated items are not allowed in the source list, 1 item was found."); }
public void Compare_Int_PreventNullableItemsInDestination() { List <int?> source = new List <int?> { 10, null } , destination = new List <int?> { 20, null }; Func <Task> act = async() => await ComparerAgent <int?> .Create() .Configure((c) => c.AllowNullableItems = RuleAllowanceType.Source) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); act.Should().ThrowAsync <ArgumentException>().WithMessage("Null-able items are not allowed in the destination list, 1 item was found."); }
public void Sync_SortedSet_DestinationSyncProviderMustBeSetAfterSettingComparerAgent() { SortedSet <int> source = new SortedSet <int> { 5, 4, 9 } , destination = new SortedSet <int> { 6, 10, 5 }; Func <Task> act = async() => await SyncAgent <int> .Create() .SetDestinationProvider(destination) .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SyncAsync(CancellationToken.None).ConfigureAwait(false); act.Should().Throw <NullReferenceException>().WithMessage($"The {nameof(SyncAgent<int>.ComparerAgent)} must be set first."); }
public async Task Sync_UpdateSource_Int_WithEmptyDestination() { List <int> source = new List <int> { 5, 4, 9 } , destination = new List <int>(); await SyncAgent <int> .Create() .Configure((c) => c.SyncMode.SyncModePreset = SyncModePreset.UpdateSource) .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SetDestinationProvider(destination) .SyncAsync(CancellationToken.None).ConfigureAwait(false); source.Should().BeEquivalentTo(new List <int> { 5, 4, 9 }); destination.Should().BeEmpty(); }
public async Task Sync_TwoWay_Int_WithEmptySourceList() { List <int> source = new List <int>() , destination = new List <int> { 6, 10, 5 }; await SyncAgent <int> .Create() .Configure((c) => c.SyncMode.SyncModePreset = SyncModePreset.TwoWay) .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SetDestinationProvider(destination) .SyncAsync(CancellationToken.None).ConfigureAwait(false); source.Should().BeEquivalentTo(new List <int> { 6, 10, 5 }); destination.Should().BeEquivalentTo(new List <int> { 6, 10, 5 }); }
public async Task Compare_String_WithCaseSensitiveComparer_AndNullableItemsInDestination() { List <string> source = new List <string> { "Tom" } , destination = new List <string> { null }; var comparisonResult = await ComparerAgent <string> .Create() .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEquivalentTo(new List <string> { "Tom" }); comparisonResult.ItemsInDestinationOnly.Should().BeEquivalentTo(new List <string> { null }); comparisonResult.Matches.Should().BeEmpty(); }
public async Task Sync_MirrorToDestination_Int_NonEmptyLists() { List <int> source = new List <int> { 5, 4, 9 } , destination = new List <int> { 6, 10, 5 }; await SyncAgent <int> .Create() .Configure((c) => c.SyncMode.SyncModePreset = SyncModePreset.MirrorToDestination) .SetComparerAgent(ComparerAgent <int> .Create()) .SetSourceProvider(source) .SetDestinationProvider(destination) .SyncAsync(CancellationToken.None).ConfigureAwait(false); source.Should().BeEquivalentTo(new List <int> { 5, 4, 9 }); destination.Should().BeEquivalentTo(new List <int> { 5, 4, 9 }); }
/// <summary> /// Synchronizes the items that exist in the source and destination. /// </summary> /// <param name="batchKeys">The keys of the items.</param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param> /// <returns></returns> private async Task SyncMatchesBatchAsync(List <TKey> batchKeys, CancellationToken cancellationToken) { var srcTask = SourceProvider.GetAsync(batchKeys, cancellationToken); var dstTask = DestinationProvider.GetAsync(batchKeys, cancellationToken); await Task.WhenAll(srcTask, dstTask); // Compare var comparisonResult = await ComparerAgent <TKey, TItem> .Create() .Configure((c) => { c.AllowDuplicateItems = RuleAllowanceType.None; c.AllowDuplicateKeys = RuleAllowanceType.None; c.AllowNullableItems = RuleAllowanceType.None; }) .SetKeySelector(KeySelector) .SetCompareItemFunc(CompareItemFunc) .SetSourceProvider(srcTask.Result) .SetDestinationProvider(dstTask.Result) .CompareAsync(cancellationToken).ConfigureAwait(false); // Sync await SyncAsync(comparisonResult, cancellationToken).ConfigureAwait(false); }
public async Task Compare_ClassWithNullableKey_Updated() { List <Event> source = new List <Event> { new Event { Id = 2, Title = "Birthday", ModifiedDate = new DateTime(2000, 1, 1) }, new Event { Id = 1, Title = "soccer match", ModifiedDate = new DateTime(2000, 1, 2) }, new Event { Id = null, Title = "Private", ModifiedDate = null }, new Event(), new Event { Id = 4, Title = "Hang-out", ModifiedDate = new DateTime(2000, 1, 2) }, new Event { Id = 5, Title = "bad", ModifiedDate = new DateTime(2000, 1, 8) } } , destination = new List <Event> { new Event { Id = 1, Title = "Soccer Match", ModifiedDate = new DateTime(2000, 1, 3) }, new Event { Id = 2, Title = "Birthday", ModifiedDate = new DateTime(2000, 1, 1) }, new Event { Id = 3, Title = "Free-time", ModifiedDate = null }, new Event { Id = 4, Title = "hang-out", ModifiedDate = new DateTime(2000, 1, 1) }, new Event { Id = 5, Title = "Bad", ModifiedDate = new DateTime(2000, 1, 8) } }; var comparisonResult = await ComparerAgent <int?, Event> .Create() .SetKeySelector(e => e.Id) .SetCompareItemFunc((s, d) => { if (s.Title == d.Title && s.ModifiedDate == d.ModifiedDate) { return(MatchComparisonResultType.Same); } else if (s.ModifiedDate < d.ModifiedDate) { return(MatchComparisonResultType.NewerDestination); } else if (s.ModifiedDate > d.ModifiedDate) { return(MatchComparisonResultType.NewerSource); } else { return(MatchComparisonResultType.Conflict); } }) .SetSourceProvider(source) .SetDestinationProvider(destination) .CompareAsync(CancellationToken.None).ConfigureAwait(false); comparisonResult.ItemsInSourceOnly.Should().BeEquivalentTo(new List <Event> { source[2], source[3] }); comparisonResult.ItemsInDestinationOnly.Should().BeEquivalentTo(new List <Event> { destination[2] }); comparisonResult.Matches.Should().BeEquivalentTo(new List <MatchComparisonResult <Event> > { new MatchComparisonResult <Event> { Source = source[1], Destination = destination[0], ComparisonResult = MatchComparisonResultType.NewerDestination }, new MatchComparisonResult <Event> { Source = source[0], Destination = destination[1], ComparisonResult = MatchComparisonResultType.Same }, new MatchComparisonResult <Event> { Source = source[4], Destination = destination[3], ComparisonResult = MatchComparisonResultType.NewerSource }, new MatchComparisonResult <Event> { Source = source[5], Destination = destination[4], ComparisonResult = MatchComparisonResultType.Conflict }, }); }