コード例 #1
0
            public void DoesNotRestrictAccessForDifferentExceptions()
            {
                ApiErrorHandlingService.TryHandleDeprecationError(exception);

                AccessRestrictionStorage.DidNotReceive().SetApiOutdated();
                AccessRestrictionStorage.DidNotReceive().SetClientOutdated();
            }
コード例 #2
0
        public static FoundationMvvmCross RegisterServices(this Foundation self,
                                                           IDialogService dialogService,
                                                           IBrowserService browserService,
                                                           IKeyValueStorage keyValueStorage,
                                                           IAccessRestrictionStorage accessRestrictionStorage,
                                                           IUserPreferences userPreferences,
                                                           IOnboardingStorage onboardingStorage,
                                                           IMvxNavigationService navigationService,
                                                           IPasswordManagerService passwordManagerService = null)
        {
            Ensure.Argument.IsNotNull(self, nameof(self));
            Ensure.Argument.IsNotNull(dialogService, nameof(dialogService));
            Ensure.Argument.IsNotNull(browserService, nameof(browserService));
            Ensure.Argument.IsNotNull(keyValueStorage, nameof(keyValueStorage));
            Ensure.Argument.IsNotNull(accessRestrictionStorage, nameof(accessRestrictionStorage));
            Ensure.Argument.IsNotNull(userPreferences, nameof(userPreferences));
            Ensure.Argument.IsNotNull(onboardingStorage, nameof(onboardingStorage));
            Ensure.Argument.IsNotNull(navigationService, nameof(navigationService));

            var timeService = self.TimeService;

            var apiErrorHandlingService = new ApiErrorHandlingService(navigationService, accessRestrictionStorage);

            Mvx.RegisterSingleton(self.BackgroundService);
            Mvx.RegisterSingleton(dialogService);
            Mvx.RegisterSingleton(self.Database);
            Mvx.RegisterSingleton(browserService);
            Mvx.RegisterSingleton(self.UserAgent);
            Mvx.RegisterSingleton(self.TimeService);
            Mvx.RegisterSingleton(self.Scheduler);
            Mvx.RegisterSingleton(self.ShortcutCreator);
            Mvx.RegisterSingleton(self.MailService);
            Mvx.RegisterSingleton(self.ShortcutCreator);
            Mvx.RegisterSingleton(self.AnalyticsService);
            Mvx.RegisterSingleton(self.PlatformConstants);
            Mvx.RegisterSingleton(self.Database.IdProvider);
            Mvx.RegisterSingleton(self.SuggestionProviderContainer);
            Mvx.RegisterSingleton(userPreferences);
            Mvx.RegisterSingleton(onboardingStorage);
            Mvx.RegisterSingleton(accessRestrictionStorage);
            Mvx.RegisterSingleton <IApiErrorHandlingService>(apiErrorHandlingService);
            Mvx.RegisterSingleton(passwordManagerService ?? new StubPasswordManagerService());

            Mvx.LazyConstructAndRegisterSingleton <IInteractorFactory, InteractorFactory>();

            return(new FoundationMvvmCross(
                       self.ApiFactory,
                       self.Database,
                       timeService,
                       self.Scheduler,
                       self.AnalyticsService,
                       self.GoogleService,
                       self.ShortcutCreator,
                       self.BackgroundService,
                       onboardingStorage,
                       accessRestrictionStorage,
                       navigationService,
                       apiErrorHandlingService));
        }
コード例 #3
0
            public void DoesNotThrowForAnyExceptionWhichCanBeThrownByTheProgressObservable(Exception exception)
            {
                ApiErrorHandlingService.TryHandleUnauthorizedError(Arg.Any <UnauthorizedException>()).Returns(true);
                ApiErrorHandlingService.TryHandleDeprecationError(Arg.Any <ClientDeprecatedException>()).Returns(true);
                ApiErrorHandlingService.TryHandleDeprecationError(Arg.Any <ApiDeprecatedException>()).Returns(true);

                Action processingError = () => ProgressSubject.OnError(exception);

                processingError.Should().NotThrow();
            }
コード例 #4
0
            public async ThreadingTask SetsTheUnauthorizedAccessFlag()
            {
                var exception = new UnauthorizedException(request, response);

                ApiErrorHandlingService.TryHandleUnauthorizedError(Arg.Any <UnauthorizedException>()).Returns(true);

                ProgressSubject.OnError(exception);

                ApiErrorHandlingService.Received().TryHandleUnauthorizedError(Arg.Is(exception));
            }
