Пример #1
0
        public void InitializeMocks(T loggerClass)
        {
            _loggerMock = LoggerMock.SetupMock(loggerClass);
            _logger     = _loggerMock.Object;
            BaseMock.ShouldThrowException = false;

            _httpContextMock = HttpContextMock.SetupHttpContextMock();
            _httpContext     = _httpContextMock.Object;

            _dateTimeUtil = new DateTimeUtilMock();
            _tokenHandler = JwtSecurityTokenHandlerMock.SetupMock().Object;

            DbContextMock.ShouldThrowException = false;
            DbContextMock.SaveChangesResult    = 1;
            _dbContextMock = DbContextMock.SetupDbContext <IApplicationDbContext>();
            _dbContext     = _dbContextMock.Object;

            _tokenRepositoryMock = TokenRepositoryMock.SetupMock(_dbContext, _dateTimeUtil);
            _tokenRepository     = _tokenRepositoryMock.Object;

            _usersRepositoryMock = UsersRepositoryMock.SetupMock(_dbContext, _dateTimeUtil);
            _usersRepository     = _usersRepositoryMock.Object;

            _authServiceMock = AuthServiceMock.SetupMock(_usersRepository,
                                                         _tokenRepository,
                                                         _dateTimeUtil,
                                                         _logger as IEMSLogger <AuthService>,
                                                         _tokenHandler);
            _authService = _authServiceMock.Object;

            _usersServiceMock = UsersServiceMock.SetupMock(_usersRepository,
                                                           _logger as IEMSLogger <UsersService>, _dateTimeUtil);
            _usersService = _usersServiceMock.Object;
        }
            public void TestFixtureSetUp()
            {
                m_authService          = new AuthServiceMock(AuthServiceMock.KeyType.ECDSA_P256);
                m_accessTokenValidator = AccessTokenValidatorFactory.CreateRemoteValidator(
                    new HttpClient(),
                    m_authService.Host
                    );

                m_authService.SetupJwks().Wait();
            }
Пример #3
0
            public void TestFixtureSetUp()
            {
                m_authService          = new AuthServiceMock(AuthServiceMock.KeyType.ECDSA_P256);
                m_accessTokenValidator = AccessTokenValidatorFactory.CreateRemoteValidator(
                    new HttpClient(m_authService.MockHandler),
                    new Uri(m_authService.Host, ".well-known/jwks")
                    );

                m_authService.SetupJwks().Wait();
            }
        public void Setup()
        {
            CurrentUser = Fixture.Create <GoogleUser>();

            // Reset any calls made to the mocks.
            NavigationServiceMock.Reset();
            PageDialogServiceMock.Reset();
            AuthServiceMock.Reset();
            DatabaseServiceMock.Reset();
        }
Пример #5
0
        public void loginUserTest()
        {
            var userRepositoryMock = new UserRepositoryMock();
            var authServiceMock    = new AuthServiceMock();
            var loginUser          = new LoginUser(userRepositoryMock, authServiceMock);
            var expected           = new ReturnObject(true, "Logged in.");

            var returnObject = loginUser.loginUser("*****@*****.**", "0testPassword!");

            Assert.AreEqual(expected.isSuccess(), returnObject.isSuccess());
        }
        public void OnNavigatedTo_WhenNotLoggedIn_ShouldSetUserNull()
        {
            // Arrange
            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(() => null);

            // Act
            AccountSettingsPageViewModel.OnNavigatedTo(null);

            // Assert
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.Once, "Function AuthenticationService.GetUser not called exactly once.");
            Assert.IsNull(AccountSettingsPageViewModel.User, "Attribute AccountSettingsPageViewModel.User is not null.");
        }
        public void OnNavigatedTo_WhenLoggedIn_ShouldSetCurrentUser()
        {
            // Arrange
            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(() => CurrentUser);

            // Act
            AccountSettingsPageViewModel.OnNavigatedTo(null);

            // Assert
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.Once, "Function AuthenticationService.GetUser not called exactly once.");
            Assert.AreEqual(CurrentUser, AccountSettingsPageViewModel.User, "Attribute AccountSettingsPageViewModel.User does not equal the expected user.");
        }
        public async Task LogoutUserAsync_WhenFailingLogout_ShouldDoNothing()
        {
            // Arrange
            AuthServiceMock.Setup(authService => authService.LogoutAsync()).Returns(Task.Run(() => false));
            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(() => null);

            // Act
            await AccountSettingsPageViewModel.LogoutUserAsync();

            // Assert
            AuthServiceMock.Verify(authService => authService.LogoutAsync(), Times.Once, "Function AuthenticationService.LoginAsync not called exactly once.");
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.Never, "Function AuthenticationService.GetUser called atleast once.");
            Assert.IsNull(AccountSettingsPageViewModel.User, "Attribute AccountSettingsPageViewModel.User is not null.");
        }
