public void ReturnsTrueIfTheUserDataWasStoredInThePrivateStorage()
            {
                PrivateSharedStorageService.HasUserDataStored().Returns(true);
                PrivateSharedStorageService.GetApiToken().Returns("ApiToken");

                var result = UserAccessManager.CheckIfLoggedIn();

                result.Should().BeTrue();
            }
            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 EmitsWhenUserIsLoggedInAndDataIsAlreadyStoredInThePrivateStorage()
            {
                var observer = Substitute.For <IObserver <ITogglApi> >();

                UserAccessManager.UserLoggedIn.Subscribe(observer);
                PrivateSharedStorageService.HasUserDataStored().Returns(true);
                PrivateSharedStorageService.GetApiToken().Returns("ApiToken");

                UserAccessManager.LoginWithSavedCredentials();

                observer.Received().OnNext(Arg.Any <ITogglApi>());
            }
            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>());
            }