コード例 #5
0
            public void SetsTheOutdatedApiVersionFlag()
            {
                var exception = new ApiDeprecatedException(request, response);

                ApiErrorHandlingService.TryHandleDeprecationError(Arg.Any <ApiDeprecatedException>()).Returns(true);

                ProgressSubject.OnError(exception);

                ApiErrorHandlingService.Received().TryHandleDeprecationError(Arg.Is(exception));
                ApiErrorHandlingService.DidNotReceive().TryHandleUnauthorizedError(Arg.Is(exception));
            }
コード例 #6
0
            internal void ReturnsTrueButDoesNotNavigateOrSetUnathorizedAccessFlagWhenTheApiTokenCannotBeExtractedFromTheRequest()
            {
                var request = Substitute.For <IRequest>();

                request.Headers.Returns(new HttpHeader[0]);
                var exceptionWithoutApiToken = new UnauthorizedException(request, Substitute.For <IResponse>());

                var handled = ApiErrorHandlingService.TryHandleUnauthorizedError(exceptionWithoutApiToken);

                handled.Should().BeTrue();
                NavigationService.DidNotReceive().Navigate <TokenResetViewModel>();
                AccessRestrictionStorage.DidNotReceive().SetUnauthorizedAccess(Arg.Any <string>());
            }
コード例 #7
0
                public void DoesNothingWhenApiErrorHandlingServiceHandlesTheException()
                {
                    ViewModel.Email    = ValidEmail;
                    ViewModel.Password = ValidPassword;
                    var exception = new Exception();

                    LoginManager.Login(Arg.Any <Email>(), Arg.Any <Password>())
                    .Returns(Observable.Throw <ITogglDataSource>(exception));
                    ApiErrorHandlingService.TryHandleDeprecationError(Arg.Any <Exception>())
                    .Returns(true);

                    ViewModel.LoginCommand.Execute();

                    ViewModel.ErrorMessage.Should().BeEmpty();
                }
コード例 #8
0
            public void UnsubscribesFromTheBackgroundServiceObservableWhenExceptionIsCaught()
            {
                var subject = new Subject <TimeSpan>();

                BackgroundService.AppResumedFromBackground.Returns(subject.AsObservable());
                DataSource.StartSyncing();
                SyncManager.ClearReceivedCalls();
                var exception = new UnauthorizedException(request, response);

                ApiErrorHandlingService.TryHandleUnauthorizedError(Arg.Any <UnauthorizedException>()).Returns(true);

                ProgressSubject.OnError(exception);
                subject.OnNext(MinimumTimeInBackgroundForFullSync + TimeSpan.FromSeconds(1));

                SyncManager.DidNotReceive().ForceFullSync();
            }
コード例 #9
0
            public void RestricsAccessForClientDeprecatedException()
            {
                ApiErrorHandlingService.TryHandleDeprecationError(exception);

                AccessRestrictionStorage.Received().SetClientOutdated();
            }
コード例 #10
0
            public void ReturnsTrueForClientDeprecatedException()
            {
                var result = ApiErrorHandlingService.TryHandleDeprecationError(exception);

                result.Should().BeTrue();
            }
コード例 #11
0
            public void NavigatesToOutdatedAppViewModelForApiDeprecatedException()
            {
                ApiErrorHandlingService.TryHandleDeprecationError(exception);

                NavigationService.Received().Navigate <OutdatedAppViewModel>();
            }
コード例 #12
0
            public void DoesNotNavigateForDifferentExceptions()
            {
                ApiErrorHandlingService.TryHandleUnauthorizedError(exception);

                NavigationService.DidNotReceive().Navigate <TokenResetViewModel>();
            }
コード例 #13
0
            public void DoesNotRestrictAccessForDifferentExceptions()
            {
                ApiErrorHandlingService.TryHandleUnauthorizedError(exception);

                AccessRestrictionStorage.DidNotReceive().SetUnauthorizedAccess(Arg.Any <string>());
            }
コード例 #14
0
            public void NavigatesToOutdatedAppViewModelForClientDeprecatedException()
            {
                ApiErrorHandlingService.TryHandleUnauthorizedError(exception);

                NavigationService.Received().Navigate <TokenResetViewModel>();
            }
コード例 #15
0
            public void RestricsAccessForClientDeprecatedException()
            {
                ApiErrorHandlingService.TryHandleUnauthorizedError(exception);

                AccessRestrictionStorage.Received().SetUnauthorizedAccess(Arg.Is(User.ApiToken));
            }
コード例 #16
0
            public void DoesNotNavigateForDifferentExceptions()
            {
                ApiErrorHandlingService.TryHandleDeprecationError(exception);

                NavigationService.DidNotReceive().Navigate <OutdatedAppViewModel>();
            }