Пример #9
0
        public async Task SetupMainPage_AfterSecondCall_ShouldNotLoginAndSync()
        {
            // Arrange
            AuthServiceMock.Setup(authService => authService.LoginAsync()).Returns(Task.Run(() => GoogleActionStatus.Completed));
            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(CurrentUser);
            DatabaseServiceMock.Setup(databaseService => databaseService.SyncRecipesAsync()).Verifiable();
            DatabaseServiceMock.Setup(databaseService => databaseService.GetRecipesAsync()).Returns(Task.Run(() => new List <Recipe>()));

            // Act
            await MainPageViewModel.SetupMainPage();

            await MainPageViewModel.SetupMainPage();

            // Assert
            AuthServiceMock.Verify(authService => authService.LoginAsync(), Times.Once, "Function IAuthenticationService.LoginAsync not called exactly once.");
            DatabaseServiceMock.Verify(databaseService => databaseService.SyncRecipesAsync(), Times.Once, "Function IDatabaseService.SyncRecipes not called exactly once.");
        }
Пример #10
0
        public async Task SetupMainPage_WithoutLoggingIn_ShouldSetupMainPage()
        {
            // Arrange
            AuthServiceMock.Setup(authService => authService.LoginAsync()).Returns(Task.Run(() => GoogleActionStatus.Canceled));
            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(() => null);
            DatabaseServiceMock.Setup(databaseService => databaseService.SyncRecipesAsync()).Verifiable();
            DatabaseServiceMock.Setup(databaseService => databaseService.GetRecipesAsync()).Returns(Task.Run(() => new List <Recipe>()));

            // Act
            await MainPageViewModel.SetupMainPage();

            // Assert
            AuthServiceMock.Verify(authService => authService.LoginAsync(), Times.Never, "Function IAuthenticationService.LoginAsync called atleast once.");
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.AtLeastOnce, "Function IAuthenticationService.GetUser not called atleast once.");
            DatabaseServiceMock.Verify(databaseService => databaseService.SyncRecipesAsync(), Times.Never, "Function IDatabaseService.SyncRecipes called atleast once.");
            DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipesAsync(), Times.Once, "Function IDatabaseService.GetRecipesAsync not called exactly once.");
            Assert.IsNotNull(MainPageViewModel.Recipes, "Attribute MainPageViewModel.Recipes is null");
        }
Пример #11
0
        public async Task ToggleLogin_WhenUserNull_ShouldLogin()
        {
            // Arrange
            AuthServiceMock.SetupSequence(authService => authService.GetUser())
            .Returns(() => null)
            .Returns(CurrentUser);
            AuthServiceMock.Setup(authService => authService.LoginAsync()).Returns(Task.Run(() => GoogleActionStatus.Completed));
            DatabaseServiceMock.Setup(databaseService => databaseService.SyncRecipesAsync()).Verifiable();
            DatabaseServiceMock.Setup(databaseService => databaseService.GetRecipesAsync()).Returns(Task.Run(() => new List <Recipe>()));

            // Act
            await MainPageViewModel.ToggleLogin();

            // Assert
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.AtLeastOnce, "Function IAuthenticationService.GetUser not called atleast once.");
            AuthServiceMock.Verify(authService => authService.LoginAsync(), Times.Once, "Function IAuthenticationService.LoginAsync not called exactly once.");
            DatabaseServiceMock.Verify(databaseService => databaseService.SyncRecipesAsync(), Times.Once, "Function IDatabaseService.SyncRecipesAsync not called exactly once.");
            DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipesAsync(), Times.Once, "Function IDatabaseService.GetRecipesAsync not called exactly once.");
        }
