public async void DoesNotShowTheRatingViewIfAfter24HourSnooze() { var defaultRemoteConfiguration = new RatingViewConfiguration(5, RatingViewCriterion.Start); RemoteConfigService .RatingViewConfiguration .Returns(Observable.Return(defaultRemoteConfiguration)); var now = DateTimeOffset.Now; var firstOpened = now - TimeSpan.FromDays(6); var lastInteraction = now - TimeSpan.FromDays(2); TimeService.CurrentDateTime.Returns(now); OnboardingStorage.GetFirstOpened().Returns(firstOpened); OnboardingStorage.RatingViewOutcome().Returns(RatingViewOutcome.AppWasNotRated); OnboardingStorage.RatingViewOutcomeTime().Returns(lastInteraction); await ViewModel.Initialize(); var observer = TestScheduler.CreateObserver <bool>(); ViewModel.ShouldShowRatingView.Subscribe(observer); TestScheduler.Start(); observer.LastEmittedValue().Should().BeFalse(); }
protected override void AdditionalSetup() { base.AdditionalSetup(); var syncManager = Substitute.For <ISyncManager>(); syncManager.ProgressObservable.Returns(ProgressSubject.AsObservable()); var defaultRemoteConfiguration = new RatingViewConfiguration(5, RatingViewCriterion.None); RemoteConfigService .RatingViewConfiguration .Returns(Observable.Return(defaultRemoteConfiguration)); var provider = Substitute.For <ISuggestionProvider>(); provider.GetSuggestions().Returns(Observable.Empty <Suggestion>()); SuggestionProviderContainer.Providers.Returns(new[] { provider }.ToList().AsReadOnly()); DataSource.Preferences.Current.Returns(Observable.Create <IThreadSafePreferences>(observer => { observer.OnNext(new MockPreferences { DateFormat = DateFormat.FromLocalizedDateFormat("dd/mm/YYYY") }); return(Disposable.Empty); })); }
public MockFetchRemoteConfigService( bool shouldSucceed = true, bool shouldFail = false, Exception exceptionOnFailure = null, RatingViewConfiguration ratingViewConfigurationToReturn = default(RatingViewConfiguration), PushNotificationsConfiguration pushNotificationsConfigurationReturn = default(PushNotificationsConfiguration)) { this.shouldSucceed = shouldSucceed; this.shouldFail = shouldFail; this.exceptionOnFailure = exceptionOnFailure; this.ratingViewConfigurationToReturn = ratingViewConfigurationToReturn; this.pushNotificationsConfigurationReturn = pushNotificationsConfigurationReturn; }
private bool dayCountPassed(RatingViewConfiguration ratingViewConfiguration) { var firstOpened = onboardingStorage.GetFirstOpened(); if (firstOpened == null) { return(false); } var targetDayCount = ratingViewConfiguration.DayCount; var actualDayCount = (timeService.CurrentDateTime - firstOpened.Value).TotalDays; return(actualDayCount >= targetDayCount); }
protected override void AdditionalSetup() { base.AdditionalSetup(); var syncManager = Substitute.For <ISyncManager>(); syncManager.ProgressObservable.Returns(ProgressSubject.AsObservable()); DataSource.SyncManager.Returns(syncManager); var defaultRemoteConfiguration = new RatingViewConfiguration(5, RatingViewCriterion.None); RemoteConfigService .RatingViewConfiguration .Returns(Observable.Return(defaultRemoteConfiguration)); }
public void ShouldUpdateTheCacheWhenFetchingSucceeds(int ratingViewDayCount, RatingViewCriterion ratingViewCriterion, bool registerPushes, bool handlePushes) { var expectedRatingViewConfiguration = new RatingViewConfiguration(ratingViewDayCount, ratingViewCriterion); var expectedPushNotificationsConfiguration = new PushNotificationsConfiguration(registerPushes, handlePushes); var mockFetchRemoteConfigService = new MockFetchRemoteConfigService( true, ratingViewConfigurationToReturn: expectedRatingViewConfiguration, pushNotificationsConfigurationReturn: expectedPushNotificationsConfiguration); UpdateRemoteConfigCacheService = new UpdateRemoteConfigCacheService(TimeService, KeyValueStorage, mockFetchRemoteConfigService); UpdateRemoteConfigCacheService.FetchAndStoreRemoteConfigData(); KeyValueStorage.Received().SetInt(RatingViewDelayParameter, ratingViewDayCount); KeyValueStorage.Received().SetString(RatingViewTriggerParameter, ratingViewCriterion.ToString()); KeyValueStorage.Received().SetBool(RegisterPushNotificationsTokenWithServerParameter, registerPushes); KeyValueStorage.Received().SetBool(HandlePushNotificationsParameter, handlePushes); }
public async void ShowsTheRatingView() { var defaultRemoteConfiguration = new RatingViewConfiguration(5, RatingViewCriterion.Start); RemoteConfigService .RatingViewConfiguration .Returns(Observable.Return(defaultRemoteConfiguration)); var now = DateTimeOffset.Now; var firstOpened = now - TimeSpan.FromDays(5); TimeService.CurrentDateTime.Returns(now); OnboardingStorage.GetFirstOpened().Returns(firstOpened); await ViewModel.Initialize(); await NavigationService.Received().ChangePresentation( Arg.Is <ToggleRatingViewVisibilityHint>(hint => hint.ShouldHide == false) ); }
protected override void AdditionalSetup() { base.AdditionalSetup(); var syncManager = Substitute.For <ISyncManager>(); syncManager.ProgressObservable.Returns(ProgressSubject.AsObservable()); DataSource.SyncManager.Returns(syncManager); var defaultRemoteConfiguration = new RatingViewConfiguration(5, RatingViewCriterion.None); RemoteConfigService .RatingViewConfiguration .Returns(Observable.Return(defaultRemoteConfiguration)); var provider = Substitute.For <ISuggestionProvider>(); provider.GetSuggestions().Returns(Observable.Empty <Suggestion>()); SuggestionProviderContainer.Providers.Returns(new[] { provider }.ToList().AsReadOnly()); }
public async void DoesNotShowTheRatingViewIfAfter24HourSnooze() { var defaultRemoteConfiguration = new RatingViewConfiguration(5, RatingViewCriterion.Start); RemoteConfigService .RatingViewConfiguration .Returns(Observable.Return(defaultRemoteConfiguration)); var now = DateTimeOffset.Now; var firstOpened = now - TimeSpan.FromDays(6); var lastInteraction = now - TimeSpan.FromDays(2); TimeService.CurrentDateTime.Returns(now); OnboardingStorage.GetFirstOpened().Returns(firstOpened); OnboardingStorage.RatingViewOutcome().Returns(RatingViewOutcome.AppWasNotRated); OnboardingStorage.RatingViewOutcomeTime().Returns(lastInteraction); await ViewModel.Initialize(); await NavigationService.DidNotReceive().ChangePresentation( Arg.Is <ToggleRatingViewVisibilityHint>(hint => hint.ShouldHide == false) ); }
public async void ShowsTheRatingView() { var defaultRemoteConfiguration = new RatingViewConfiguration(5, RatingViewCriterion.Start); RemoteConfigService .GetRatingViewConfiguration() .Returns(defaultRemoteConfiguration); var now = DateTimeOffset.Now; var firstOpened = now - TimeSpan.FromDays(5); TimeService.CurrentDateTime.Returns(now); OnboardingStorage.GetFirstOpened().Returns(firstOpened); await ViewModel.Initialize(); var observer = TestScheduler.CreateObserver <bool>(); ViewModel.ShouldShowRatingView.Subscribe(observer); TestScheduler.Start(); observer.LastEmittedValue().Should().BeTrue(); }
private IObservable <(bool criterionMatched, RatingViewConfiguration configuration)> criterionMatched(RatingViewConfiguration configuration) { switch (configuration.Criterion) { case RatingViewCriterion.Stop: return(dataSource .TimeEntries .TimeEntryStopped .Select(_ => (true, configuration))); case RatingViewCriterion.Start: return(dataSource .TimeEntries .TimeEntryStarted .Select(_ => (true, configuration))); case RatingViewCriterion.Continue: return(dataSource .TimeEntries .TimeEntryContinued .Merge(dataSource.TimeEntries.SuggestionStarted) .Select(_ => (true, configuration))); default: return(Observable.Return((false, configuration))); } }