Exemplo n.º 1
0
            public async Task ShowsTheOnboardingViewModelIfTheUserHasNotLoggedInPreviously()
            {
                UserAccessManager.CheckIfLoggedIn().Returns(false);

                AppStart.Start();

                await NavigationService.Received().Navigate <OnboardingViewModel>();
            }
Exemplo n.º 2
0
            public void ReturnsNotLoggedInWhenTheUserHasNotLoggedInPreviously()
            {
                UserAccessManager.CheckIfLoggedIn().Returns(false);

                var accessLevel = App.GetAccessLevel();

                accessLevel.Should().Be(AccessLevel.NotLoggedIn);
            }
            public void ReturnsTrueIfTheUserDataWasStoredInThePrivateStorage()
            {
                PrivateSharedStorageService.HasUserDataStored().Returns(true);
                PrivateSharedStorageService.GetApiToken().Returns("ApiToken");

                var result = UserAccessManager.CheckIfLoggedIn();

                result.Should().BeTrue();
            }
            public void ReturnsADataSourceIfTheUserExistsInTheDatabase()
            {
                var observable = Observable.Return <IDatabaseUser>(FoundationUser.Clean(User));

                Database.User.Single().Returns(observable);

                var result = UserAccessManager.CheckIfLoggedIn();

                result.Should().BeTrue();
            }
            public void ReturnsNullIfTheDatabaseHasNoUsers()
            {
                var observable = Observable.Throw <IDatabaseUser>(new InvalidOperationException());

                Database.User.Single().Returns(observable);

                var result = UserAccessManager.CheckIfLoggedIn();

                result.Should().BeFalse();
            }
            public void ReturnsTrueTheUserExistsInTheDatabase()
            {
                var observable = Observable.Return <IDatabaseUser>(FoundationUser.Clean(User));

                Database.User.Single().Returns(observable);
                PrivateSharedStorageService.HasUserDataStored().Returns(false);

                var result = UserAccessManager.CheckIfLoggedIn();

                result.Should().BeTrue();
            }
            public void ReturnsFalseIfTheDatabaseHasNoUsers()
            {
                var observable = Observable.Throw <IDatabaseUser>(new InvalidOperationException());

                Database.User.Single().Returns(observable);
                PrivateSharedStorageService.HasUserDataStored().Returns(false);

                var result = UserAccessManager.CheckIfLoggedIn();

                result.Should().BeFalse();
            }
            public void EmitsWhenUserIsLoggedIn()
            {
                var observer   = Substitute.For <IObserver <ITogglApi> >();
                var observable = Observable.Return <IDatabaseUser>(FoundationUser.Clean(User));

                Database.User.Single().Returns(observable);
                UserAccessManager.UserLoggedIn.Subscribe(observer);

                UserAccessManager.CheckIfLoggedIn();

                observer.Received().OnNext(Arg.Any <ITogglApi>());
            }
            public void DoesNotEmitWhenUserIsNotLoggedIn()
            {
                var observer   = Substitute.For <IObserver <ITogglApi> >();
                var observable = Observable.Throw <IDatabaseUser>(new InvalidOperationException());

                Database.User.Single().Returns(observable);
                UserAccessManager.UserLoggedIn.Subscribe(observer);

                UserAccessManager.CheckIfLoggedIn();

                observer.DidNotReceive().OnNext(Arg.Any <ITogglApi>());
            }
Exemplo n.º 10
0
            public void ReturnsTrueAndStoresTheUserDataIfUserIsInTheDatabaseButNotInThePrivateStorage()
            {
                PrivateSharedStorageService.HasUserDataStored().Returns(false);
                var observable = Observable.Return <IDatabaseUser>(FoundationUser.Clean(User));

                Database.User.Single().Returns(observable);

                var result = UserAccessManager.CheckIfLoggedIn();

                result.Should().BeTrue();
                PrivateSharedStorageService.Received().SaveApiToken(Arg.Any <string>());
            }
Exemplo n.º 11
0
            protected AppStartTest()
            {
                var api = Substitute.For <ITogglApi>();

                UserAccessManager.UserLoggedIn.Returns(Observable.Return(api));

                var dependencyContainer = new TestDependencyContainer
                {
                    MockTimeService              = TimeService,
                    MockUserAccessManager        = UserAccessManager,
                    MockNavigationService        = NavigationService,
                    MockOnboardingStorage        = OnboardingStorage,
                    MockAccessRestrictionStorage = AccessRestrictionStorage,
                    MockSyncManager              = Substitute.For <ISyncManager>(),
                    MockInteractorFactory        = Substitute.For <IInteractorFactory>(),
                    MockBackgroundSyncService    = Substitute.For <IBackgroundSyncService>()
                };

                UserAccessManager.CheckIfLoggedIn().Returns(true);

                AppStart = new AppStart <OnboardingViewModel>(App, dependencyContainer);
            }