Exemple #1
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 AzureDevOpsPullRequest(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(AzureDevOpsPullRequestState.NotSet);
                pullRequest.CodeReviewId.ShouldBe(0);
                pullRequest.SourceRefName.ShouldBeEmpty();
                pullRequest.TargetRefName.ShouldBeEmpty();
                pullRequest.LastSourceCommitId.ShouldBeEmpty();
                pullRequest.LastTargetCommitId.ShouldBeEmpty();
            }
Exemple #2
0
            public void Should_Return_Collection_Of_Valid_Iteration_Changes()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 22);
                var pullRequest = new AzureDevOpsPullRequest(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 <AzureDevOpsPullRequestIterationChange>();
                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 <AzureDevOpsPullRequestIterationChange>();
                changes.Skip(1).First().ChangeId.ShouldBe(200);
                changes.Skip(1).First().ChangeTrackingId.ShouldBe(2);
                changes.Skip(1).First().ItemPath.ShouldBeNull();
            }
Exemple #3
0
            public void Should_Throw_If_AzureDevOps_Url_Is_Invalid()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.InvalidUrl, 42);

                // When
                var result = Record.Exception(() => new AzureDevOpsPullRequest(fixture.Log, fixture.Settings));

                // Then
                result.IsUrlFormatException();
            }
Exemple #4
0
            public void Should_Throw_If_Comment_Is_Whitespace()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                result.IsArgumentOutOfRangeException("comment");
            }
Exemple #5
0
            public void Should_Throw_If_AzureDevOps_Pull_Request_Status_Is_Null()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 16);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                result.IsArgumentNullException("status");
            }
Exemple #6
0
            public void Should_Throw_If_Input_Thread_Is_Null()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                result.IsArgumentNullException("thread");
            }
Exemple #7
0
            public void Should_Set_Approved_Vote_On_AzureDevOps_Pull_Request()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 23);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

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

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

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

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

                // Then
                id.ShouldBe(-1);
            }
Exemple #10
0
            public void Should_Resolve_Comment_Thread()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 21);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                pullRequest.ResolveCommentThread(123);

                // Then
                // ?? Nothing to validate here since the method returns void
            }
Exemple #11
0
            public void Should_Throw_If_Comment_Is_Null_Or_Empty_Or_Whitespace(string comment, Type expectedExceptionType)
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var result = Record.Exception(() => pullRequest.CreateComment(comment)) as ArgumentException;

                // Then
                result.ShouldNotBeNull();
                result.IsArgumentException(expectedExceptionType, "comment");
            }
Exemple #12
0
            public void Should_Throw_If_Vote_Value_Is_Invalid_On_AzureDevOps_Pull_Request()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 23);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("Vote");
                result.Message.ShouldBe("Something went wrong");
            }
Exemple #13
0
            public void Should_Throw_If_Settings_Are_Null()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 42)
                {
                    Settings = null
                };

                // When
                var result = Record.Exception(() => new AzureDevOpsPullRequest(fixture.Log, fixture.Settings));

                // Then
                result.IsArgumentNullException("settings");
            }
Exemple #14
0
            public void Should_Throw_If_Git_Client_Factory_Is_Null()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 42)
                {
                    GitClientFactory = null
                };

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

                // Then
                result.IsArgumentNullException("gitClientFactory");
            }
Exemple #15
0
            public void Should_Create_Valid_Comment_Thread()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 200);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                // ?? Nothing to validate here since the method returns void
            }
Exemple #16
0
            public void Should_Not_Throw_If_Null_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 21)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                changes.ShouldBeNull();
            }
Exemple #17
0
            public void Should_Throw_If_Strict_Is_On_And_Pull_Request_Is_Null_By_Branch()
            {
                // Given
                var fixture =
                    new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, "feature")
                {
                    GitClientFactory = new FakeNullGitClientFactory(),
                };

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

                // Then
                result.IsAzureDevOpsPullRequestNotFoundException();
            }
Exemple #18
0
            public void Should_Throw_If_Null_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 11)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                result.IsAzureDevOpsException();
            }
