public async Task SubscribesToResumingFromBackgroundSignal() { AutomaticSyncingService.Start(SyncManager); AppResumedFromBackground.OnNext(Foundation.Services.AutomaticSyncingService.MinimumTimeInBackgroundForFullSync); await SyncManager.Received().ForceFullSync(); }
public async Task SubscribesToResumingFromBackgroundSignal() { AutomaticSyncingService.SetupAutomaticSync(UserAccessManager); LoggedIn.OnNext(DataSource); AppResumedFromBackground.OnNext(MinimumTimeInBackgroundForFullSync); await SyncManager.Received().ForceFullSync(); }
public void EnablesAutomaticSyncing() { AutomaticSyncingService.ClearReceivedCalls(); var syncManager = new SyncManager(Queue, Orchestrator, AnalyticsService, LastTimeUsageStorage, TimeService, AutomaticSyncingService); AutomaticSyncingService.Received().Start(syncManager); }
protected BaseAutomaticSyncingServiceTest() { AutomaticSyncingService = new AutomaticSyncingService(BackgroundService, TimeService, AnalyticsService); BackgroundService.AppResumedFromBackground.Returns(AppResumedFromBackground); SyncManager.Errors.Returns(Observable.Never <Exception>()); DataSource.SyncManager.Returns(SyncManager); DataSource.TimeEntries.Returns(TimeEntriesSource); UserAccessManager.UserLoggedIn.Returns(LoggedIn); UserAccessManager.UserLoggedOut.Returns(LoggedOut); }
public async Task StopsWhenSyncManagerFails() { var midnightSubject = new Subject <DateTimeOffset>(); TimeService.MidnightObservable.Returns(midnightSubject); AutomaticSyncingService.Start(SyncManager); midnightSubject.OnNext(new DateTimeOffset(2018, 12, 17, 00, 00, 00, TimeSpan.Zero)); await SyncManager.Received().CleanUp(); }
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(); }
public async Task UnsubscribesFromTheSignalWhenStopped() { var subject = new Subject <TimeSpan>(); BackgroundService.AppResumedFromBackground.Returns(subject.AsObservable()); var errors = Observable.Never <Exception>(); SyncManager.Errors.Returns(errors); AutomaticSyncingService.Start(SyncManager); SyncManager.ClearReceivedCalls(); AutomaticSyncingService.Stop(); subject.OnNext(Foundation.Services.AutomaticSyncingService.MinimumTimeInBackgroundForFullSync); await SyncManager.DidNotReceive().ForceFullSync(); }
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(); }
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); }
protected override void InitializeApp(IMvxPluginManager pluginManager, IMvxApplication app) { #if !USE_PRODUCTION_API System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; #endif const string clientName = "Daneel"; const string remoteConfigDefaultsFileName = "RemoteConfigDefaults"; var version = NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"].ToString(); var database = new Database(); var scheduler = Scheduler.Default; var timeService = new TimeService(scheduler); var topViewControllerProvider = (ITopViewControllerProvider)Presenter; var dialogService = new DialogServiceIos(topViewControllerProvider); var platformInfo = new PlatformInfoIos(); var suggestionProviderContainer = new SuggestionProviderContainer( new MostUsedTimeEntrySuggestionProvider(database, timeService, maxNumberOfSuggestions) ); var intentDonationService = new IntentDonationServiceIos(); var privateSharedStorageService = new PrivateSharedStorageServiceIos(); var appVersion = Version.Parse(version); var keyValueStorage = new UserDefaultsStorageIos(); var permissionsService = new PermissionsServiceIos(); var userAgent = new UserAgent(clientName, version); var settingsStorage = new SettingsStorage(Version.Parse(version), keyValueStorage); var remoteConfigService = new RemoteConfigServiceIos(); remoteConfigService.SetupDefaults(remoteConfigDefaultsFileName); var schedulerProvider = new IOSSchedulerProvider(); var calendarService = new CalendarServiceIos(permissionsService); var notificationService = new NotificationServiceIos(permissionsService, timeService); var backgroundSyncService = new BackgroundSyncServiceIos(); var backgroundService = new BackgroundService(timeService, analyticsService); var automaticSyncingService = new AutomaticSyncingService(backgroundService, timeService, analyticsService); var errorHandlingService = new ErrorHandlingService(navigationService, settingsStorage); var foundation = TogglFoundation .ForClient(userAgent, appVersion) .WithDatabase(database) .WithScheduler(scheduler) .WithTimeService(timeService) .WithApiEnvironment(environment) .WithGoogleService <GoogleServiceIos>() .WithRatingService <RatingServiceIos>() .WithLicenseProvider <LicenseProviderIos>() .WithAnalyticsService(analyticsService) .WithSchedulerProvider(schedulerProvider) .WithRemoteConfigService(remoteConfigService) .WithNotificationService(notificationService) .WithApiFactory(new ApiFactory(environment, userAgent)) .WithBackgroundService(backgroundService) .WithAutomaticSyncingService(automaticSyncingService) .WithApplicationShortcutCreator(new ApplicationShortcutCreator()) .WithSuggestionProviderContainer(suggestionProviderContainer) .WithIntentDonationService(intentDonationService) .WithStopwatchProvider <FirebaseStopwatchProviderIos>() .WithPrivateSharedStorageService(privateSharedStorageService) .WithPlatformInfo(platformInfo) .WithBackgroundSyncService(backgroundSyncService) .StartRegisteringPlatformServices() .WithDialogService(dialogService) .WithLastTimeUsageStorage(settingsStorage) .WithBrowserService <BrowserServiceIos>() .WithKeyValueStorage(keyValueStorage) .WithUserPreferences(settingsStorage) .WithCalendarService(calendarService) .WithOnboardingStorage(settingsStorage) .WithNavigationService(navigationService) .WithPermissionsService(permissionsService) .WithAccessRestrictionStorage(settingsStorage) .WithPasswordManagerService <OnePasswordServiceIos>() .WithErrorHandlingService(errorHandlingService) .WithSyncErrorHandlingService(new SyncErrorHandlingService(errorHandlingService)) .WithRxActionFactory(new RxActionFactory(schedulerProvider)) .Build(); foundation.RevokeNewUserIfNeeded().Initialize(); base.InitializeApp(pluginManager, app); }
public void DisablesAutomaticSyncing() { SyncManager.Freeze(); AutomaticSyncingService.Received().Stop(); }
protected BaseAutomaticSyncingServiceTest() { BackgroundService.AppResumedFromBackground.Returns(AppResumedFromBackground.AsObservable()); AutomaticSyncingService = new AutomaticSyncingService(BackgroundService, TimeService); }
protected override void InitializeApp(IMvxPluginManager pluginManager, IMvxApplication app) { const string clientName = "Giskard"; var packageInfo = ApplicationContext.PackageManager.GetPackageInfo(ApplicationContext.PackageName, 0); var version = packageInfo.VersionName; var sharedPreferences = ApplicationContext.GetSharedPreferences(clientName, FileCreationMode.Private); var database = new Database(); var scheduler = Scheduler.Default; var timeService = new TimeService(scheduler); var backgroundService = new BackgroundService(timeService, analyticsService); var suggestionProviderContainer = new SuggestionProviderContainer( new MostUsedTimeEntrySuggestionProvider(database, timeService, maxNumberOfSuggestions) ); var appVersion = Version.Parse(version); var userAgent = new UserAgent(clientName, version); var dialogService = new DialogServiceAndroid(); var platformInfo = new PlatformInfoAndroid(); var keyValueStorage = new SharedPreferencesStorageAndroid(sharedPreferences); var settingsStorage = new SettingsStorage(appVersion, keyValueStorage); var schedulerProvider = new AndroidSchedulerProvider(); var permissionsService = new PermissionsServiceAndroid(); var calendarService = new CalendarServiceAndroid(permissionsService); var automaticSyncingService = new AutomaticSyncingService(backgroundService, timeService); var errorHandlingService = new ErrorHandlingService(navigationService, settingsStorage); ApplicationContext.RegisterReceiver(new TimezoneChangedBroadcastReceiver(timeService), new IntentFilter(Intent.ActionTimezoneChanged)); var dataSource = new TogglDataSource( database, timeService, analyticsService); var foundation = TogglFoundation .ForClient(userAgent, appVersion) .WithDatabase(database) .WithDataSource(dataSource) .WithScheduler(scheduler) .WithTimeService(timeService) .WithApiEnvironment(environment) .WithGoogleService <GoogleServiceAndroid>() .WithRatingService(new RatingServiceAndroid(ApplicationContext)) .WithLicenseProvider <LicenseProviderAndroid>() .WithAnalyticsService(analyticsService) .WithSchedulerProvider(schedulerProvider) .WithPlatformInfo(platformInfo) .WithNotificationService <NotificationServiceAndroid>() .WithRemoteConfigService <RemoteConfigServiceAndroid>() .WithApiFactory(new ApiFactory(environment, userAgent)) .WithBackgroundService(backgroundService) .WithAutomaticSyncingService(automaticSyncingService) .WithSuggestionProviderContainer(suggestionProviderContainer) .WithApplicationShortcutCreator(new ApplicationShortcutCreator(ApplicationContext)) .WithStopwatchProvider <FirebaseStopwatchProviderAndroid>() .WithIntentDonationService(new NoopIntentDonationServiceAndroid()) .WithPrivateSharedStorageService(new NoopPrivateSharedStorageServiceAndroid()) .WithBackgroundSyncService <BackgroundSyncServiceAndroid>() .StartRegisteringPlatformServices() .WithDialogService(dialogService) .WithLastTimeUsageStorage(settingsStorage) .WithBrowserService <BrowserServiceAndroid>() .WithCalendarService(calendarService) .WithKeyValueStorage(keyValueStorage) .WithUserPreferences(settingsStorage) .WithOnboardingStorage(settingsStorage) .WithNavigationService(navigationService) .WithPermissionsService(permissionsService) .WithAccessRestrictionStorage(settingsStorage) .WithErrorHandlingService(errorHandlingService) .WithSyncErrorHandlingService(new SyncErrorHandlingService(errorHandlingService)) .WithRxActionFactory(new RxActionFactory(schedulerProvider)) .Build(); foundation.RevokeNewUserIfNeeded().Initialize(); ensureDataSourceInitializationIfLoggedIn(); createApplicationLifecycleObserver(backgroundService); base.InitializeApp(pluginManager, app); }