Example #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):"));
            }
Example #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");
            }
Example #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.");
            }
Example #4
0
            public void Should_Initialize_Pull_Request_System()
            {
                // Given
                var fixture = new PrcaFixture();

                // When
                fixture.RunOrchestrator();

                // Then
                fixture.PullRequestSystem.PrcaSettings.ShouldBe(fixture.Settings);
            }
            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);
            }
Example #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");
            }
Example #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");
            }
Example #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);
            }
            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);
            }
            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");
            }
Example #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");
            }
Example #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);
            }
Example #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");
            }
Example #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");
            }
Example #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");
            }
Example #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");
            }
Example #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");
            }
Example #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");
            }
            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");
            }
Example #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):"));
            }
Example #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):"));
            }
Example #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}");
            }
Example #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);
            }
Example #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.");
            }
            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);
            }
            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);
            }