Exemple #1
0
            public void Should_Set_Properly()
            {
                // Given
                var thread = new GitPullRequestCommentThread
                {
                    Id     = 15,
                    Status = CommentThreadStatus.Active,
                };

                // When
                var tfsThread = new TfsPullRequestCommentThread(thread)
                {
                    Comments = new List <TfsComment> {
                        new TfsComment("hi", false, CommentType.Text)
                    },
                };

                // Then
                tfsThread.Comments.ShouldNotBeNull();
                tfsThread.Comments.ShouldHaveSingleItem();
                tfsThread.Comments.First().ShouldNotBeNull();
                tfsThread.Comments.First().ShouldBeOfType <TfsComment>();
                tfsThread.Comments.First().Content.ShouldBe("hi");
                tfsThread.Comments.First().CommentType.ShouldBe(TfsCommentType.Text);
                tfsThread.Comments.First().IsDeleted.ShouldBeFalse();
            }
Exemple #2
0
            public void Should_Get_Valid_Properties()
            {
                // Given
                var tfsThread = new TfsPullRequestCommentThread(
                    new GitPullRequestCommentThread
                {
                    Id         = 42,
                    Status     = CommentThreadStatus.Active,
                    Properties = new PropertiesCollection {
                        { "one", "way" }, { "two", 2 }
                    },
                });

                // When
                var prop1 = tfsThread.GetValue <string>("one");
                var prop2 = tfsThread.GetValue <int>("two");
                var prop3 = tfsThread.GetValue <object>("ghost");

                // Then
                prop1.ShouldNotBeNull();
                prop1.ShouldBeOfType <string>();
                prop1.ShouldNotBeEmpty();
                prop1.ShouldBe("way");

                prop2.ShouldNotBeNull();
                prop2.ShouldBeOfType <int>();
                prop2.ShouldBe(2);

                prop3.ShouldBeNull();
            }
Exemple #3
0
            public void Should_Throw_If_Property_Name_Is_Empty()
            {
                // Given
                var tfsThread = new TfsPullRequestCommentThread();

                // When
                var result = Record.Exception(() => tfsThread.SetValue(string.Empty, new object()));

                // Then
                result.IsArgumentOutOfRangeException("propertyName");
            }
Exemple #4
0
            public void Should_Throw_If_Property_Name_Is_Null()
            {
                // Given
                var tfsThread = new TfsPullRequestCommentThread();

                // When
                var result = Record.Exception(() => tfsThread.SetValue(null, string.Empty));

                // Then
                result.IsArgumentNullException("propertyName");
            }
Exemple #5
0
            public void Should_Return_Default_Value_If_Property_Collection_Is_Null_For_Integer_Value()
            {
                // Given
                var tfsThread = new TfsPullRequestCommentThread();

                // When
                var result = tfsThread.GetValue <int>("key");

                // Then
                result.ShouldBe(default(int));
            }
Exemple #6
0
            public void Should_Throw_If_Property_Collection_Is_Null()
            {
                // Given
                var tfsThread = new TfsPullRequestCommentThread();

                // When
                var result = Record.Exception(() => tfsThread.SetValue("key", 1));

                // Then
                result.IsInvalidOperationException();
            }
Exemple #7
0
            public void Should_Return_Null_If_Not_Set()
            {
                // Given
                var thread = new GitPullRequestCommentThread
                {
                    Id     = 16,
                    Status = CommentThreadStatus.Active,
                };

                // When
                var tfsThread = new TfsPullRequestCommentThread(thread);

                // Then
                tfsThread.Properties.ShouldBeNull();
            }
Exemple #8
0
            public void Should_Throw_If_Not_Set()
            {
                // Given
                var thread = new GitPullRequestCommentThread
                {
                    Id     = 15,
                    Status = CommentThreadStatus.Active,
                };

                // When
                var tfsThread = new TfsPullRequestCommentThread(thread);
                var result    = Record.Exception(() => tfsThread.Comments);

                // Then
                result.IsInvalidOperationException();
            }
Exemple #9
0
            public void Should_Return_Empty_Comment_Thread()
            {
                // Given, When
                var thread            = new TfsPullRequestCommentThread();
                var getCommentsResult = Record.Exception(() => thread.Comments);

                // Then
                thread.ShouldNotBeNull();
                thread.InnerThread.ShouldBeOfType(typeof(GitPullRequestCommentThread));
                thread.Id.ShouldBe(default(int));
                thread.FilePath.ShouldBeNull();
                thread.Status.ShouldBe(default(TfsCommentThreadStatus));
                thread.Properties.ShouldBeNull();

                getCommentsResult.IsInvalidOperationException();
            }
Exemple #10
0
            public void Should_Return_Null_If_Not_Initialized()
            {
                // Given
                var thread = new GitPullRequestCommentThread
                {
                    Id     = 16,
                    Status = CommentThreadStatus.Active,
                };

                // When
                var tfsThread = new TfsPullRequestCommentThread(thread);
                var filePath  = tfsThread.FilePath;

                // Then
                filePath.ShouldBeNull();
            }
            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();
            }
