Пример #1
0
            public void Should_Ignore_Issues_Already_Present_Not_Related_To_A_File()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        null,
                        null,
                        "Foo",
                        0,
                        "Foo",
                        "Foo"),
                    new CodeAnalysisIssue(
                        null,
                        null,
                        "Bar",
                        0,
                        "Bar",
                        "Bar")
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>
                {
                    new PrcaDiscussionThread(
                        1,
                        PrcaDiscussionStatus.Active,
                        null,
                        new List <IPrcaDiscussionComment>
                    {
                        new PrcaDiscussionComment()
                        {
                            Content   = "Foo",
                            IsDeleted = false
                        }
                    })
                    {
                        CommentSource = fixture.ReportIssuesToPullRequestSettings.CommentSource,
                    }
                },
                        new List <FilePath>
                {
                    new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs")
                });

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered because they were already present");
                fixture.Log.Entries.ShouldContain(x => x.Message.StartsWith("Posting 1 issue(s):"));
            }
Пример #2
0
            public void Should_Throw_If_Modified_Files_Contain_Absolute_Path()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>
                {
                    new FilePath(@"c:\FakeCodeAnalysisProvider.cs")
                });

                // When
                var result = Record.Exception(() =>
                                              fixture.FilterIssues(
                                                  new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo")
                },
                                                  new Dictionary <ICodeAnalysisIssue, IEnumerable <IPrcaDiscussionComment> >()));

                // Then
                result.IsPrcaException(@"Absolute file paths are not suported for modified files. Path: c:/FakeCodeAnalysisProvider.cs");
            }
Пример #3
0
            public void Should_Resolve_Closed_Issues()
            {
                // Given
                var threadToResolve =
                    new PrcaDiscussionThread(
                        1,
                        PrcaDiscussionStatus.Active,
                        new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs"),
                        new List <IPrcaDiscussionComment>
                {
                    new PrcaDiscussionComment()
                    {
                        Content   = "Bar",
                        IsDeleted = false
                    }
                })
                {
                    CommentSource = null
                };

                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo")
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>
                {
                    threadToResolve
                },
                        new List <FilePath>
                {
                    new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs")
                });

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.PullRequestSystem.ThreadsMarkedAsFixed.ShouldContain(threadToResolve);
                fixture.Log.Entries.ShouldContain(x => x.Message == "Found 1 existing thread(s) that do not match any new issue and can be resolved.");
            }
Пример #4
0
            public void Should_Initialize_Pull_Request_System()
            {
                // Given
                var fixture = new PrcaFixture();

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.PullRequestSystem.PrcaSettings.ShouldBe(fixture.Settings);
            }
Пример #5
0
            public void Should_Initialize_Code_Analysis_Provider()
            {
                // Given
                var fixture = new PrcaFixture();

                // When
                fixture.ReadIssues(PrcaCommentFormat.Undefined);

                // Then
                fixture.CodeAnalysisProviders.ShouldAllBe(x => x.PrcaSettings == fixture.Settings);
            }
Пример #6
0
            public void Should_Throw_If_Issues_Are_Null()
            {
                // Given
                var fixture = new PrcaFixture();

                // When
                var result = Record.Exception(() => fixture.FilterIssues(null, new Dictionary <ICodeAnalysisIssue, IEnumerable <IPrcaDiscussionComment> >()));

                // Then
                result.IsArgumentNullException("issues");
            }
Пример #7
0
            public void Should_Throw_If_Issue_Comments_Are_Null()
            {
                // Given
                var fixture = new PrcaFixture();

                // When
                var result = Record.Exception(() => fixture.FilterIssues(new List <ICodeAnalysisIssue>(), null));

                // Then
                result.IsArgumentNullException("issueComments");
            }
Пример #8
0
            public void Should_Return_Reported_Issues_If_PullRequestSystem_Could_Not_Be_Initialized()
            {
                // Given
                var firstIssue =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");
                var secondIssue =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    firstIssue, secondIssue
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>
                {
                    new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs")
                })
                {
                    ShouldFailOnInitialization = true
                };

                fixture.ReportIssuesToPullRequestSettings.MaxIssuesToPost = 1;

                // When
                var result = fixture.RunOrchestrator();

                // Then
                result.ReportedIssues.Count().ShouldBe(2);
                result.ReportedIssues.ShouldContain(firstIssue);
                result.ReportedIssues.ShouldContain(secondIssue);
                result.PostedIssues.Count().ShouldBe(0);
            }