Пример #12
0
        public async Task CreateConversation_ShouldCreateConversationAndAddIdToMembersUserData()
        {
            // Arrange
            string expectedName = Constants.ConversationInfo1.Name;

            AuthServiceMock.Setup(authService => authService.CurrentUser).Returns(Constants.User1);

            // Act
            await MessagingService.CreateConversation(expectedName);

            // Assert
            // Verify that one (and only one) conversation with the correct info is added to the database.
            var conversations = await DatabaseServiceMock.Ref(DatabasePaths.Conversations)
                                .Once <Dictionary <string, ConversationModel> >();

            var conversation = conversations.First().Value;

            Assert.AreEqual(conversations.Count, 1);
            Assert.IsNotNull(conversation);
        }
        public async Task LoginUserAsync_WhenRefusingLoginWithInternetConnection_ShouldDoNothing()
        {
            // Arrange
            var alertTitle        = "Geen internet connectie";
            var alertMessage      = "Het is niet mogelijk om in te loggen. Controleer uw internet connectie en probeer opnieuw.";
            var alertCancelButton = "Ok";

            AuthServiceMock.Setup(authService => authService.LoginAsync()).Returns(Task.Run(() => GoogleActionStatus.Canceled));
            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(() => null);
            PageDialogServiceMock.Setup(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton)).Verifiable();

            // Act
            await AccountSettingsPageViewModel.LoginUserAsync();

            // Assert
            AuthServiceMock.Verify(authService => authService.LoginAsync(), Times.Once, "Function AuthenticationService.LoginAsync not called exactly once.");
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.Never, "Function AuthenticationService.GetUser called atleast once.");
            PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Never, "Alert for no internet connection called atleast once.");
            Assert.IsNull(AccountSettingsPageViewModel.User, "Attribute AccountSettingsPageViewModel.User is not null.");
        }
Пример #14
0
        public async Task ToggleLogin_WhenRefusingLogin_ShouldNotDisplayAlert()
        {
            // Arrange
            var alertTitle        = "Uitgelogd!";
            var alertMessage      = "U bent succesvol uitgelogd.";
            var alertCancelButton = "Ok";

            AuthServiceMock.Setup(authService => authService.GetUser()).Returns(CurrentUser);
            AuthServiceMock.Setup(authService => authService.LogoutAsync()).Returns(Task.Run(() => false));

            // Act
            await MainPageViewModel.ToggleLogin();

            // Assert
            AuthServiceMock.Verify(authService => authService.GetUser(), Times.AtLeastOnce, "Function IAuthenticationService.GetUser not called atleast once.");
            AuthServiceMock.Verify(authService => authService.LoginAsync(), Times.Never, "Function IAuthenticationService.LoginAsync called atleast once.");
            AuthServiceMock.Verify(authService => authService.LogoutAsync(), Times.Once, "Function IAuthenticationService.Logout not not called exactly once.");
            DatabaseServiceMock.Verify(databaseService => databaseService.GetRecipesAsync(), Times.Never, "Function IDatabaseService.GetRecipesAsync called atleast once.");
            PageDialogServiceMock.Verify(dialogService => dialogService.DisplayAlertAsync(alertTitle, alertMessage, alertCancelButton), Times.Never, "Logout alert displayed atleast once.");
        }
Пример #15
0
        public async Task GetConversations_ShouldReturnExistingConversations()
        {
            // Arrange
            User user = Constants.User1;
            var  expectedConversationInfos = new Dictionary <string, ConversationModel>()
            {
                { Constants.ConversationInfo1.Id, Constants.ConversationInfo1 },
                { Constants.ConversationInfo2.Id, Constants.ConversationInfo2 }
            };

            var expectedUserConversations = new Dictionary <string, string>();

            foreach (var conversationId in expectedConversationInfos.Keys)
            {
                expectedUserConversations.Add(conversationId, conversationId);
            }

            AuthServiceMock.Setup(authService => authService.CurrentUser).Returns(user);

            await DatabaseServiceMock.Ref(DatabasePaths.Users)
            .Child(user.Id)
            .Child(DatabasePaths.Conversations)
            .Set(expectedUserConversations);

            await DatabaseServiceMock.Ref(DatabasePaths.Conversations)
            .Set(expectedConversationInfos);

            // Act
            var actualConversations = await MessagingService.GetConversations();

            // Assert
            var expectedConversations = expectedConversationInfos.Values.Select(info => new Conversation(info, AuthServiceMock.Object, DatabaseServiceMock));

            Assert.AreEqual(expectedConversations.Count(), actualConversations.Count());
            foreach (var expectedConversation in expectedConversations)
            {
                Assert.IsTrue(actualConversations.Contains(expectedConversation));
            }
        }