public async Task UpdateGroupAsync_GeneralSqlExeption_ReturnException()
        {
            // Arrange
            var group = new GroupDto
            {
                Name           = "GroupName",
                Email          = "GroupEmail",
                Source         = UserGroupSource.Database,
                LicenseType    = LicenseType.Author,
                CurrentVersion = 0
            };
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlGroupRepository(cxn.Object);
            var errorId    = (int)SqlErrorCodes.GeneralSqlError;
            var groupId    = 1;

            cxn.SetupExecuteScalarAsync("UpdateGroup", It.IsAny <Dictionary <string, object> >(), 0, new Dictionary <string, object> {
                { "ErrorCode", errorId }
            });

            // Act
            await repository.UpdateGroupAsync(groupId, group, null);

            // Assert
            // Exception
        }
        public async Task DeleteMembersFromGroupAsync_SuccessfulDeletingMembers_ReturnCountDeletedMembers()
        {
            // Arrange
            var assignScope = new AssignScope
            {
                SelectAll = true,
                Members   = new List <KeyValuePair <int, UserType> > {
                    new KeyValuePair <int, UserType>(1, UserType.User)
                }
            };
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlGroupRepository(cxn.Object);
            var errorId    = 0;
            var groupId    = 1;

            cxn.SetupExecuteScalarAsync("DeleteMembersFromGroup", It.IsAny <Dictionary <string, object> >(), 0, new Dictionary <string, object> {
                { "ErrorCode", errorId }
            });

            // Act
            await repository.DeleteMembersFromGroupAsync(groupId, assignScope);

            // Assert
            cxn.Verify();
        }
        public async Task DeleteMembersFromGroupAsync_GroupWithCurrentIdNotExist_ReturnNotFoundException()
        {
            // Arrange
            var assignScope = new AssignScope
            {
                SelectAll = true,
                Members   = new List <KeyValuePair <int, UserType> > {
                    new KeyValuePair <int, UserType>(1, UserType.User)
                }
            };
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlGroupRepository(cxn.Object);
            var errorId    = (int)SqlErrorCodes.GroupWithCurrentIdNotExist;
            var groupId    = 1;

            cxn.SetupExecuteScalarAsync("DeleteMembersFromGroup", It.IsAny <Dictionary <string, object> >(), 0, new Dictionary <string, object> {
                { "ErrorCode", errorId }
            });

            // Act
            await repository.DeleteMembersFromGroupAsync(groupId, assignScope);

            // Assert
            // Exception
        }
Exemplo n.º 4
0
        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 MakePermanent_Returns_NumberEffectedRows()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn                = new SqlConnectionWrapperMock();
            var repository         = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid               = Guid.NewGuid();
            var numberEffectedRows = 2;

            cxn.SetupExecuteScalarAsync(
                "[FileStore].MakeFilePermanent",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                numberEffectedRows);

            // Act
            var rows = await repository.MakeFilePermanent(guid);

            // Assert
            cxn.Verify();
            Assert.AreEqual(numberEffectedRows, rows);
        }
        public async Task DeleteFile_QueryReturnsNull_ReturnsNotNull()
        {
            // Arrange
            var configRepoMock = new Mock <IConfigRepository>();

            configRepoMock.Setup((m) => m.CommandTimeout).Returns(60);
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlFilesRepository(cxn.Object, configRepoMock.Object);
            var guid       = new Guid("34567345673456734567345673456734");

            cxn.SetupExecuteScalarAsync(
                "[FileStore].DeleteFile",
                new Dictionary <string, object> {
                { "FileId", guid }
            },
                1,
                new Dictionary <string, object> {
                { "ExpiredTime", DateTime.UtcNow }
            });

            // Act
            Guid?id = await repository.DeleteFile(guid, DateTime.UtcNow);

            // Assert
            cxn.Verify();
            Assert.IsNotNull(id);
        }
Exemplo n.º 7
0
        public async Task AddArtifactsToCollectionAsync_AllParametersAreValid_Success()
        {
            // Arrange
            var expectedResult = 3;

            var artifactIds = new List <int> {
                1, 2, 3
            };

            _cxn.SetupExecuteScalarAsync("AddArtifactsToCollection", It.IsAny <Dictionary <string, object> >(),
                                         expectedResult);

            // Act
            var actualResult = await _repository.AddArtifactsToCollectionAsync(_collectionId, artifactIds, _userId);

            Assert.IsNotNull(actualResult);
            Assert.AreEqual(expectedResult, actualResult);
        }
Exemplo n.º 8
0
        public async Task AreEmailDiscussionsEnabled_EnableEmailRepliesProjectHasPermission_ReturnsTrue()
        {
            // Arrange
            var projectId = 1;

            _fakeEmailSettings.EnableEmailReplies = true;
            _instanceSettingsRepository           = new SqlInstanceSettingsRepositoryMock(_fakeEmailSettings, _instanceSettings);
            _cxn.SetupExecuteScalarAsync("GetProjectPermissions", new Dictionary <string, object> {
                { "ProjectId", projectId }
            }, ProjectPermissions.AreEmailRepliesEnabled);
            // Act
            var result = await _mentionHelper.AreEmailDiscussionsEnabled(projectId);

            // Assert
            Assert.IsTrue(result);
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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();
        }