Exemple #19
0
            public void Should_Return_Null_If_Null_Is_Returned_From_Git_Client()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var thread = pullRequest.CreateComment("Foo");

                // Then
                thread.ShouldBeNull();
            }
Exemple #20
0
            public void Should_Not_Throw_If_Null_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                // ?? Nothing to validate here since the method returns void
            }
Exemple #21
0
            public void Should_Not_Fail_If_Empty_List_Is_Returned()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 33)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                threads.ShouldNotBeNull();
                threads.ShouldBeEmpty();
            }
Exemple #22
0
            public void Should_Set_Valid_Status_On_AzureDevOps_Pull_Request()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 16);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new AzureDevOpsPullRequestStatus("Hello")
                {
                    State = AzureDevOpsPullRequestStatusState.Succeeded
                };

                // When
                pullRequest.SetStatus(status);

                // Then
                // ?? Nothing to validate here since the method returns void
            }
Exemple #23
0
            public void Should_Return_Valid_Comment_Threads()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 44);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

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

                AzureDevOpsPullRequestCommentThread thread1 = threads.First();

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

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

                AzureDevOpsComment comment11 = thread1.Comments.First();

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

                AzureDevOpsComment comment12 = thread1.Comments.Last();

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

                AzureDevOpsPullRequestCommentThread thread2 = threads.Last();

                thread2.Id.ShouldBe(22);
                thread2.Status.ShouldBe(AzureDevOpsCommentThreadStatus.Fixed);
                thread2.FilePath.ShouldBeNull();
                thread2.Comments.ShouldNotBeNull();
                thread2.Comments.ShouldBeEmpty();
            }
Exemple #24
0
            public void Should_Return_Empty_Collection_If_No_Changes_Found()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 42)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory()
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                files.ShouldBeOfType <List <FilePath> >();
                files.ShouldNotBeNull();
                files.ShouldBeEmpty();
            }
Exemple #25
0
            public void Should_Create_Valid_Comment_Thread()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsUrl, 200);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var inThread    = new AzureDevOpsPullRequestCommentThread {
                    Id = 300, Status = AzureDevOpsCommentThreadStatus.Pending, FilePath = "/index.html"
                };

                // When
                var outThread = pullRequest.CreateCommentThread(inThread);

                // Then
                outThread.Id.ShouldBe(inThread.Id);
                outThread.Status.ShouldBe(inThread.Status);
                outThread.FilePath.ShouldBeEquivalentTo(inThread.FilePath);
            }
Exemple #26
0
            public void Should_Throw_If_Null_Is_Returned_On_AzureDevOps_Pull_Request()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 23)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

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

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("Vote");
                result.IsAzureDevOpsPullRequestNotFoundException();
            }
Exemple #27
0
            public void Should_Return_Null_If_Pull_Request_Is_Invalid()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 100)
                {
                    GitClientFactory = new FakeNullGitClientFactory(),
                };

                fixture.Settings.ThrowExceptionIfPullRequestCouldNotBeFound = false;

                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);

                // When
                var outThread = pullRequest.CreateCommentThread(new AzureDevOpsPullRequestCommentThread());

                // Then
                outThread.ShouldBeNull();
            }
Exemple #28
0
            public void Should_Throw_If_AzureDevOps_Pull_Request_State_Is_Invalid()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 16);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new AzureDevOpsPullRequestStatus("whatever")
                {
                    State = (AzureDevOpsPullRequestStatusState)123
                };

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

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("SetStatus");
                result.Message.ShouldBe("Unknown value");
            }
Exemple #29
0
            public void Should_Return_Valid_Collection_Of_Modified_Files()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 42);
                var pullRequest = new AzureDevOpsPullRequest(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");
            }
Exemple #30
0
            public void Should_Throw_If_Null_Is_Returned_On_AzureDevOps_Pull_Request()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 16)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new AzureDevOpsPullRequestStatus("One")
                {
                    State = AzureDevOpsPullRequestStatusState.Failed
                };

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

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("SetStatus");
                result.IsAzureDevOpsPullRequestNotFoundException();
            }