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}}}"); }
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; } }))); }
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 Sync_ComparerAgentNotSet() { List <int> source = new List <int> { 5, 4, 9 } , destination = new List <int> { 6, 10, 5 }; Func <Task> act = async() => await SyncAgent <int> .Create() .SyncAsync(CancellationToken.None).ConfigureAwait(false); act.Should().Throw <NullReferenceException>().WithMessage($"The {nameof(SyncAgent<int>.ComparerAgent)} 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 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 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 void Sync_DestinationComparerSyncProviderIsSetWithoutSettingComparerAgent() { ListSyncProvider <int> source = new ListSyncProvider <int> { Items = new List <int> { 5, 4, 9 } } , destination = new ListSyncProvider <int> { Items = new List <int> { 6, 10, 5 } }; Func <Task> act = async() => await SyncAgent <int> .Create() .Configure((c) => c.SyncMode.SyncModePreset = SyncModePreset.MirrorToDestination) .SetDestinationProvider(destination) .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_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 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 }); }