public async Task <RoleAssignmentQueryResult <RoleAssignment> > GetProjectRoleAssignmentsAsync(int projectId, TabularData tabularData, Func <Sorting, string> sort = null) { var orderField = string.Empty; if (sort != null && tabularData.Sorting != null) { orderField = sort(tabularData.Sorting); } if (!string.IsNullOrWhiteSpace(tabularData.Search)) { tabularData.Search = UsersHelper.ReplaceWildcardCharacters(tabularData.Search); } var parameters = new DynamicParameters(); parameters.Add("@projectId", projectId); parameters.Add("@Offset", tabularData.Pagination.Offset); parameters.Add("@Limit", tabularData.Pagination.Limit); parameters.Add("@OrderField", orderField); parameters.Add("@Search", tabularData.Search); parameters.Add("@Total", dbType: DbType.Int32, direction: ParameterDirection.Output); parameters.Add("@ProjectName", dbType: DbType.String, direction: ParameterDirection.Output, size: -1); parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output); var rolesAssigments = await _connectionWrapper.QueryAsync <RoleAssignment>("GetProjectRoleAssignments", parameters, commandType : CommandType.StoredProcedure); var errorCode = parameters.Get <int?>("ErrorCode"); if (errorCode.HasValue && errorCode.Value == (int)SqlErrorCodes.ProjectWithCurrentIdNotExist) { throw new ResourceNotFoundException(ErrorMessages.ProjectNotExist, ErrorCodes.ResourceNotFound); } var total = parameters.Get <int?>("Total"); var projectName = parameters.Get <string>("ProjectName"); var queryDataResult = new RoleAssignmentQueryResult <RoleAssignment> { Items = rolesAssigments, Total = total ?? 0, ProjectName = projectName ?? string.Empty }; return(queryDataResult); }
public void Initialize() { _instanceRepositoryMock = new Mock <IInstanceRepository>(); _logRepositoryMock = new Mock <IServiceLogRepository>(); _artifactPermissionsRepositoryMock = new Mock <IArtifactPermissionsRepository>(); _privilegeRepositoryMock = new Mock <IPrivilegesRepository>(); _instanceServiceMock = new Mock <IInstanceService>(); var request = new HttpRequestMessage(); request.Properties[ServiceConstants.SessionProperty] = new Session { UserId = UserId }; _controller = new InstanceController ( _instanceRepositoryMock.Object, _logRepositoryMock.Object, _artifactPermissionsRepositoryMock.Object, _privilegeRepositoryMock.Object, _instanceServiceMock.Object) { Request = request, Configuration = new HttpConfiguration() }; _folder = new FolderDto { Name = "Folder1", ParentFolderId = 2 }; _project = new ProjectDto { Name = "Project1", Description = "Project1Description", ParentFolderId = 1 }; _pagination = new Pagination { Limit = 1, Offset = 0 }; _sorting = new Sorting { Order = SortOrder.Asc, Sort = "Name" }; var projectRolesAssignments = new List <RoleAssignment> { new RoleAssignment { GroupName = "GroupName", Id = 1, RoleName = "RoleName" } }; _rolesAssignmentsQueryResult = new RoleAssignmentQueryResult <RoleAssignment> { Items = projectRolesAssignments, Total = 1, ProjectName = "Project1" }; _instanceRepositoryMock .Setup(repo => repo.GetProjectRoleAssignmentsAsync(It.IsAny <int>(), It.IsAny <TabularData>(), It.IsAny <Func <Sorting, string> >())) .ReturnsAsync(_rolesAssignmentsQueryResult); _privilegeRepositoryMock .Setup(r => r.GetInstanceAdminPrivilegesAsync(UserId)) .ReturnsAsync(InstanceAdminPrivileges.AccessAllProjectsAdmin); _roleAssignment = new RoleAssignmentDTO() { GroupId = 1, RoleId = 1 }; _roleAssignmentId = 1; }