Example #1
0
            public void ReportsErrorToTheAnalyticsService()
            {
                var exception = new Exception();

                OrchestratorSyncComplete.OnNext(new Error(exception));

                AnalyticsService.Received().TrackAnonymized(exception);
            }
Example #2
0
            public void ReportsOfflineExceptionsToTheAnalyticsServiceAsANormalEvent()
            {
                var exception = new OfflineException();

                OrchestratorSyncComplete.OnNext(new Error(exception));

                AnalyticsService.OfflineModeDetected.Received().Track();
            }
Example #3
0
            public void DoNotReportOfflineExceptionsToTheAnalyticsService()
            {
                var exception = new OfflineException();

                OrchestratorSyncComplete.OnNext(new Error(exception));

                AnalyticsService.DidNotReceive().TrackSyncError(Arg.Any <Exception>());
            }
Example #4
0
            public void TracksSyncError()
            {
                var exception = new Exception();

                OrchestratorSyncComplete.OnNext(new Error(exception));

                AnalyticsService.Received().TrackAnonymized(exception);
                AnalyticsService.Received().SyncFailed.Track(exception.GetType().FullName, exception.Message, exception.StackTrace);
            }
Example #5
0
            public void EmitsFailedWhenSyncFailsWithUnknownException()
            {
                SyncProgress?emitted = null;

                OrchestratorSyncComplete.OnNext(new Error(new Exception()));
                SyncManager.ProgressObservable.Subscribe(progress => emitted = progress);

                emitted.Should().NotBeNull();
                emitted.Should().Be(SyncProgress.Failed);
            }
Example #6
0
            public void DoesNotPreventFurtherSyncingAfterAnErrorWasReported()
            {
                OrchestratorSyncComplete.OnNext(new Error(new Exception()));
                Orchestrator.ClearReceivedCalls();
                Queue.When(q => q.QueuePushSync()).Do(_ => Queue.Dequeue().Returns(Push));

                SyncManager.PushSync();

                Orchestrator.Received().Start(Arg.Is(Push));
            }
Example #7
0
            public void DoesNotTellQueueToStartOrchestratorWhenInSecondPartOfMultiPhaseSync()
            {
                Queue.Dequeue().Returns(Pull);
                SyncManager.ForceFullSync();
                OrchestratorSyncComplete.OnNext(new Success(Push));
                Queue.ClearReceivedCalls();

                CallMethod();

                Queue.DidNotReceive().Dequeue();
            }
Example #8
0
            public void ReportsTheErrorWhenAKnownClientErrorExceptionIsReported(ClientErrorException exception)
            {
                Exception caughtException = null;

                SyncManager.Errors.Subscribe(e => caughtException = e);

                OrchestratorSyncComplete.OnNext(new Error(exception));

                caughtException.Should().NotBeNull();
                caughtException.Should().Be(exception);
            }
Example #9
0
            public void TracksSyncCompleted()
            {
                SyncProgress?emitted = null;

                Queue.Dequeue().Returns(Sleep);

                OrchestratorSyncComplete.OnNext(new Success(Pull));
                SyncManager.ProgressObservable.Subscribe(progress => emitted = progress);

                AnalyticsService.Received().SyncCompleted.Track();
            }
Example #10
0
            public void TellsQueueToStartOrchestratorWhenInSecondPartOfMultiPhaseSync()
            {
                Queue.StartNextQueuedState(Orchestrator).Returns(Pull);
                SyncManager.ForceFullSync();
                OrchestratorSyncComplete.OnNext(Push);
                Queue.ClearReceivedCalls();

                CallMethod();

                Queue.Received().StartNextQueuedState(Orchestrator);
            }
Example #11
0
            public void EmitsNoDefaultWorkspaceErrorWhenSyncFailsWithNoDefaultWorkspaceException()
            {
                Exception caughtException = null;
                var       thrownException = new NoDefaultWorkspaceException();

                SyncManager.Errors.Subscribe(e => caughtException = e);

                OrchestratorSyncComplete.OnNext(new Error(thrownException));

                caughtException.Should().BeSameAs(thrownException);
            }
Example #12
0
            public void EmitsTheLastValueAfterSubscribing()
            {
                SyncProgress?emitted = null;

                OrchestratorSyncComplete.OnNext(new Error(new Exception()));

                SyncManager.ProgressObservable.Subscribe(progress => emitted = progress);

                emitted.Should().NotBeNull();
                emitted.Should().Be(SyncProgress.Failed);
            }
Example #13
0
            public void EmitsFailedWhenAKnownClientErrorExceptionIsReported(ClientErrorException exception)
            {
                SyncProgress?emitted = null;

                SyncManager.ProgressObservable.Subscribe(progress => emitted = progress, (Exception e) => { });

                OrchestratorSyncComplete.OnNext(new Error(exception));

                emitted.Should().NotBeNull();
                emitted.Should().Be(SyncProgress.Failed);
            }
