public async Task GetSubArtifactTreeAsync_HasPermissions_OK()
        {
            // Arrange
            const int userId  = 1;
            var       session = new Session {
                UserId = userId
            };
            const int artifactId            = 2;
            var       artifactIds           = new[] { artifactId };
            var       permissionsDictionary = new Dictionary <int, RolePermissions>();

            permissionsDictionary.Add(artifactId, RolePermissions.Read);
            var subArtifacts = new List <SubArtifact> {
                new SubArtifact {
                    Id = 1
                }
            };
            var mockArtifactRepository = new Mock <IArtifactRepository>();

            mockArtifactRepository.Setup(r => r.GetSubArtifactTreeAsync(artifactId, userId, int.MaxValue, true)).ReturnsAsync(subArtifacts);
            var mockArtifactPermissionsRepository = new Mock <IArtifactPermissionsRepository>();

            mockArtifactPermissionsRepository.Setup(r => r.GetArtifactPermissions(artifactIds, userId, false, int.MaxValue, true, null)).ReturnsAsync(permissionsDictionary);
            var mockServiceLogRepository = new Mock <IServiceLogRepository>();

            var artifactController = new ArtifactController(mockArtifactRepository.Object, mockArtifactPermissionsRepository.Object, _mockSqlPrivilegesRepository.Object, mockServiceLogRepository.Object)
            {
                Request = new HttpRequestMessage()
            };

            artifactController.Request.Properties[ServiceConstants.SessionProperty] = session;

            // Act
            var result = await artifactController.GetSubArtifactTreeAsync(artifactId);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result[0].Id);
        }
        public async Task GetSubArtifactTreeAsync_NoPermissions_ThrowsNoPermissionsException()
        {
            // Arrange
            const int userId  = 1;
            var       session = new Session {
                UserId = userId
            };
            const int artifactId            = 2;
            var       artifactIds           = new[] { artifactId };
            var       permissionsDictionary = new Dictionary <int, RolePermissions>();

            permissionsDictionary.Add(artifactId, RolePermissions.None);
            var mockArtifactRepository            = new Mock <IArtifactRepository>();
            var mockArtifactPermissionsRepository = new Mock <IArtifactPermissionsRepository>();

            mockArtifactPermissionsRepository.Setup(r => r.GetArtifactPermissions(artifactIds, userId, false, int.MaxValue, true, null)).ReturnsAsync(permissionsDictionary);
            var mockServiceLogRepository = new Mock <IServiceLogRepository>();

            var artifactController = new ArtifactController(mockArtifactRepository.Object, mockArtifactPermissionsRepository.Object, _mockSqlPrivilegesRepository.Object, mockServiceLogRepository.Object)
            {
                Request = new HttpRequestMessage()
            };

            artifactController.Request.Properties[ServiceConstants.SessionProperty] = session;

            HttpResponseException result = null;

            // Act
            try {
                await artifactController.GetSubArtifactTreeAsync(artifactId);
            } catch (HttpResponseException e)
            {
                result = e;
            }
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.Forbidden, result.Response.StatusCode);
        }