Esempio n. 1
0
            public async Task SubscribesToResumingFromBackgroundSignal()
            {
                AutomaticSyncingService.SetupAutomaticSync(UserAccessManager);
                LoggedIn.OnNext(DataSource);
                AppResumedFromBackground.OnNext(MinimumTimeInBackgroundForFullSync);

                await SyncManager.Received().ForceFullSync();
            }
Esempio n. 2
0
            public async Task StopsWhenSyncManagerFails()
            {
                var midnightSubject = new Subject <DateTimeOffset>();

                TimeService.MidnightObservable.Returns(midnightSubject);

                AutomaticSyncingService.SetupAutomaticSync(UserAccessManager);
                LoggedIn.OnNext(DataSource);
                midnightSubject.OnNext(new DateTimeOffset(2018, 12, 17, 00, 00, 00, TimeSpan.Zero));

                await SyncManager.Received().CleanUp();
            }
Esempio n. 3
0
            public void UnsubscribesFromTheBackgroundServiceObservableWhenExceptionIsCaught()
            {
                var subject       = new Subject <TimeSpan>();
                var errorsSubject = new Subject <Exception>();

                BackgroundService.AppResumedFromBackground.Returns(subject.AsObservable());
                SyncManager.Errors.Returns(errorsSubject);

                AutomaticSyncingService.SetupAutomaticSync(UserAccessManager);
                LoggedIn.OnNext(DataSource);
                SyncManager.ClearReceivedCalls();
                errorsSubject.OnNext(new Exception());
                subject.OnNext(MinimumTimeInBackgroundForFullSync);

                SyncManager.DidNotReceive().ForceFullSync();
            }
Esempio n. 4
0
            public async Task UnsubscribesFromTheSignalAfterLogout()
            {
                var subject = new Subject <TimeSpan>();

                BackgroundService.AppResumedFromBackground.Returns(subject.AsObservable());
                var errors = Observable.Never <Exception>();

                SyncManager.Errors.Returns(errors);

                AutomaticSyncingService.SetupAutomaticSync(UserAccessManager);
                LoggedIn.OnNext(DataSource);
                SyncManager.ClearReceivedCalls();
                LoggedOut.OnNext(Unit.Default);

                subject.OnNext(MinimumTimeInBackgroundForFullSync);

                await SyncManager.DidNotReceive().ForceFullSync();
            }
Esempio n. 5
0
            public async Task TracksHowManyEntitiesChangeDuringAutomaticSyncWhenResumingFromBackground()
            {
                var syncedTimeEntry = new MockTimeEntry {
                    SyncStatus = SyncStatus.InSync
                };
                var unsyncedTimeEntry = new MockTimeEntry {
                    SyncStatus = SyncStatus.SyncNeeded
                };
                var createdSubject  = new Subject <IThreadSafeTimeEntry>();
                var updatedSubject  = new Subject <EntityUpdate <IThreadSafeTimeEntry> >();
                var deletedSubject  = new Subject <long>();
                var fullSyncSubject = new Subject <SyncState>();

                TimeEntriesSource.Created.Returns(createdSubject);
                TimeEntriesSource.Updated.Returns(updatedSubject);
                TimeEntriesSource.Deleted.Returns(deletedSubject);
                SyncManager.ForceFullSync().Returns(fullSyncSubject);
                SyncManager.Errors.Returns(Observable.Never <Exception>());

                AutomaticSyncingService.SetupAutomaticSync(UserAccessManager);
                LoggedIn.OnNext(DataSource);
                AppResumedFromBackground.OnNext(MinimumTimeInBackgroundForFullSync);
                createdSubject.OnNext(syncedTimeEntry);
                createdSubject.OnNext(unsyncedTimeEntry);
                updatedSubject.OnNext(new EntityUpdate <IThreadSafeTimeEntry>(123, syncedTimeEntry));
                updatedSubject.OnNext(new EntityUpdate <IThreadSafeTimeEntry>(123, unsyncedTimeEntry));
                deletedSubject.OnNext(123);
                fullSyncSubject.OnNext(SyncState.Sleep);
                fullSyncSubject.OnCompleted();

                bool wasCalled;

                do
                {
                    await Task.Delay(TimeSpan.FromSeconds(0.5));

                    wasCalled = AnalyticsService.NumberOfSyncedTimeEntriesWhenResumingTheAppFromBackground
                                .ReceivedCalls()
                                .Any();
                }while (!wasCalled);

                AnalyticsService.NumberOfSyncedTimeEntriesWhenResumingTheAppFromBackground.Received().Track(3);
            }