예제 #1
0
            public void Should_Return_Collection_Of_Valid_Iteration_Changes()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 22);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var changes = pullRequest.GetIterationChanges(500);

                // Then
                changes.ShouldNotBeNull();
                changes.ShouldNotBeEmpty();
                changes.Count().ShouldBe(2);

                changes.First().ShouldNotBeNull();
                changes.First().ShouldBeOfType <TfsPullRequestIterationChange>();
                changes.First().ChangeId.ShouldBe(100);
                changes.First().ChangeTrackingId.ShouldBe(1);
                changes.First().ItemPath.ShouldBeOfType <FilePath>();
                changes.First().ItemPath.FullPath.ShouldBe("/src/my/class1.cs");

                changes.Skip(1).First().ShouldNotBeNull();
                changes.Skip(1).First().ShouldBeOfType <TfsPullRequestIterationChange>();
                changes.Skip(1).First().ChangeId.ShouldBe(200);
                changes.Skip(1).First().ChangeTrackingId.ShouldBe(2);
                changes.Skip(1).First().ItemPath.ShouldBeNull();
            }
예제 #2
0
            public void Should_Return_Null_Azure_DevOps_Pull_Request_By_Branch()
            {
                // Given
                var fixture =
                    new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, "somebranch")
                {
                    GitClientFactory = new FakeNullGitClientFactory(),
                    Settings         = { ThrowExceptionIfPullRequestCouldNotBeFound = false },
                };

                // When
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // Then
                pullRequest.ShouldNotBe(null);
                pullRequest.HasPullRequestLoaded.ShouldBe(false);
                pullRequest.RepositoryName.ShouldBe("MyRepoName");
                pullRequest.CollectionName.ShouldBe("DefaultCollection");
                pullRequest.ProjectName.ShouldBe("MyProject");
                pullRequest.PullRequestId.ShouldBe(0);
                pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.NotSet);
                pullRequest.CodeReviewId.ShouldBe(0);
                pullRequest.SourceRefName.ShouldBeEmpty();
                pullRequest.TargetRefName.ShouldBeEmpty();
                pullRequest.LastSourceCommitId.ShouldBeEmpty();
                pullRequest.LastTargetCommitId.ShouldBeEmpty();
            }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TfsPullRequestSystem"/> class.
        /// Connects to the TFS server using NTLM authentication.
        /// </summary>
        /// <param name="log">The Cake log context.</param>
        /// <param name="settings">Settings for accessing TFS.</param>
        public TfsPullRequestSystem(ICakeLog log, TfsPullRequestSystemSettings settings)
            : base(log)
        {
            settings.NotNull(nameof(settings));

            this.settings = settings;

            if (settings.CheckCommitId)
            {
                this.AddCapability(new TfsCheckingCommitIdCapability(log, this));
                this.Log.Information("Commit ID check capability is enabled.");
            }
            else
            {
                this.Log.Information("Commit ID check capability is disabled.");
            }

            if (settings.ManageDiscussionThreadStatus)
            {
                this.AddCapability(new TfsDiscussionThreadsCapability(log, this));
                this.Log.Information("Discussion thread status management capability is enabled.");
            }
            else
            {
                this.Log.Information("Discussion thread status management capability is disabled.");
            }

            // Filtering by modified files is always required as we otherwise no longer can compare issues
            // in a subsequent run as we lose information about file and line.
            // See https://github.com/cake-contrib/Cake.Issues.PullRequests.Tfs/issues/46#issuecomment-419149355
            this.AddCapability(new TfsFilteringByModifiedFilesCapability(log, this));

            this.tfsPullRequest = new TfsPullRequest(log, settings);
        }
예제 #4
0
            public void Should_Resolve_Comment_Thread()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 21);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                pullRequest.ResolveCommentThread(123);

                // Then
                // ?? Nothing to validate here since the method returns void
            }
예제 #5
0
            public void Should_Throw_If_Input_Thread_Is_Null()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 100);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var result = Record.Exception(() => pullRequest.CreateCommentThread(null));

                // Then
                Assert.IsType <NullReferenceException>(result);
            }
예제 #6
0
            public void Should_Throw_If_Tfs_Pull_Request_Status_Is_Null()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 16);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var result = Record.Exception(() => pullRequest.SetStatus(null));

                // Then
                result.IsArgumentNullException("status");
            }
예제 #7
0
            public void Should_Set_Approved_Vote_On_Tfs_Pull_Request()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 23);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                pullRequest.Vote(TfsPullRequestVote.Approved);

                // Then
                // ?? Nothing to validate here since the method returns void
            }
예제 #8
0
            public void Should_Return_Valid_Iteration_Id()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 12);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                int id = pullRequest.GetLatestIterationId();

                // Then
                id.ShouldBe(42);
            }
