コード例 #1
0
        public async Task GetArtifactPermissions_MultipleProjectsWithNullPermission_ReturnsReadPermissions()
        {
            // Arrange
            int revisionId = 1;
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlArtifactPermissionsRepository(cxn.Object);

            MockToReturnInstanceAdmin(false, cxn);
            var itemIds = new List <int> {
                1
            };
            var mockProjectsArtifactsItemsResult = new List <ProjectsArtifactsItem>
            {
                new ProjectsArtifactsItem
                {
                    HolderId          = 1,
                    VersionArtifactId = 1,
                    VersionProjectId  = 1
                },
                new ProjectsArtifactsItem
                {
                    HolderId          = 3,
                    VersionArtifactId = 3,
                    VersionProjectId  = 3
                }
            }.AsEnumerable();
            var mockVersionProjectInfoResult = new List <VersionProjectInfo>
            {
                new VersionProjectInfo
                {
                    ProjectId   = 2,
                    Permissions = (long)RolePermissions.Read
                },
                new VersionProjectInfo
                {
                    ProjectId = 3
                }
            }.AsEnumerable();

            MockQueryMultipleAsync(itemIds, cxn, mockProjectsArtifactsItemsResult, mockVersionProjectInfoResult, revisionId);
            var mockOpenArtifactPermissionsResult = new List <OpenArtifactPermission>()
            {
                new OpenArtifactPermission
                {
                    HolderId    = 1,
                    Permissions = (long)RolePermissions.Read
                }
            }.AsEnumerable();

            MockGetOpenArtifactPermissions(mockOpenArtifactPermissionsResult, cxn, new List <int>()
            {
                1
            }, revisionId);

            // Act
            var result = await repository.GetArtifactPermissions(itemIds, 0, false, revisionId);

            // Assert
            Assert.IsTrue(result[1] == RolePermissions.Read);
        }
コード例 #2
0
        public async Task GetArtifactPermissions_UserIsInstanceAdmin_ReturnsAllPermissions()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlArtifactPermissionsRepository(cxn.Object);

            MockToReturnInstanceAdmin(true, cxn);
            var itemIds = new List <int> {
                1
            };
            var allPermissions = Enum.GetValues(typeof(RolePermissions)).Cast <long>().Aggregate(RolePermissions.None, (current, permission) => current | (RolePermissions)permission);

            // Act
            var result = await repository.GetArtifactPermissions(itemIds, 0);


            // Assert
            Assert.IsTrue(result[1] == allPermissions);
        }
コード例 #3
0
        public async Task GetArtifactPermissions_VersionProjectInfosContainsProjectId_ReturnsEditPermissions()
        {
            // Arrange
            var cxn        = new SqlConnectionWrapperMock();
            var repository = new SqlArtifactPermissionsRepository(cxn.Object);

            MockToReturnInstanceAdmin(false, cxn);
            var itemIds = new List <int> {
                1
            };
            var mockProjectsArtifactsItemsResult = new List <ProjectsArtifactsItem>
            {
                new ProjectsArtifactsItem
                {
                    HolderId          = 1,
                    VersionArtifactId = 1,
                    VersionProjectId  = 1
                }
            }.AsEnumerable();
            var mockVersionProjectInfoResult = new List <VersionProjectInfo>
            {
                new VersionProjectInfo
                {
                    ProjectId   = 1,
                    Permissions = (long)RolePermissions.Edit
                }
            }.AsEnumerable();

            MockQueryMultipleAsync(itemIds, cxn, mockProjectsArtifactsItemsResult, mockVersionProjectInfoResult);

            // Act
            var result = await repository.GetArtifactPermissions(itemIds, 0);

            // Assert
            Assert.IsTrue(result[1] == RolePermissions.Edit);
        }