Ejemplo n.º 1
0
            public async Task UpdatesWithNewLineNumber()
            {
                var baseContents    = @"Line 1
Line 2
Line 3
Line 4";
                var headContents    = @"Line 1
Line 2
Line 3 with comment
Line 4";
                var newHeadContents = @"Inserted Line
Line 1
Line 2
Line 3 with comment
Line 4";

                var comment = CreateComment(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment");

                using (var diffService = new FakeDiffService(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment);
                    var target      = CreateTarget(diffService);

                    var threads = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff,
                        "HEAD_SHA");

                    Assert.That(2, Is.EqualTo(threads[0].LineNumber));

                    diff = await diffService.Diff(FilePath, newHeadContents);

                    var changedLines = target.UpdateCommentThreads(threads, diff);

                    Assert.That(3, Is.EqualTo(threads[0].LineNumber));
                    Assert.That(
                        new[]
                    {
                        Tuple.Create(2, DiffSide.Right),
                        Tuple.Create(3, DiffSide.Right)
                    },
                        Is.EqualTo(changedLines.ToArray()));
                }
            }
Ejemplo n.º 2
0
            public async Task MatchesReviewCommentOnDifferentLine()
            {
                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var headContents = @"New Line 1
New Line 2
Line 1
Line 2
Line 3 with comment
Line 4";

                var comment = CreateComment(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment");

                using (var diffService = new FakeDiffService(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff);

                    var thread = result.Single();
                    Assert.Equal(4, thread.LineNumber);
                }
            }
Ejemplo n.º 3
0
        static IPullRequestSessionService CreateService(FakeDiffService diffService)
        {
            var result = Substitute.For <IPullRequestSessionService>();

            result.Diff(
                Arg.Any <ILocalRepositoryModel>(),
                Arg.Any <string>(),
                Arg.Any <string>(),
                Arg.Any <string>(),
                Arg.Any <byte[]>())
            .Returns(i => diffService.Diff(
                         null,
                         i.ArgAt <string>(1),
                         i.ArgAt <string>(2),
                         i.ArgAt <string>(3),
                         i.ArgAt <byte[]>(4)));
            result.GetTipSha(Arg.Any <ILocalRepositoryModel>()).Returns("BRANCH_TIP");

            var diffChunk = "@@ -1,4 +1,4 @@";

            result.PostReviewComment(null, null, null, 0, null, 0).ReturnsForAnyArgs(i =>
                                                                                     CreateComment(diffChunk, i.ArgAt <string>(4)));
            result.PostReviewComment(null, null, null, 0, null, null, null, 0).ReturnsForAnyArgs(i =>
                                                                                                 CreateComment(diffChunk, i.ArgAt <string>(4)));
            return(result);
        }
        static IPullRequestSessionService CreateService(FakeDiffService diffService)
        {
            var result = Substitute.For <IPullRequestSessionService>();

            result.Diff(
                Arg.Any <ILocalRepositoryModel>(),
                Arg.Any <string>(),
                Arg.Any <string>(),
                Arg.Any <byte[]>())
            .Returns(i => diffService.Diff(
                         null,
                         i.ArgAt <string>(1),
                         i.ArgAt <string>(2),
                         i.ArgAt <byte[]>(3)));
            result.GetTipSha(Arg.Any <ILocalRepositoryModel>()).Returns("BRANCH_TIP");
            return(result);
        }
Ejemplo n.º 5
0
            public async Task ReturnsLineNumberMinus1ForNonMatchingComment()
            {
                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var headContents = @"Line 1
Line 2
Line 3 with comment
Line 4";

                var comment1 = CreateCommentThread(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment", position: 1);

                var comment2 = CreateCommentThread(@"@@ -1,4 +1,4 @@
-Line 1
 Line 2
-Line 3
+Line 3 with comment", position: 2);

                using (var diffService = new FakeDiffService(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment1, comment2);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff,
                        "HEAD_SHA");

                    Assert.That(result.Count, Is.EqualTo(2));
                    Assert.That(result[1].LineNumber, Is.EqualTo(-1));
                }
            }
Ejemplo n.º 6
0
            public async Task HandlesDifferingPathSeparators()
            {
                var winFilePath    = @"foo\test.cs";
                var gitHubFilePath = "foo/test.cs";

                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var headContents = @"New Line 1
New Line 2
Line 1
Line 2
Line 3 with comment
Line 4";

                var comment = CreateCommentThread(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment", gitHubFilePath);

                using (var diffService = new FakeDiffService(winFilePath, baseContents))
                {
                    var diff = await diffService.Diff(winFilePath, headContents);

                    var pullRequest = CreatePullRequest(gitHubFilePath, comment);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        winFilePath,
                        diff,
                        "HEAD_SHA");

                    var thread = result.First();
                    Assert.That(thread.LineNumber, Is.EqualTo(4));
                }
            }
            public async Task IgnoreCommentsWithNoDiffLineContext()
            {
                var baseContents = "Line 1";
                var headContents = "Line 1";

                var comment = CreateComment(@"@@ -10,7 +10,6 @@ class Program");

                using (var diffService = new FakeDiffService(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff);

                    Assert.That(result, Is.Empty);
                }
            }
Ejemplo n.º 8
0
            public async Task UnmarksStaleThreads()
            {
                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var headContents = @"Line 1
Line 2
Line 3 with comment
Line 4";

                var comment = CreateCommentThread(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment");

                using (var diffService = new FakeDiffService(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment);
                    var target      = CreateTarget(diffService);

                    var threads = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff,
                        "HEAD_SHA");

                    threads[0].IsStale = true;
                    var changedLines = target.UpdateCommentThreads(threads, diff);

                    Assert.That(threads[0].IsStale, Is.False);
                    Assert.That(changedLines.ToArray(), Is.EqualTo(new[] { Tuple.Create(2, DiffSide.Right) }));
                }
            }