Пример #9
0
            public void Should_Initialize_All_Code_Analysis_Provider()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo"),
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        12,
                        "Bar",
                        0,
                        "Bar",
                        "Bar")
                }));
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\Foo.cs",
                        5,
                        "Foo",
                        0,
                        "Foo",
                        "Foo"),
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\Bar.cs",
                        7,
                        "Bar",
                        0,
                        "Bar",
                        "Bar")
                }));

                // When
                fixture.ReadIssues(PrcaCommentFormat.Undefined);

                // Then
                fixture.CodeAnalysisProviders.ShouldAllBe(x => x.PrcaSettings == fixture.Settings);
            }
Пример #10
0
            public void Should_Throw_If_Code_Analysis_Provider_List_Is_Empty()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();

                // When
                var result = Record.Exception(() => fixture.ReadIssues(PrcaCommentFormat.Undefined));

                // Then
                result.IsArgumentException("issueProviders");
            }
Пример #11
0
            public void Should_Throw_If_Code_Analysis_Provider_List_Is_Empty()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();

                // When
                var result = Record.Exception(() => fixture.RunOrchestrator());

                // Then
                result.IsArgumentException("codeAnalysisProviders");
            }
Пример #12
0
            public void Should_Return_Correct_Values()
            {
                // Given
                var reportedIssue =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");
                var postedIssue =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    postedIssue, reportedIssue
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>
                {
                    new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs")
                });

                fixture.ReportIssuesToPullRequestSettings.MaxIssuesToPost = 1;

                // When
                var result = fixture.RunOrchestrator();

                // Then
                result.ReportedIssues.Count().ShouldBe(2);
                result.ReportedIssues.ShouldContain(reportedIssue);
                result.ReportedIssues.ShouldContain(postedIssue);
                result.PostedIssues.Count().ShouldBe(1);
                result.PostedIssues.ShouldContain(postedIssue);
            }
Пример #13
0
            public void Should_Throw_If_Code_Analysis_Provider_List_Is_Null()
            {
                // Given
                var fixture = new PrcaFixture
                {
                    CodeAnalysisProviders = null
                };

                // When
                var result = Record.Exception(() => fixture.RunOrchestrator());

                // Then
                result.IsArgumentNullException("codeAnalysisProviders");
            }
Пример #14
0
            public void Should_Throw_If_Log_Is_Null()
            {
                // Given
                var fixture = new PrcaFixture
                {
                    Log = null
                };

                // When
                var result = Record.Exception(() => fixture.RunOrchestrator());

                // Then
                result.IsArgumentNullException("log");
            }
Пример #15
0
            public void Should_Throw_If_Settings_Are_Null()
            {
                // Given
                var fixture = new PrcaFixture
                {
                    Settings = null
                };

                // When
                var result = Record.Exception(() => fixture.RunOrchestrator());

                // Then
                result.IsArgumentNullException("settings");
            }
Пример #16
0
            public void Should_Throw_If_Settings_Are_Null()
            {
                // Given
                var fixture = new PrcaFixture
                {
                    Settings = null
                };

                // When
                var result = Record.Exception(() => fixture.FilterIssues(null, null));

                // Then
                result.IsArgumentNullException("settings");
            }
Пример #17
0
            public void Should_Throw_If_Log_Is_Null()
            {
                // Given
                var fixture = new PrcaFixture
                {
                    Log = null
                };

                // When
                var result = Record.Exception(() => fixture.FilterIssues(null, null));

                // Then
                result.IsArgumentNullException("log");
            }
Пример #18
0
            public void Should_Throw_If_Pull_Request_System_Is_Null()
            {
                // Given
                var fixture = new PrcaFixture
                {
                    PullRequestSystem = null
                };

                // When
                var result = Record.Exception(() => fixture.FilterIssues(null, null));

                // Then
                result.IsArgumentNullException("pullRequestSystem");
            }
Пример #19
0
            public void Should_Throw_If_Settings_Are_Null()
            {
                // Given
                var fixture = new PrcaFixture
                {
                    Settings = null
                };

                // When
                var result = Record.Exception(() => fixture.ReadIssues(PrcaCommentFormat.Undefined));

                // Then
                result.IsArgumentNullException("settings");
            }