Exemple #12
0
            public void Should_Return_Default_Value_If_Property_Does_Not_Exist_For_Int_Value()
            {
                // Given
                var tfsThread = new TfsPullRequestCommentThread(
                    new GitPullRequestCommentThread
                {
                    Id         = 42,
                    Status     = CommentThreadStatus.Active,
                    Properties = new PropertiesCollection(),
                });

                // When
                var result = tfsThread.GetValue <int>("key");

                // Then
                result.ShouldBe(default(int));
            }
Exemple #13
0
        /// <summary>
        /// Creates a new comment thread in the pull request.
        /// </summary>
        /// <param name="thread">The instance of the thread.</param>
        public void CreateCommentThread(TfsPullRequestCommentThread thread)
        {
            if (!this.ValidatePullRequest())
            {
                return;
            }

            using (var gitClient = this.gitClientFactory.CreateGitClient(this.CollectionUrl, this.credentials))
            {
                gitClient.CreateThreadAsync(
                    thread.InnerThread,
                    this.RepositoryId,
                    this.PullRequestId,
                    null,
                    CancellationToken.None).Wait();
            }
        }
Exemple #14
0
            public void Should_Set_And_Trimmed_Properly()
            {
                // Given
                var thread = new GitPullRequestCommentThread
                {
                    Id     = 100,
                    Status = CommentThreadStatus.Active,
                };

                // When
                var tfsThread = new TfsPullRequestCommentThread(thread)
                {
                    FilePath = "/path/to/myclass.cs",
                };

                // Then
                tfsThread.FilePath.ShouldNotBeNull();
                tfsThread.FilePath.FullPath.ShouldBe("path/to/myclass.cs");
            }
Exemple #15
0
            public void Should_Set_Empty_Collection()
            {
                // Given
                var thread = new GitPullRequestCommentThread
                {
                    Id     = 16,
                    Status = CommentThreadStatus.Active,
                };

                // When
                var tfsThread = new TfsPullRequestCommentThread(thread)
                {
                    Properties = new Dictionary <string, object>(),
                };

                // Then
                tfsThread.Properties.ShouldNotBeNull();
                tfsThread.Properties.ShouldBeOfType <PropertiesCollection>();
                tfsThread.Properties.ShouldBeEmpty();
            }
Exemple #16
0
            public void Should_Return_Valid_Comment_Thread()
            {
                // Given
                var gitCommentThread = new GitPullRequestCommentThread
                {
                    Id            = 42,
                    Status        = CommentThreadStatus.Pending,
                    ThreadContext = new CommentThreadContext {
                        FilePath = "/src/myclass.cs"
                    },
                    Comments = new List <Comment> {
                        new Comment {
                            Content = "Hello", CommentType = CommentType.Text, IsDeleted = false
                        }
                    },
                    Properties = new PropertiesCollection(),
                };

                // When
                var tfsCommentThread = new TfsPullRequestCommentThread(gitCommentThread);

                // Then
                tfsCommentThread.ShouldNotBeNull();
                tfsCommentThread.Id.ShouldBe(42);
                tfsCommentThread.Status.ShouldBe(TfsCommentThreadStatus.Pending);
                tfsCommentThread.FilePath.ShouldNotBeNull();
                tfsCommentThread.FilePath.FullPath.ShouldBe("src/myclass.cs");

                tfsCommentThread.Comments.ShouldNotBeNull();
                tfsCommentThread.Comments.ShouldNotBeEmpty();
                tfsCommentThread.Comments.ShouldHaveSingleItem();
                tfsCommentThread.Comments.First().ShouldNotBeNull();
                tfsCommentThread.Comments.First().Content.ShouldBe("Hello");
                tfsCommentThread.Comments.First().CommentType.ShouldBe(TfsCommentType.Text);
                tfsCommentThread.Comments.First().IsDeleted.ShouldBeFalse();

                tfsCommentThread.Properties.ShouldNotBeNull();
                tfsCommentThread.Properties.ShouldBeEmpty();
            }
Exemple #17
0
            public void Should_Set_Valid_Properties()
            {
                // Given
                var tfsThread = new TfsPullRequestCommentThread(
                    new GitPullRequestCommentThread
                {
                    Id         = 42,
                    Status     = CommentThreadStatus.Active,
                    Properties = new PropertiesCollection {
                        { "one", 1 }
                    },
                });

                // When
                tfsThread.SetValue("one", "string");
                tfsThread.SetValue("two", 2);

                // Then
                tfsThread.Properties.ShouldNotBeNull();
                tfsThread.Properties.ShouldNotBeEmpty();
                tfsThread.Properties.ShouldContainKeyAndValue("one", "string");
                tfsThread.Properties.ShouldContainKeyAndValue("two", 2);
            }
Exemple #18
0
            public void Should_Set_Colletion_With_Single_Element()
            {
                // Given
                var thread = new GitPullRequestCommentThread
                {
                    Id         = 16,
                    Status     = CommentThreadStatus.Active,
                    Properties = new PropertiesCollection(),
                };

                // When
                var tfsThread = new TfsPullRequestCommentThread(thread)
                {
                    Properties = { ["fake"] = "value" }
                };

                // Then
                tfsThread.Properties.ShouldNotBeNull();
                tfsThread.Properties.ShouldNotBeEmpty();
                tfsThread.Properties.ShouldHaveSingleItem();

                tfsThread.Properties["fake"].ShouldNotBeNull();
                tfsThread.Properties["fake"].ShouldBe("value");
            }