public async Task LogsOutAfterGoogleLogin() { GoogleService.GetAuthToken().Returns(Observable.Return("sometoken")); await UserAccessManager.LoginWithGoogle(); await UserAccessManager.Logout(); await DataSource.Received().Logout(); }
public void AndStopRetryingAfterASuccessfullLoginWithGoogleApiCall() { var observer = TestScheduler.CreateObserver <ITogglDataSource>(); var userIsMissingApiTokenException = new UserIsMissingApiTokenException(Substitute.For <IRequest>(), Substitute.For <IResponse>()); GoogleService.GetAuthToken().Returns(Observable.Return("sometoken")); Api.User.GetWithGoogle().Returns(Observable.Throw <IUser>(userIsMissingApiTokenException), Observable.Return(User)); TestScheduler.Start(); LoginManager.LoginWithGoogle().Subscribe(observer); TestScheduler.AdvanceBy(TimeSpan.FromDays(1).Ticks); Api.User.Received(2).GetWithGoogle(); }
public void AfterAWhileWhenTheApiThrowsUserIsMissingApiTokenException(int seconds, int apiCalls) { var userIsMissingApiTokenException = new UserIsMissingApiTokenException(Substitute.For <IRequest>(), Substitute.For <IResponse>()); GoogleService.GetAuthToken().Returns(Observable.Return("sometoken")); Api.User.GetWithGoogle().Returns(Observable.Throw <IUser>(userIsMissingApiTokenException)); var observer = TestScheduler.CreateObserver <ITogglDataSource>(); TestScheduler.Start(); LoginManager.LoginWithGoogle().Subscribe(observer); TestScheduler.AdvanceBy(TimeSpan.FromSeconds(seconds).Ticks); Api.User.Received(apiCalls).GetWithGoogle(); }
public void LoggingInWithGoogleWhenReceivingUserIsMissingApiTokenExceptionAndThenForwardTheErrorOnTheThirdFailure() { var userIsMissingApiTokenException = new UserIsMissingApiTokenException(Substitute.For <IRequest>(), Substitute.For <IResponse>()); GoogleService.GetAuthToken().Returns(Observable.Return("sometoken")); Api.User.GetWithGoogle().Returns(Observable.Throw <IUser>(userIsMissingApiTokenException)); var observer = TestScheduler.CreateObserver <ITogglDataSource>(); TestScheduler.Start(); LoginManager.LoginWithGoogle().Subscribe(observer); TestScheduler.AdvanceBy(TimeSpan.FromSeconds(20).Ticks); Api.User.Received(3).GetWithGoogle(); observer.Messages.Single().Value.Exception.Should().BeOfType <UserIsMissingApiTokenException>(); }
public void WhenReceivingUserIsMissingApiTokenExceptionOrThrowOtherExceptions() { var userIsMissingApiTokenException = new UserIsMissingApiTokenException(Substitute.For <IRequest>(), Substitute.For <IResponse>()); var serverErrorException = Substitute.For <ServerErrorException>(Substitute.For <IRequest>(), Substitute.For <IResponse>(), "Some Exception"); GoogleService.GetAuthToken().Returns(Observable.Return("sometoken")); Api.User.GetWithGoogle().Returns(Observable.Throw <IUser>(userIsMissingApiTokenException), Observable.Throw <IUser>(serverErrorException)); var observer = TestScheduler.CreateObserver <ITogglDataSource>(); TestScheduler.Start(); LoginManager.LoginWithGoogle().Subscribe(observer); TestScheduler.AdvanceBy(TimeSpan.FromSeconds(20).Ticks); observer.Messages.Single().Value.Exception.Should().Be(serverErrorException); Api.User.Received(2).GetWithGoogle(); }
public async Task TracksMissingApiToken() { var userIsMissingApiTokenException = new UserIsMissingApiTokenException(Substitute.For <IRequest>(), Substitute.For <IResponse>()); Api.User.SignUpWithGoogle(Arg.Any <string>()).Returns(Observable.Throw <IUser>(userIsMissingApiTokenException)); GoogleService.GetAuthToken().Returns(Observable.Return("abc")); try { await LoginManager.SignUpWithGoogle(); } catch { } AnalyticsService.UserIsMissingApiToken.Received().Track(Arg.Is(LoginSignupAuthenticationMethod.SignUpWithGoogle)); }
public void AndWhenReceivingUserIsMissingApiTokenExceptionWillResumeTryingToLoginWithGoogleThreeTimesBeforeThrowingIt() { var userIsMissingApiTokenException = new UserIsMissingApiTokenException(Substitute.For <IRequest>(), Substitute.For <IResponse>()); GoogleService.GetAuthToken().Returns(Observable.Return("sometoken")); Api.User.SignUpWithGoogle(Arg.Any <string>()).Returns(Observable.Throw <IUser>(userIsMissingApiTokenException)); Api.User.GetWithGoogle().Returns(Observable.Throw <IUser>(userIsMissingApiTokenException)); var observer = TestScheduler.CreateObserver <ITogglDataSource>(); TestScheduler.Start(); LoginManager.SignUpWithGoogle().Subscribe(observer); TestScheduler.AdvanceBy(TimeSpan.FromSeconds(20).Ticks); Api.User.Received(1).SignUpWithGoogle(Arg.Any <string>()); Api.User.Received(3).GetWithGoogle(); observer.Messages.Single().Value.Exception.Should().BeOfType <UserIsMissingApiTokenException>(); }
public TheUserAccessUsingGoogleMethod() { GoogleService.GetAuthToken().Returns(Observable.Return("sometoken")); }