Beispiel #1
0
 private void AttachComments(FileChange change, FileDiffModel file)
 {
     foreach (var groups in change.Comments.GroupBy(c => c.DiffLineIndex))
     {
         foreach (var comment in groups.OrderBy(c => c.PostedOn))
         {
             file.Lines[groups.Key.Value].Comments.Add(new CommentModel()
             {
                 Id = comment.Id,
                 Author = UserModel.FromUser(comment.User),
                 Body = comment.Content,
                 IsAuthor = comment.UserId == User.Identity.UserId,
                 PostedOn = comment.PostedOn.ToLocalTime()
             });
         }
     }
 }
            public void ReturnsOkWithFileDiffModelWithCommentsIfCommentsFoundForChange()
            {
                // Arrange
                var c = CreateController();
                var add = new FileAddition()
                {
                    FileName = "blorg",
                    Diff = "blarg",
                    Comments = new List<Comment>()
                    {
                        new Comment() { DiffLineIndex = 0, Content = "blorg", UserId = ApiTestData.LoggedInUser.Id, User = ApiTestData.LoggedInUser },
                        new Comment() { DiffLineIndex = 2, Content = "blarg", UserId = ApiTestData.NotLoggedInUser.Id, User = ApiTestData.NotLoggedInUser }
                    }
                };
                var expected = new FileDiffModel()
                {
                    Lines = new List<LineDiffModel>()
                    {
                        new LineDiffModel() { Index = 0, Comments = new List<CommentModel>() },
                        new LineDiffModel() { Index = 1, Comments = new List<CommentModel>() },
                        new LineDiffModel() { Index = 2, Comments = new List<CommentModel>() },
                    }
                };
                c.MockData.Changes.Add(add);
                c.MockData.SaveChanges();
                c.MockDiff.Setup(d => d.ParseFileDiff("blorg", "blarg"))
                          .Returns(expected);

                // Act
                var result = c.Get(add.Id);

                // Assert
                Assert.Equal(HttpStatusCode.OK, result.StatusCode);
                var actual = Assert.IsType<FileDiffModel>(result.GetObjectContent());
                Assert.Same(expected, actual);
                Assert.Equal(actual.Lines[0].Comments.Single().Body, "blorg");
                Assert.True(actual.Lines[0].Comments.Single().IsAuthor);
                Assert.False(actual.Lines[1].Comments.Any());
                Assert.Equal(actual.Lines[2].Comments.Single().Body, "blarg");
                Assert.False(actual.Lines[2].Comments.Single().IsAuthor);
            }
            public void ReturnsOkWithFileDiffModelWithNoCommentsIfNoCommentsFoundForChange()
            {
                // Arrange
                var c = CreateController();
                var add = new FileAddition() { FileName = "blorg", Diff = "blarg" };
                var expected = new FileDiffModel();
                c.MockData.Changes.Add(add);
                c.MockData.SaveChanges();
                c.MockDiff.Setup(d => d.ParseFileDiff("blorg", "blarg"))
                          .Returns(expected);

                // Act
                var result = c.Get(add.Id);

                // Assert
                Assert.Equal(HttpStatusCode.OK, result.StatusCode);
                Assert.Same(expected, result.GetObjectContent());
            }