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 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 SelectSessions_SessionDoesNotExist_ReturnsEmpty() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlSessionsRepository(cxn.Object); int ps = 100; int pn = 1; Session[] result = { }; cxn.SetupQueryAsync("[AdminStore].SelectSessions", new Dictionary <string, object> { { "ps", ps }, { "pn", pn } }, result); // Act IEnumerable <Session> sessions = await repository.SelectSessions(ps, pn); // Assert cxn.Verify(); Assert.IsFalse(sessions.Any()); }
public async Task EndSession_TimeoutSessionDoesNotExist_ReturnsNull() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlSessionsRepository(cxn.Object); var guid = new Guid("00000000000000000000000000000000"); DateTime?timeoutTime = DateTime.UtcNow; var sessions = new Session[] { }; cxn.SetupQueryAsync("[AdminStore].EndSession", new Dictionary <string, object> { { "SessionId", guid }, { "TimeoutTime", timeoutTime } }, sessions); // Act Session result = await repository.EndSession(guid, timeoutTime); // Assert cxn.Verify(); Assert.IsNull(result); }
public async Task GetVersionControlArtifactInfoAsync_LatestDeleted() { // Arrange int userId = 1, itemId = 11, artifactId = 10, lockedByUserId = 2, latestDeletedByUserId = 3; SqlConnectionWrapperMock connectionWrapperMock = new SqlConnectionWrapperMock(); Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>(); artifactRepositoryMock .Setup(m => m.GetArtifactBasicDetails(itemId, userId, null)) .ReturnsAsync(new ArtifactBasicDetails { ItemId = itemId, ArtifactId = artifactId, DraftDeleted = false, LatestDeleted = true, UserId = userId, LockedByUserId = lockedByUserId, LatestDeletedByUserId = latestDeletedByUserId }); Mock <IArtifactPermissionsRepository> artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>(); artifactPermissionsRepositoryMock.Setup(apr => apr.GetArtifactPermissions( It.IsAny <IEnumerable <int> >(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null)) .ReturnsAsync(new Dictionary <int, RolePermissions> { { artifactId, RolePermissions.Read } }); SqlArtifactVersionsRepository artifactVersionsRepository = new SqlArtifactVersionsRepository( connectionWrapperMock.Object, artifactRepositoryMock.Object, artifactPermissionsRepositoryMock.Object, _itemInfoRepositoryMock.Object); // Act VersionControlArtifactInfo artifactInfo = (await artifactVersionsRepository.GetVersionControlArtifactInfoAsync(itemId, null, userId)); // Assert connectionWrapperMock.Verify(); Assert.IsNotNull(artifactInfo.DeletedByUser); Assert.IsNotNull(artifactInfo.DeletedByUser.Id); Assert.IsTrue(artifactInfo.DeletedByUser.Id.Value == latestDeletedByUserId); }
public async Task GetProcessArtifactInfo_GetProcessInfo_Success() { // Arrange artifactIds = new HashSet <int>() { 1, 2, 3 }; List <ProcessInfoDto> processInfos = new List <ProcessInfoDto>() { new ProcessInfoDto() { ItemId = 1, ProcessType = ProcessType.BusinessProcess }, new ProcessInfoDto() { ItemId = 2, ProcessType = ProcessType.UserToSystemProcess }, new ProcessInfoDto() { ItemId = 3, ProcessType = ProcessType.SystemToSystemProcess } }; var permissionDict = new Dictionary <int, RolePermissions>() { }; permissionDict.Add(key: 1, value: RolePermissions.Read); _artifactPermissionsRepository.Setup(q => q.GetArtifactPermissions(It.IsAny <IEnumerable <int> >(), session.UserId, false, Int32.MaxValue, true, null)).ReturnsAsync(permissionDict); _artifactRepositoryMock.Setup(r => r.GetProcessInformationAsync(artifactIds, session.UserId)).ReturnsAsync(processInfos); repository = new SqlArtifactRepository(cxn.Object, new SqlItemInfoRepository(new SqlConnectionWrapper("")), _artifactPermissionsRepository.Object); // Act await repository.GetProcessInformationAsync(artifactIds, session.UserId); // Assert cxn.Verify(); }
public async Task EndSession_LogoutSessionExists_ReturnsFirst() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlSessionsRepository(cxn.Object); var guid = new Guid("12345678901234567890123456789012"); var sessions = new[] { new Session { SessionId = guid } }; cxn.SetupQueryAsync("[AdminStore].EndSession", new Dictionary <string, object> { { "SessionId", guid }, { "TimeoutTime", null } }, sessions); // Act Session result = await repository.EndSession(guid); // Assert cxn.Verify(); Assert.AreEqual(sessions[0], result); }
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 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 GetUserSession_SessionExists_ReturnsFirst() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlSessionsRepository(cxn.Object); int uid = 1; Session[] result = { new Session { UserId = uid } }; cxn.SetupQueryAsync("[AdminStore].GetUserSession", new Dictionary <string, object> { { "UserId", uid } }, result); // Act Session session = await repository.GetUserSession(uid); // Assert cxn.Verify(); Assert.AreEqual(result.First(), session); }
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 ExtendSession_SessionExists_ReturnsFirst() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlSessionsRepository(cxn.Object); var guid = new Guid("12345678901234567890123456789012"); Session[] result = { new Session { SessionId = guid } }; cxn.SetupQueryAsync("[AdminStore].ExtendSession", new Dictionary <string, object> { { "SessionId", guid } }, result); // Act Session session = await repository.ExtendSession(guid); // Assert cxn.Verify(); Assert.AreEqual(result.First(), session); }
public async Task GetLockedLicenses_QueryReturnsValue_ReturnsValue() { // Arrange const int userId = 1; const int licenseLevel = 3; const int lockTime = 1440; var cxn = new SqlConnectionWrapperMock(); var repository = new SqlLicensesRepository(cxn.Object); int result = 2; cxn.SetupExecuteScalarAsync(v => true, new Dictionary <string, object> { { "UserId", userId }, { "LicenseLevel", licenseLevel }, { "TimeDiff", -lockTime } }, result); // Act var count = await repository.GetLockedLicenses(userId, 3, 1440); // Assert cxn.Verify(); Assert.AreEqual(result, count); }
public async Task GetFederatedAuthentication_QueryReturnsSettings_ReturnsFirst() { // Arrange var cxn = new SqlConnectionWrapperMock(); var repository = new SqlSettingsRepository(cxn.Object); var xml = SerializationHelper.Serialize(new FederatedAuthenticationSettings.FASettings()); dynamic dbObject = new ExpandoObject(); dbObject.Settings = xml; dbObject.Certificate = null; var expectedFedAuthSettings = new FederatedAuthenticationSettings(xml, null); var result = new[] { dbObject }; cxn.SetupQueryAsync("GetFederatedAuthentications", null, result); // Act var settings = await repository.GetFederatedAuthenticationSettingsAsync(); // Assert cxn.Verify(); Assert.IsTrue(Equals(expectedFedAuthSettings, settings)); }
public async Task AddUserAsync_SuccessfulCreationOfGroup_ReturnCreatedUserId() { // Arrange var group = new GroupDto { Name = "GroupName", Email = "GroupEmail", Source = UserGroupSource.Database, LicenseType = LicenseType.Author }; var cxn = new SqlConnectionWrapperMock(); var repository = new SqlGroupRepository(cxn.Object); var groupId = 100; cxn.SetupExecuteScalarAsync("AddGroup", It.IsAny <Dictionary <string, object> >(), groupId); // Act await repository.AddGroupAsync(group, null); // Assert cxn.Verify(); }
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 GetVersionControlArtifactInfoAsync_HasChangesLockedByMe() { // Arrange int userId = 1, itemId = 11, artifactId = 10; SqlConnectionWrapperMock connectionWrapperMock = new SqlConnectionWrapperMock(); Mock <IArtifactRepository> artifactRepositoryMock = new Mock <IArtifactRepository>(); artifactRepositoryMock .Setup(m => m.GetArtifactBasicDetails(itemId, userId, null)) .ReturnsAsync(new ArtifactBasicDetails { ItemId = itemId, ArtifactId = artifactId, HasDraftRelationships = false, UserId = userId, LockedByUserId = userId, }); Mock <IArtifactPermissionsRepository> artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>(); artifactPermissionsRepositoryMock.Setup(apr => apr.GetArtifactPermissions( It.IsAny <IEnumerable <int> >(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>(), null)) .ReturnsAsync(new Dictionary <int, RolePermissions> { { artifactId, RolePermissions.Read } }); SqlArtifactVersionsRepository artifactVersionsRepository = new SqlArtifactVersionsRepository( connectionWrapperMock.Object, artifactRepositoryMock.Object, artifactPermissionsRepositoryMock.Object, _itemInfoRepositoryMock.Object); // Act VersionControlArtifactInfo artifactInfo = (await artifactVersionsRepository.GetVersionControlArtifactInfoAsync(itemId, null, userId)); // Assert connectionWrapperMock.Verify(); Assert.IsTrue(artifactInfo.HasChanges); }
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(); }
public async Task GetArtifactVersions_Should_Not_Return_Draft_Version_When_includeDrafts_Is_False() { // Arrange int artifactId = 1; int limit = 2; int offset = 0; int? userId = 1; bool asc = true; int sessionUserId = 1; bool includeDrafts = false; var cxn = new SqlConnectionWrapperMock(); var repository = new SqlArtifactVersionsRepository(cxn.Object); var artifactVersionParams = new Dictionary <string, object> { { "artifactId", artifactId }, { "lim", limit }, { "offset", offset }, { "userId", userId.Value }, { "ascd", asc } }; cxn.SetupQueryAsync("DoesArtifactHavePublishedOrDraftVersion", new Dictionary <string, object> { { "artifactId", artifactId } }, new List <bool> { true }); cxn.SetupQueryAsync("IsArtifactDeleted", new Dictionary <string, object> { { "artifactId", artifactId } }, new List <bool> { false }); var testResult = new[] { new ArtifactHistoryVersion { VersionId = 1, UserId = 1, Timestamp = new DateTime() } }; cxn.SetupQueryAsync("GetArtifactVersions", artifactVersionParams, testResult); var userIdsTable = SqlConnectionWrapper.ToDataTable(new List <int> { sessionUserId }); cxn.SetupQueryAsync("GetUserInfos", new Dictionary <string, object> { { "userIds", userIdsTable } }, new List <UserInfo> { new UserInfo { UserId = 1, DisplayName = "David", ImageId = 1 } }); // Act var actual = await repository.GetArtifactVersions(artifactId, limit, offset, userId, asc, sessionUserId, includeDrafts); // Assert cxn.Verify(); Assert.AreEqual(actual.ArtifactId, 1); Assert.AreEqual(actual.ArtifactHistoryVersions.Count(), 1); Assert.AreEqual(actual.ArtifactHistoryVersions.ToList()[0].VersionId, 1); }
public async Task GetArtifactVersions_WithDraftsAscending_Success() { // Arrange int artifactId = 1; int limit = 2; int offset = 0; int? userId = 1; bool asc = true; int sessionUserId = 1; var cxn = new SqlConnectionWrapperMock(); var repository = new SqlArtifactVersionsRepository(cxn.Object); var prm = new Dictionary <string, object> { { "artifactId", artifactId }, { "lim", limit }, { "offset", offset }, { "userId", userId.Value }, { "ascd", asc } }; cxn.SetupQueryAsync("DoesArtifactHavePublishedOrDraftVersion", new Dictionary <string, object> { { "artifactId", artifactId } }, new List <bool> { true }); cxn.SetupQueryAsync("IsArtifactDeleted", new Dictionary <string, object> { { "artifactId", artifactId } }, new List <bool> { false }); var testResult = new ArtifactHistoryVersion[] { new ArtifactHistoryVersion { VersionId = 1, UserId = 1, Timestamp = new DateTime() } }; cxn.SetupQueryAsync("GetArtifactVersions", prm, testResult); var artifactIdsTable = SqlConnectionWrapper.ToDataTable(new List <int> { artifactId }, "Int32Collection", "Int32Value"); var prm2 = new Dictionary <string, object> { { "userId", sessionUserId }, { "artifactIds", artifactIdsTable } }; cxn.SetupQueryAsync("GetArtifactsWithDraft", prm2, new int[] { artifactId }); var userIdsTable = SqlConnectionWrapper.ToDataTable(new List <int> { sessionUserId }, "Int32Collection", "Int32Value"); cxn.SetupQueryAsync("GetUserInfos", new Dictionary <string, object> { { "userIds", userIdsTable } }, new List <UserInfo> { new UserInfo { UserId = 1, DisplayName = "David", ImageId = 1 } }); // Act var actual = await repository.GetArtifactVersions(artifactId, limit, offset, userId, asc, sessionUserId, true); // Assert cxn.Verify(); Assert.AreEqual(actual.ArtifactId, 1); Assert.AreEqual(actual.ArtifactHistoryVersions.ToList().Count(), 2); Assert.AreEqual(actual.ArtifactHistoryVersions.ToList()[1].VersionId, int.MaxValue); Assert.AreEqual(actual.ArtifactHistoryVersions.ToList()[0].VersionId, 1); }