public async Task DeleteUsersAsync_UsersToDeleteDoNotExists_QueryReturnEmptyCollection() { // arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); int[] userIds = { }; var operationScope = new OperationScope { Ids = userIds, SelectAll = false }; var userIdTable = SqlConnectionWrapper.ToDataTable(operationScope.Ids); var returntResult = new List <int>(); cxn.SetupQueryAsync("DeleteUsers", new Dictionary <string, object> { { "UserIds", userIdTable }, { "Search", "" }, { "SessionUserId", 0 }, { "SelectAll", operationScope.SelectAll } }, returntResult); // act var result = await repository.DeleteUsersAsync(operationScope, string.Empty, 0, null); // assert cxn.Verify(); Assert.AreEqual(result.Count, returntResult.Count); }
public async Task AddUserAsync_SuccessfulCreationOfUser_ReturnCreatedUserId() { // Arrange var user = new User { Login = "******", FirstName = "FirstNameValue", LastName = "LastNameValue", DisplayName = "DisplayNameValue", Email = "*****@*****.**", Source = UserGroupSource.Database, AllowFallback = false, Enabled = true, ExpirePassword = true, Password = "******", UserSALT = Guid.NewGuid(), Title = "TitleValue", Department = "Departmentvalue", GroupMembership = new int[] { 1 }, Guest = false }; var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var userId = 100; cxn.SetupExecuteScalarAsync("AddUser", It.IsAny <Dictionary <string, object> >(), userId); // Act var result = await repository.AddUserAsync(user, null); // Assert cxn.Verify(); Assert.AreEqual(result, userId); }
public async Task ValidadeUserPasswordForHistoryAsync_Invalid_False() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); const int userId = 99; var userSalt = new Guid(); const string newPassword = "******"; var passwordHystory = new List <SqlUserRepository.HashedPassword> { new SqlUserRepository.HashedPassword { Password = HashingUtilities.GenerateSaltedHash(newPassword, userSalt), UserSALT = userSalt } }; cxn.SetupQueryAsync( "GetLastUserPasswords", new Dictionary <string, object> { { "@userId", userId } }, passwordHystory); // Act var result = await repository.ValidateUserPasswordForHistoryAsync(userId, newPassword); // Assert cxn.Verify(); Assert.AreEqual(false, result); }
public async Task GetEffectiveUserLicenseAsync_QueryReturnsLicenseType_ReturnsFirst() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var userId = 1; var userIds = new[] { userId }; var userIdTable = SqlConnectionWrapper.ToDataTable(userIds); var result = new List <UserLicense> { new UserLicense { UserId = userId, LicenseType = 3 } }; cxn.SetupQueryAsync("GetEffectiveUserLicense", new Dictionary <string, object> { { "UserIds", userIdTable } }, result); // Act var licenseType = await repository.GetEffectiveUserLicenseAsync(userId); // Assert cxn.Verify(); Assert.AreEqual(result.First().LicenseType, licenseType); }
public async Task ValidadeUserPasswordForHistoryAsync_Valid_True() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); const int userId = 99; const string newPassword = "******"; var passwordHystory = new List <SqlUserRepository.HashedPassword> { new SqlUserRepository.HashedPassword { Password = "******", UserSALT = new Guid() } }; cxn.SetupQueryAsync( "GetLastUserPasswords", new Dictionary <string, object> { { "@userId", userId } }, passwordHystory); // Act var result = await repository.ValidateUserPasswordForHistoryAsync(userId, newPassword); // Assert cxn.Verify(); Assert.AreEqual(true, result); }
public async Task UpdateUserOnInvalidLoginAsync_CallsProcedureWithCorrectParameters() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); AuthenticationUser user = new AuthenticationUser { Login = "******", IsEnabled = true, InvalidLogonAttemptsNumber = 1, LastInvalidLogonTimeStamp = new DateTime(0L) }; cxn.SetupExecuteAsync( "UpdateUserOnInvalidLogin", new Dictionary <string, object> { { "Login", user.Login }, { "Enabled", user.IsEnabled }, { "InvalidLogonAttemptsNumber", user.InvalidLogonAttemptsNumber }, { "LastInvalidLogonTimeStamp", user.LastInvalidLogonTimeStamp } }, 1); // Act await repository.UpdateUserOnInvalidLoginAsync(user); // Assert cxn.Verify(); }
public async Task GetLicenseTransactionUserInfoAsync_QueryReturnsUsers_ReturnsUsers() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); int[] userIds = { 1, 2, 3 }; var userIdTable = SqlConnectionWrapper.ToDataTable(userIds); LicenseTransactionUser[] result = { new LicenseTransactionUser { Id = 1, Login = "******", Department = "Dept" }, new LicenseTransactionUser { Id = 2, Login = "******", Department = null }, new LicenseTransactionUser { Id = 3, Login = "******", Department = "Another Dept" } }; cxn.SetupQueryAsync("GetLicenseTransactionUser", new Dictionary <string, object> { { "UserIds", userIdTable } }, result); // Act IEnumerable <LicenseTransactionUser> users = await repository.GetLicenseTransactionUserInfoAsync(userIds); // Assert cxn.Verify(); CollectionAssert.AreEquivalent(result, users.ToList()); }
public async Task CheckIfAdminCanCreateUsers_CreateUsersPerInstanceLimitWasReached_ReturnFalseResult() { // arrange var returnResult = false; var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); cxn.SetupExecuteScalarAsyncFunc("select dbo.CanCreateUsers()", null, returnResult); // act var result = await repository.CheckIfAdminCanCreateUsers(); // assert cxn.Verify(); Assert.AreEqual(returnResult, result); }
public async Task AddUserToGroupsAsync_SuccessfulAddingUserToGroups_ReturnOk() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var errorId = 1; cxn.SetupExecuteScalarAsync("AddUserToGroups", It.IsAny <Dictionary <string, object> >(), 1, new Dictionary <string, object> { { "ErrorCode", errorId } }); // Act await repository.AddUserToGroupsAsync(1, new OperationScope { Ids = new[] { 3, 4 } }, string.Empty); // Assert cxn.Verify(); }
public async Task GetUser_WeDoNotHaveThisActiveUserInDb_ReturnsNull() { // arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); User[] returnResult = { }; cxn.SetupQueryAsync("GetUserDetails", new Dictionary <string, object> { { "UserId", 0 } }, returnResult); // act var result = await repository.GetUserAsync(0); // assert cxn.Verify(); Assert.IsNull(result); }
public async Task CheckUserHasProjectAdminRoleAsync_QueryReturnsFalse_ReturnsFalse() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var userId = 5; cxn.SetupExecuteScalarAsync("IsProjectAdminForAnyNonDeletedProject", new Dictionary <string, object> { { "UserId", userId } }, false); // Act var isUserHasAdminRole = await repository.CheckUserHasProjectAdminRoleAsync(userId); // Assert cxn.Verify(); Assert.IsFalse(isUserHasAdminRole); }
public async Task GetLoginUserByIdAsync_QueryReturnsEmpty_ReturnsNull() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); int userId = 5; LoginUser[] result = { }; cxn.SetupQueryAsync("GetLoginUserById", new Dictionary <string, object> { { "UserId", userId } }, result); // Act LoginUser user = await repository.GetLoginUserByIdAsync(userId); // Assert cxn.Verify(); Assert.IsNull(user); }
public async Task GetUserByLoginAsync_QueryReturnsEmpty_ReturnsNull() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); string login = "******"; AuthenticationUser[] result = { }; cxn.SetupQueryAsync("GetUserByLogin", new Dictionary <string, object> { { "Login", login } }, result); // Act AuthenticationUser user = await repository.GetUserByLoginAsync(login); // Assert cxn.Verify(); Assert.IsNull(user); }
public async Task GetUser_WeHaveThisUserInDb_QueryReturnUser() { // arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var userId = 10; User[] returnResult = { new User { Id = 5 } }; cxn.SetupQueryAsync("GetUserDetails", new Dictionary <string, object> { { "UserId", userId } }, returnResult); // act var result = await repository.GetUserAsync(userId); // assert cxn.Verify(); Assert.AreEqual(returnResult.First(), result); }
public async Task GetEffectiveUserLicenseAsync_QueryReturnsEmpty_ReturnsZero() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var userId = 1; var userIds = new[] { userId }; var userIdTable = SqlConnectionWrapper.ToDataTable(userIds); var result = Enumerable.Empty <UserLicense>(); cxn.SetupQueryAsync("GetEffectiveUserLicense", new Dictionary <string, object> { { "UserIds", userIdTable } }, result); // Act var licenseType = await repository.GetEffectiveUserLicenseAsync(userId); // Assert cxn.Verify(); Assert.AreEqual(0, licenseType); }
public async Task GetLoginUserByIdAsync_QueryReturnsUser_ReturnsFirst() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); int userId = 1; LoginUser[] result = { new LoginUser { Id = userId } }; cxn.SetupQueryAsync("GetLoginUserById", new Dictionary <string, object> { { "UserId", userId } }, result); // Act LoginUser user = await repository.GetLoginUserByIdAsync(userId); // Assert cxn.Verify(); Assert.AreEqual(result.First(), user); }
public async Task UpdateUserOnPasswordResetAsync_Success() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var user = new AuthenticationUser { Login = "******", Id = 99, Password = "******", UserSalt = new Guid() }; cxn.SetupExecuteAsync( "AddCurrentUserPasswordToHistory", new Dictionary <string, object> { { "@userId", user.Id } }, 1); cxn.SetupExecuteAsync( "UpdateUserOnPasswordResetAsync", new Dictionary <string, object> { { "@Login", user.Login }, { "@Password", user.Password }, { "@UserSALT", user.UserSalt } }, 1); // Act await repository.UpdateUserOnPasswordResetAsync(user); // Assert cxn.Verify(); }
public async Task UpdateUserAsync_SuccessfulUpdateOfUser_ReturnOk() { // Arrange var user = new User { Login = "******", FirstName = "FirstNameValueUpdate", LastName = "LastNameValueUpdate", DisplayName = "DisplayNameValueUpdate", Email = "*****@*****.**", Source = UserGroupSource.Database, AllowFallback = false, Enabled = true, ExpirePassword = true, Password = "******", UserSALT = Guid.NewGuid(), Title = "TitleValue", Department = "DepartmentvalueUpdate", GroupMembership = new int[] { 1 }, Guest = false, CurrentVersion = 1 }; var cxn = new SqlConnectionWrapperMock(); var repository = new SqlUserRepository(cxn.Object, cxn.Object); var errorId = 1; cxn.SetupExecuteAsync("UpdateUser", It.IsAny <Dictionary <string, object> >(), 1, new Dictionary <string, object> { { "ErrorCode", errorId } }); // Act await repository.UpdateUserAsync(user, null); // Assert cxn.Verify(); }