예제 #9
0
            public void Should_Return_Invalid_Id_If_Something_Is_Wrong_With_Iteration()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 13);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                int id = pullRequest.GetLatestIterationId();

                // Then
                id.ShouldBe(-1);
            }
예제 #10
0
            public void Should_Activate_Comment_Thread()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 12);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                pullRequest.ActivateCommentThread(321);

                // Then
                // ?? Nothing to validate here since the method returns void
            }
예제 #11
0
            public void Should_Create_Valid_Comment_Thread()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 200);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                pullRequest.CreateCommentThread(new TfsPullRequestCommentThread {
                    Id = 300, Status = TfsCommentThreadStatus.Pending, FilePath = "/index.html"
                });

                // Then
                // ?? Nothing to validate here since the method returns void
            }
예제 #12
0
            public void Should_Throw_If_Vote_Value_Is_Invalid_On_Tfs_Pull_Request()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 23);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var result = Record.Exception(() => pullRequest.Vote((TfsPullRequestVote)3));

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("Vote");
                result.Message.ShouldBe("Something went wrong");
            }
예제 #13
0
            public void Should_Not_Throw_If_Null_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 100)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                pullRequest.CreateCommentThread(new TfsPullRequestCommentThread());

                // Then
                // ?? Nothing to validate here since the method returns void
            }
예제 #14
0
            public void Should_Throw_If_Null_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 11)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var result = Record.Exception(() => pullRequest.GetLatestIterationId());

                // Then
                result.IsTfsException();
            }
예제 #15
0
            public void Should_Not_Throw_If_Null_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 21)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var changes = pullRequest.GetIterationChanges(42);

                // Then
                changes.ShouldBeNull();
            }
예제 #16
0
            public void Should_Set_Valid_Status_On_Tfs_Pull_Request()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 16);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new TfsPullRequestStatus("Hello")
                {
                    State = TfsPullRequestStatusState.Succeeded
                };

                // When
                pullRequest.SetStatus(status);

                // Then
                // ?? Nothing to validate here since the method returns void
            }
예제 #17
0
        public static TfsPullRequest TfsPullRequest(
            this ICakeContext context,
            TfsPullRequestSettings settings)
        {
            context.NotNull(nameof(context));
            settings.NotNull(nameof(settings));

            var pullRequest = new TfsPullRequest(context.Log, settings, new GitClientFactory());

            if (pullRequest.HasPullRequestLoaded)
            {
                return(pullRequest);
            }

            return(null);
        }
예제 #18
0
            public void Should_Not_Fail_If_Empty_List_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 33)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var threads = pullRequest.GetCommentThreads();

                // Then
                threads.ShouldNotBeNull();
                threads.ShouldBeEmpty();
            }
예제 #19
0
            public void Should_Return_Valid_Comment_Threads()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 44);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var threads = pullRequest.GetCommentThreads();

                // Then
                threads.ShouldNotBeNull();
                threads.ShouldNotBeEmpty();
                threads.Count().ShouldBe(2);

                TfsPullRequestCommentThread thread1 = threads.First();

                thread1.Id.ShouldBe(11);
                thread1.Status.ShouldBe(TfsCommentThreadStatus.Active);
                thread1.FilePath.ShouldNotBeNull();
                thread1.FilePath.FullPath.ShouldBe("some/path/to/file.cs");

                thread1.Comments.ShouldNotBeNull();
                thread1.Comments.ShouldNotBeEmpty();
                thread1.Comments.Count().ShouldBe(2);

                TfsComment comment11 = thread1.Comments.First();

                comment11.ShouldNotBeNull();
                comment11.Content.ShouldBe("Hello");
                comment11.IsDeleted.ShouldBe(false);
                comment11.CommentType.ShouldBe(TfsCommentType.CodeChange);

                TfsComment comment12 = thread1.Comments.Last();

                comment12.ShouldNotBeNull();
                comment12.Content.ShouldBe("Goodbye");
                comment12.IsDeleted.ShouldBe(true);
                comment12.CommentType.ShouldBe(TfsCommentType.Text);

                TfsPullRequestCommentThread thread2 = threads.Last();

                thread2.Id.ShouldBe(22);
                thread2.Status.ShouldBe(TfsCommentThreadStatus.Fixed);
                thread2.FilePath.ShouldBeNull();
                thread2.Comments.ShouldNotBeNull();
                thread2.Comments.ShouldBeEmpty();
            }
예제 #20
0
            public void Should_Return_Empty_Collection_If_No_Changes_Found()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 42)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory()
                };
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var files = pullRequest.GetModifiedFiles();

                // Then
                files.ShouldBeOfType <List <FilePath> >();
                files.ShouldNotBeNull();
                files.ShouldBeEmpty();
            }
예제 #21
0
            public void Should_Throw_If_Null_Is_Returned_On_Tfs_Pull_Request()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 23)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var result = Record.Exception(() => pullRequest.Vote(TfsPullRequestVote.WaitingForAuthor));

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("Vote");
                result.IsTfsPullRequestNotFoundException();
            }