Example #14
0
            public void DoesNotEmitSyncedWhenSyncCompletesButAnotherSyncIsQueued(SyncState queuedState)
            {
                SyncProgress?emitted = null;

                Queue.Dequeue().Returns(queuedState);

                OrchestratorSyncComplete.OnNext(new Success(Pull));
                SyncManager.ProgressObservable.Subscribe(progress => emitted = progress);

                Orchestrator.Received().Start(queuedState);
                emitted.Should().NotBe(SyncProgress.Synced);
            }
Example #15
0
            public void AgainTellsQueueToStartSyncAfterCompletingPreviousPushSync()
            {
                Queue.Dequeue().Returns(Pull);
                SyncManager.PushSync();
                Queue.Dequeue().Returns(Sleep);
                OrchestratorSyncComplete.OnNext(new Success(Push));
                Queue.ClearReceivedCalls();

                CallMethod();

                Queue.Received().Dequeue();
            }
Example #16
0
            public void EmitsSyncedWhenSyncCompletesAndQueueIsEmpty()
            {
                SyncProgress?emitted = null;

                Queue.Dequeue().Returns(Sleep);

                OrchestratorSyncComplete.OnNext(new Success(Pull));
                SyncManager.ProgressObservable.Subscribe(progress => emitted = progress);

                emitted.Should().NotBeNull();
                emitted.Should().Be(SyncProgress.Synced);
            }
Example #17
0
            public void AgainTellsQueueToStartSyncAfterCompletingPreviousFullSync()
            {
                Queue.StartNextQueuedState(Orchestrator).Returns(Pull);
                SyncManager.ForceFullSync();
                Queue.StartNextQueuedState(Orchestrator).Returns(Sleep);
                OrchestratorSyncComplete.OnNext(Pull);
                Queue.ClearReceivedCalls();

                CallMethod();

                Queue.Received().StartNextQueuedState(Orchestrator);
            }
Example #18
0
            public void PerformsThreadSafeClearingOfTheQueue()
            {
                var startQueueing = new AutoResetEvent(false);
                var startClearing = new AutoResetEvent(false);
                var queueCleared  = new AutoResetEvent(false);
                int iterator      = 0;
                int queued        = -1;
                int cleared       = -1;

                Queue.When(q => q.QueuePullSync()).Do(_ =>
                {
                    startClearing.Set();
                    Task.Delay(10).Wait();
                    queued = Interlocked.Increment(ref iterator);
                });

                Queue.When(q => q.Clear()).Do(_ =>
                {
                    cleared = Interlocked.Increment(ref iterator);
                    queueCleared.Set();
                });

                Task.Run(() =>
                {
                    startQueueing.WaitOne();
                    SyncManager.ForceFullSync();
                });

                Task.Run(() =>
                {
                    startClearing.WaitOne();
                    OrchestratorSyncComplete.OnNext(new Error(new Exception()));
                });

                startQueueing.Set();
                queueCleared.WaitOne();

                queued.Should().BeLessThan(cleared);
            }
Example #19
0
            public void GoesToSleepAfterAnErrorIsReported()
            {
                OrchestratorSyncComplete.OnNext(new Error(new Exception()));

                Orchestrator.Received().Start(Arg.Is(Sleep));
            }
Example #20
0
 public async Task DoesNotQueueUntilOtherCompletedEventReturns()
 {
     await ensureMethodIsThreadSafeWith(() => OrchestratorSyncComplete.OnNext(new Success(0)));
 }
Example #21
0
 protected override void CallMethod()
 => OrchestratorSyncComplete.OnNext(new Success(0));
Example #22
0
            public void UpdatesInternalStateSoItIsNotLockedForFutureSyncsAfterAnErrorIsReported()
            {
                OrchestratorSyncComplete.OnNext(new Error(new Exception()));

                SyncManager.IsRunningSync.Should().BeFalse();
            }
Example #23
0
            public void ClearsTheSyncQueueWhenAnErrorIsReported()
            {
                OrchestratorSyncComplete.OnNext(new Error(new Exception()));

                Queue.Received().Clear();
            }
Example #24
0
            public void FreezesTheSyncManagerWhenAKnownClientErrorExceptionIsReported(ClientErrorException exception)
            {
                OrchestratorSyncComplete.OnNext(new Error(exception));

                Orchestrator.Received().Freeze();
            }
Example #25
0
            public void ThrowsWhenAnUnsupportedSyncResultIsEmittedByTheOrchestrator()
            {
                Action emittingUnsupportedResult = () => OrchestratorSyncComplete.OnNext(new UnsupportedResult());

                emittingUnsupportedResult.Should().Throw <ArgumentException>();
            }