public void DoesNotRestrictAccessForDifferentExceptions() { ApiErrorHandlingService.TryHandleDeprecationError(exception); AccessRestrictionStorage.DidNotReceive().SetApiOutdated(); AccessRestrictionStorage.DidNotReceive().SetClientOutdated(); }
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)); }
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(); }
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)); }
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)); }
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>()); }
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(); }
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(); }
public void RestricsAccessForClientDeprecatedException() { ApiErrorHandlingService.TryHandleDeprecationError(exception); AccessRestrictionStorage.Received().SetClientOutdated(); }
public void ReturnsTrueForClientDeprecatedException() { var result = ApiErrorHandlingService.TryHandleDeprecationError(exception); result.Should().BeTrue(); }
public void NavigatesToOutdatedAppViewModelForApiDeprecatedException() { ApiErrorHandlingService.TryHandleDeprecationError(exception); NavigationService.Received().Navigate <OutdatedAppViewModel>(); }
public void DoesNotNavigateForDifferentExceptions() { ApiErrorHandlingService.TryHandleUnauthorizedError(exception); NavigationService.DidNotReceive().Navigate <TokenResetViewModel>(); }
public void DoesNotRestrictAccessForDifferentExceptions() { ApiErrorHandlingService.TryHandleUnauthorizedError(exception); AccessRestrictionStorage.DidNotReceive().SetUnauthorizedAccess(Arg.Any <string>()); }
public void NavigatesToOutdatedAppViewModelForClientDeprecatedException() { ApiErrorHandlingService.TryHandleUnauthorizedError(exception); NavigationService.Received().Navigate <TokenResetViewModel>(); }
public void RestricsAccessForClientDeprecatedException() { ApiErrorHandlingService.TryHandleUnauthorizedError(exception); AccessRestrictionStorage.Received().SetUnauthorizedAccess(Arg.Is(User.ApiToken)); }
public void DoesNotNavigateForDifferentExceptions() { ApiErrorHandlingService.TryHandleDeprecationError(exception); NavigationService.DidNotReceive().Navigate <OutdatedAppViewModel>(); }