예제 #22
0
            public void Should_Throw_If_Target_Branch_Not_Found()
            {
                // Given
                var fixture =
                    new CreatePullRequestFixture(
                        BasePullRequestFixture.ValidTfsUrl,
                        "testBranch",
                        "NotExistingBranch",
                        "test",
                        "test");

                // When
                var result =
                    Record.Exception(() => TfsPullRequest.Create(fixture.Log, fixture.GitClientFactory, fixture.Settings));

                // Then
                result.IsTfsBranchNotFoundException($"Branch not found \"NotExistingBranch\"");
            }
예제 #23
0
            public void Should_Throw_If_Tfs_Pull_Request_State_Is_Invalid()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 16);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new TfsPullRequestStatus("whatever")
                {
                    State = (TfsPullRequestStatusState)123
                };

                // When
                var result = Record.Exception(() => pullRequest.SetStatus(status));

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("SetStatus");
                result.Message.ShouldBe("Unknown value");
            }
예제 #24
0
            public void Should_Throw_If_Log_Is_Null()
            {
                // Given
                var fixture =
                    new CreatePullRequestFixture(
                        BasePullRequestFixture.ValidTfsUrl,
                        "testBranch",
                        "NotExistingBranch",
                        "test",
                        "test");
                ICakeLog log = null;

                // When
                var result =
                    Record.Exception(() => TfsPullRequest.Create(log, fixture.GitClientFactory, fixture.Settings));

                // Then
                result.IsArgumentNullException("log");
            }
예제 #25
0
            public void Should_Throw_If_Settings_Are_Null()
            {
                // Given
                var fixture =
                    new CreatePullRequestFixture(
                        BasePullRequestFixture.ValidTfsUrl,
                        "testBranch",
                        "NotExistingBranch",
                        "test",
                        "test");
                TfsCreatePullRequestSettings settings = null;

                // When
                var result =
                    Record.Exception(() => TfsPullRequest.Create(fixture.Log, fixture.GitClientFactory, settings));

                // Then
                result.IsArgumentNullException("settings");
            }
예제 #26
0
            public void Should_Return_A_PullRequest_With_Fallback_To_Default_Target_Branch()
            {
                // Given
                var    sourceRefName = "testBranch";
                string targetRefName = null;
                var    title         = "foo";
                var    description   = "bar";
                var    fixture       =
                    new CreatePullRequestFixture(
                        BasePullRequestFixture.ValidTfsUrl,
                        sourceRefName,
                        targetRefName,
                        title,
                        description);

                // When
                TfsPullRequest.Create(fixture.Log, fixture.GitClientFactory, fixture.Settings);

                // Then
                // Return is a mocked pull request unrelated to the input values
            }
예제 #27
0
            public void Should_Throw_If_Null_Is_Returned_On_Tfs_Pull_Request()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 16)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new TfsPullRequestStatus("One")
                {
                    State = TfsPullRequestStatusState.Failed
                };

                // When
                var result = Record.Exception(() => pullRequest.SetStatus(status));

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("SetStatus");
                result.IsTfsPullRequestNotFoundException();
            }
예제 #28
0
            public void Should_Return_Valid_Collection_Of_Modified_Files()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidTfsUrl, 42);
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var files = pullRequest.GetModifiedFiles();

                // Then
                files.ShouldNotBeNull();
                files.ShouldNotBeEmpty();
                files.ShouldHaveSingleItem();

                var filePath = files.First();

                filePath.ShouldBeOfType <FilePath>();
                filePath.ShouldNotBeNull();
                filePath.FullPath.ShouldNotBeEmpty();
                filePath.FullPath.ShouldBe("src/project/myclass.cs");
            }
예제 #29
0
            public void Should_Return_Valid_Azure_DevOps_Pull_Request_By_Source_Branch()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, "feature");

                // When
                var pullRequest = new TfsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // Then
                pullRequest.ShouldNotBe(null);
                pullRequest.HasPullRequestLoaded.ShouldBe(true);
                pullRequest.PullRequestId.ShouldBe(777);
                pullRequest.PullRequestStatus.ShouldBe(TfsPullRequestState.Active);
                pullRequest.RepositoryName.ShouldBe("MyRepoName");
                pullRequest.CollectionName.ShouldBe("DefaultCollection");
                pullRequest.CodeReviewId.ShouldBe(123);
                pullRequest.ProjectName.ShouldBe("MyProject");
                pullRequest.SourceRefName.ShouldBe("feature");
                pullRequest.TargetRefName.ShouldBe("master");
                pullRequest.LastSourceCommitId.ShouldBe("4a92b977");
                pullRequest.LastTargetCommitId.ShouldBe("78a3c113");
            }