public async Task GetDiscussions_Forbidden()
        {
            // Arrange
            const int artifactId = 1;
            const int projectId  = 10;
            var       itemInfo   = new ItemInfo {
                ProjectId = projectId, ArtifactId = artifactId, ItemId = artifactId
            };
            var permisionDictionary = new Dictionary <int, RolePermissions>();
            var discussion          = new Discussion {
                ItemId = artifactId
            };

            permisionDictionary.Add(artifactId, RolePermissions.None);
            _artifactVersionsRepositoryMock.Setup(m => m.IsItemDeleted(artifactId)).ReturnsAsync(false);
            _artifactPermissionsRepositoryMock.Setup(m => m.GetItemInfo(artifactId, _session.UserId, false, int.MaxValue)).ReturnsAsync(itemInfo);
            _artifactPermissionsRepositoryMock.Setup(m => m.GetArtifactPermissions(It.IsAny <IEnumerable <int> >(), _session.UserId, false, int.MaxValue, true, null)).ReturnsAsync(permisionDictionary);
            _discussionsRepositoryMock.Setup(m => m.GetDiscussions(artifactId, projectId)).ReturnsAsync(new[] { discussion });
            var controller = new DiscussionController(_discussionsRepositoryMock.Object, _artifactPermissionsRepositoryMock.Object, _artifactVersionsRepositoryMock.Object)
            {
                Request = new HttpRequestMessage()
            };

            controller.Request.Properties[ServiceConstants.SessionProperty] = _session;
            // Act
            await controller.GetDiscussions(artifactId);
        }
        public async Task GetReplies_Success()
        {
            // Arrange
            const int artifactId   = 1;
            const int projectId    = 10;
            const int discussionId = 1;
            var       itemInfo     = new ItemInfo {
                ProjectId = projectId, ArtifactId = artifactId, ItemId = artifactId
            };
            var permisionDictionary = new Dictionary <int, RolePermissions>();
            var reply = new Reply {
                ItemId = artifactId
            };

            permisionDictionary.Add(artifactId, RolePermissions.Read);
            _artifactPermissionsRepositoryMock.Setup(m => m.GetItemInfo(artifactId, _session.UserId, false, int.MaxValue)).ReturnsAsync(itemInfo);
            _artifactPermissionsRepositoryMock.Setup(m => m.GetArtifactPermissions(It.IsAny <IEnumerable <int> >(), _session.UserId, false, int.MaxValue, true, null)).ReturnsAsync(permisionDictionary);
            _discussionsRepositoryMock.Setup(m => m.GetReplies(discussionId, projectId)).ReturnsAsync(new[] { reply });
            var controller = new DiscussionController(_discussionsRepositoryMock.Object, _artifactPermissionsRepositoryMock.Object, _artifactVersionsRepositoryMock.Object)
            {
                Request = new HttpRequestMessage()
            };

            controller.Request.Properties[ServiceConstants.SessionProperty] = _session;
            // Act
            var result = await controller.GetReplies(artifactId, discussionId);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(artifactId, result.ElementAt(0).ItemId);
        }
 public async Task GetReplies_BadRequest_2()
 {
     // Arrange
     const int artifactId   = 1;
     const int discussionId = -1;
     var       controller   = new DiscussionController(_discussionsRepositoryMock.Object, _artifactPermissionsRepositoryMock.Object, _artifactVersionsRepositoryMock.Object);
     // Act
     await controller.GetReplies(artifactId, discussionId);
 }
 public async Task GetDiscussions_BadRequest_Same_Artifact_And_SubArtifactId()
 {
     // Arrange
     const int artifactId    = 1;
     const int subArtifactId = 1;
     var       controller    = new DiscussionController(_discussionsRepositoryMock.Object, _artifactPermissionsRepositoryMock.Object, _artifactVersionsRepositoryMock.Object);
     // Act
     await controller.GetDiscussions(artifactId, subArtifactId);
 }
        public async Task GetDiscussions_BadRequest_1()
        {
            // Arrange
            const int artifactId = -1;
            var       controller = new DiscussionController(_discussionsRepositoryMock.Object, _artifactPermissionsRepositoryMock.Object, _artifactVersionsRepositoryMock.Object);

            // Act
            try
            {
                var result = await controller.GetDiscussions(artifactId);
            }
            catch (BadRequestException e)
            {
                // Assert
                Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)e.ErrorCode);
            }
        }