Exemplo n.º 1
0
                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();
                }
Exemplo n.º 2
0
            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;
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
            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);
            }
Exemplo n.º 7
0
                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)
                        );
                }
Exemplo n.º 8
0
            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());
            }
Exemplo n.º 9
0
                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)
                        );
                }
Exemplo n.º 10
0
                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();
                }
Exemplo n.º 11
0
        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)));
            }
        }