コード例 #1
0
ファイル: SyncAgentTests.cs プロジェクト: Shereef/FluentSync
        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}}}");
        }
コード例 #2
0
 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;
         }
     })));
 }
コード例 #3
0
 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));
 }
コード例 #4
0
ファイル: SyncAgentTests.cs プロジェクト: Shereef/FluentSync
        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.");
        }
コード例 #5
0
        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();
        }
コード例 #6
0
ファイル: SyncAgentTests.cs プロジェクト: Shereef/FluentSync
        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.");
        }
コード例 #7
0
ファイル: SyncAgentTests.cs プロジェクト: Shereef/FluentSync
        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.");
        }
コード例 #8
0
        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();
        }
コード例 #9
0
ファイル: SyncAgentTests.cs プロジェクト: Shereef/FluentSync
        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.");
        }
コード例 #10
0
        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
            });
        }
コード例 #11
0
        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
            });
        }