Ejemplo n.º 1
0
        public async Task NoRefreshThrottleAllowsCalls()
        {
            var currentThrottle = TrelloConfiguration.RefreshThrottle;

            try
            {
                MockHost.MockJson();
                MockHost.JsonFactory.Setup(f => f.Create <SynchronizedData>())
                .Returns(new SynchronizedData());

                TrelloConfiguration.RefreshThrottle = TimeSpan.Zero;

                var target = new SynchronizedObject();

                await target.Synchronize(false, CancellationToken.None);

                await target.Synchronize(false, CancellationToken.None);

                target.RetrievalCount.Should().Be(2);
            }
            finally
            {
                TrelloConfiguration.RefreshThrottle = currentThrottle;
            }
        }
Ejemplo n.º 2
0
        public void MergeRaisesSynchronizedEvent()
        {
            MockHost.MockJson();
            MockHost.JsonFactory.Setup(f => f.Create <SynchronizedData>())
            .Returns(new SynchronizedData());

            TrelloConfiguration.RefreshThrottle = TimeSpan.FromDays(1);

            var counter = 0;

            var target = new SynchronizedObject
            {
                NewData = new SynchronizedData {
                    Test = "one"
                }
            };

            target.PublicSynchronized += properties => counter++;

            target.Merge(new SynchronizedData {
                Test = "two"
            });

            counter.Should().Be(1);
            target.Data.Test.Should().Be("two");
        }
Ejemplo n.º 3
0
        public async Task ForcedRefreshOverridesThrottle()
        {
            var currentThrottle = TrelloConfiguration.RefreshThrottle;

            try
            {
                MockHost.MockJson();
                MockHost.JsonFactory.Setup(f => f.Create <SynchronizedData>())
                .Returns(new SynchronizedData());

                TrelloConfiguration.RefreshThrottle = TimeSpan.FromDays(1);

                var target = new SynchronizedObject();

                await target.Synchronize(true, CancellationToken.None);

                await target.Synchronize(true, CancellationToken.None);

                target.RetrievalCount.Should().Be(2);
            }
            finally
            {
                TrelloConfiguration.RefreshThrottle = currentThrottle;
            }
        }
Ejemplo n.º 4
0
        public async Task SynchronizeRaisesSynchronizedEvent()
        {
            var currentThrottle = TrelloConfiguration.RefreshThrottle;

            try
            {
                MockHost.MockJson();
                MockHost.JsonFactory.Setup(f => f.Create <SynchronizedData>())
                .Returns(new SynchronizedData());

                TrelloConfiguration.RefreshThrottle = TimeSpan.FromDays(1);

                var counter = 0;

                var target = new SynchronizedObject
                {
                    NewData = new SynchronizedData {
                        Test = "one"
                    }
                };
                target.PublicSynchronized += properties => counter++;

                await target.Synchronize(false, CancellationToken.None);

                counter.Should().Be(1);
            }
            finally
            {
                TrelloConfiguration.RefreshThrottle = currentThrottle;
            }
        }
Ejemplo n.º 5
0
        public void GetValueDoesNotRetrieve()
        {
            MockHost.MockJson();
            MockHost.JsonFactory.Setup(f => f.Create <SynchronizedData>())
            .Returns(new SynchronizedData());

            var target = new SynchronizedObject();

            var value = target.GetValue <string>(nameof(SynchronizedData.Test));

            value.Should().Be("default");
            target.RetrievalCount.Should().Be(0);
        }
Ejemplo n.º 6
0
        public async Task UnsupportedUpdateSkipsSubmission()
        {
            MockHost.MockJson();
            MockHost.JsonFactory.Setup(f => f.Create <SynchronizedData>())
            .Returns(new SynchronizedData());

            var target = new SynchronizedObject {
                SupportsUpdates = false
            };

            await target.Synchronize(false, CancellationToken.None);

            target.SubmissionCount.Should().Be(0);
        }
Ejemplo n.º 7
0
        public async Task SettingDataMergesRequests()
        {
            MockHost.MockJson();
            MockHost.JsonFactory.Setup(f => f.Create <SynchronizedData>())
            .Returns(new SynchronizedData());

            TrelloConfiguration.ChangeSubmissionTime = TimeSpan.FromMilliseconds(100);

            var target = new SynchronizedObject();

            await target.SetValue(nameof(SynchronizedData.Test), "one", CancellationToken.None);

            await target.SetValue(nameof(SynchronizedData.Test), "two", CancellationToken.None);

            await Task.Delay(150);

            target.SubmissionCount.Should().Be(1);
        }