Пример #20
0
            public void Should_Limit_Messages_To_Maximum()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo"),
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        12,
                        "Bar",
                        0,
                        "Bar",
                        "Bar")
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>
                {
                    new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs")
                });

                fixture.ReportIssuesToPullRequestSettings.MaxIssuesToPost = 1;

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered to match the maximum 1 comments limit");
                fixture.Log.Entries.ShouldContain(x => x.Message.StartsWith("Posting 1 issue(s):"));
            }
Пример #21
0
            public void Should_Ignore_Issues_If_File_Is_Not_Modified()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo"),
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\NotModified.cs",
                        12,
                        "Bar",
                        0,
                        "Bar",
                        "Bar")
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>
                {
                    new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs")
                });

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.Log.Entries.ShouldContain(x => x.Message == "1 issue(s) were filtered because they do not belong to files that were changed in this pull request");
                fixture.Log.Entries.ShouldContain(x => x.Message.StartsWith("Posting 1 issue(s):"));
            }
Пример #22
0
            public void Should_Post_Issue_Not_Related_To_A_File()
            {
                // Given
                var issueToPost =
                    new CodeAnalysisIssue(
                        null,
                        null,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");

                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    issueToPost
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>
                {
                    new FilePath(@"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs")
                });

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.PullRequestSystem.PostedIssues.ShouldContain(issueToPost);
                fixture.Log.Entries.ShouldContain(
                    x =>
                    x.Message ==
                    $"Posting 1 issue(s):\n  Rule: {issueToPost.Rule} Line: {issueToPost.Line} File: {issueToPost.AffectedFileRelativePath}");
            }
Пример #23
0
            public void Should_Use_The_Correct_Comment_Format(PrcaCommentFormat format)
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>())
                {
                    CommentFormat = format
                };

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.CodeAnalysisProviders.ShouldAllBe(x => x.Format == format);
            }
Пример #24
0
            public void Should_Log_Message_If_All_Issues_Are_Filtered()
            {
                // Given
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo"),
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\NotModified.cs",
                        12,
                        "Bar",
                        0,
                        "Bar",
                        "Bar")
                }));

                fixture.PullRequestSystem =
                    new FakePullRequestSystem(
                        fixture.Log,
                        new List <IPrcaDiscussionThread>(),
                        new List <FilePath>());

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.Log.Entries.ShouldContain(x => x.Message == "All issues were filtered. Nothing new to post.");
            }
Пример #25
0
            public void Should_Read_Correct_Number_Of_Code_Analysis_Issues_Not_Related_To_A_File()
            {
                // Given
                var issue1 =
                    new CodeAnalysisIssue(
                        null,
                        null,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");
                var issue2 =
                    new CodeAnalysisIssue(
                        null,
                        null,
                        "Bar",
                        0,
                        "Bar",
                        "Bar");
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    issue1,
                    issue2
                }));

                // When
                var issues = fixture.ReadIssues(PrcaCommentFormat.Undefined).ToList();

                // Then
                issues.Count.ShouldBe(2);
                issues.ShouldContain(issue1);
                issues.ShouldContain(issue2);
            }
Пример #26
0
            public void Should_Read_Correct_Number_Of_Code_Analysis_Issues_From_Multiple_Providers()
            {
                // Given
                var issue1 =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        10,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");
                var issue2 =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\FakeCodeAnalysisProvider.cs",
                        12,
                        "Bar",
                        0,
                        "Bar",
                        "Bar");
                var issue3 =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\Foo.cs",
                        5,
                        "Foo",
                        0,
                        "Foo",
                        "Foo");
                var issue4 =
                    new CodeAnalysisIssue(
                        @"src\Cake.Prca.Tests\Bar.cs",
                        7,
                        "Bar",
                        0,
                        "Bar",
                        "Bar");
                var fixture = new PrcaFixture();

                fixture.CodeAnalysisProviders.Clear();
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    issue1,
                    issue2
                }));
                fixture.CodeAnalysisProviders.Add(
                    new FakeCodeAnalysisProvider(
                        fixture.Log,
                        new List <ICodeAnalysisIssue>
                {
                    issue3,
                    issue4
                }));

                // When
                var issues = fixture.ReadIssues(PrcaCommentFormat.Undefined).ToList();

                // Then
                issues.Count.ShouldBe(4);
                issues.ShouldContain(issue1);
                issues.ShouldContain(issue2);
                issues.ShouldContain(issue3);
                issues.ShouldContain(issue4);
            }