Пример #1
0
        public void SyncMode_VerifyGetterAndSetter(SyncModePreset syncModePreset)
        {
            var syncMode = new SyncMode {
                SyncModePreset = syncModePreset
            };

            syncMode.SyncModePreset.Should().Be(syncModePreset);
            syncMode.ToString().Should().Be($"{nameof(SyncMode.SyncModePreset)}: {syncMode.SyncModePreset}");
        }
        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 Sync_Class_WithExternalComparerAgent(SyncModePreset syncModePreset)
        {
            var syncAgent = CreateSyncAgent();
            DictionaryBatchSyncProvider <int?, Event> source = new DictionaryBatchSyncProvider <int?, Event> {
                Items = CreateSourceEventDictionary(), KeySelector = syncAgent.KeySelector
            }
            , destination = new DictionaryBatchSyncProvider <int?, Event> {
                Items = CreateDestinationEventDictionary(), KeySelector = syncAgent.KeySelector
            };

            var keyComparisonResult = await KeyComparerAgent <int?> .Create()
                                      .SetSourceProvider(source.Items.Keys)
                                      .SetDestinationProvider(destination.Items.Keys)
                                      .CompareAsync(CancellationToken.None);

            // The sync agent should handle changes to source and destination gracefully.
            if (syncModePreset == SyncModePreset.MirrorToDestination)
            {
                await source.DeleteAsync(new List <int?> {
                    5
                }, CancellationToken.None).ConfigureAwait(false);
            }
            else if (syncModePreset == SyncModePreset.MirrorToSource)
            {
                await destination.DeleteAsync(new List <int?> {
                    5
                }, CancellationToken.None).ConfigureAwait(false);
            }

            await syncAgent
            .Configure((c) => c.SyncMode.SyncModePreset = syncModePreset)
            .SetComparerAgent(null)
            .SetSourceProvider((IBatchSyncProvider <int?, Event>)source)
            .SetDestinationProvider((IBatchSyncProvider <int?, Event>)destination)
            .SyncAsync(keyComparisonResult, CancellationToken.None).ConfigureAwait(false);

            source.Items.Should().BeEquivalentTo(destination.Items);
        }