From f33519907a6791f5980901abf120c063def6de6e Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sun, 15 Oct 2017 21:59:49 +0200 Subject: [PATCH] (GH-5) Add project to issue --- src/Cake.Issues.Tests/IssueOfTTests.cs | 51 +++++++++++++++++++++++ src/Cake.Issues.Tests/IssueTests.cs | 41 +++++++++++++++++++ src/Cake.Issues/IIssue.cs | 5 +++ src/Cake.Issues/Issue.cs | 56 ++++++++++++++++++++++++++ src/Cake.Issues/Issue{T}.cs | 48 ++++++++++++++++++++++ 5 files changed, 201 insertions(+) diff --git a/src/Cake.Issues.Tests/IssueOfTTests.cs b/src/Cake.Issues.Tests/IssueOfTTests.cs index 944774887..f09d40743 100644 --- a/src/Cake.Issues.Tests/IssueOfTTests.cs +++ b/src/Cake.Issues.Tests/IssueOfTTests.cs @@ -121,6 +121,57 @@ public void Should_Throw_If_Rule_Is_Null() result.IsArgumentNullException("rule"); } + [Fact] + public void Should_Throw_If_Provider_Type_Is_WhiteSpace() + { + // Given / When + var result = Record.Exception(() => new Issue(@"src\foo.cs", 100, "foo", 1, "foo", " ")); + + // Then + result.IsArgumentOutOfRangeException("providerType"); + } + + [Fact] + public void Should_Handle_Projects_Which_Are_Null() + { + // Given / When + var issue = new Issue(null, @"src\foo.cs", null, "Foo", 1, "Bar"); + + // Then + issue.Project.ShouldBe(null); + } + + [Fact] + public void Should_Handle_Projects_Which_Are_WhiteSpace() + { + // Given / When + var issue = new Issue(" ", @"src\foo.cs", null, "Foo", 1, "Bar"); + + // Then + issue.Project.ShouldBe(" "); + } + + [Fact] + public void Should_Handle_Projects_Which_Are_Empty() + { + // Given / When + var issue = new Issue(string.Empty, @"src\foo.cs", null, "Foo", 1, "Bar"); + + // Then + issue.Project.ShouldBe(string.Empty); + } + + [Theory] + [InlineData("project")] + public void Should_Set_Project(string project) + { + // Given / When + var issue = new Issue(project, @"src\foo.cs", null, "Foo", 1, "Bar"); + + // Then + issue.Project.ShouldBe(project); + } + [Fact] public void Should_Handle_File_Paths_Which_Are_Null() { diff --git a/src/Cake.Issues.Tests/IssueTests.cs b/src/Cake.Issues.Tests/IssueTests.cs index d670aadf1..0826937b2 100644 --- a/src/Cake.Issues.Tests/IssueTests.cs +++ b/src/Cake.Issues.Tests/IssueTests.cs @@ -133,6 +133,47 @@ public void Should_Throw_If_Provider_Type_Is_WhiteSpace() result.IsArgumentOutOfRangeException("providerType"); } + [Fact] + public void Should_Handle_Projects_Which_Are_Null() + { + // Given / When + var issue = new Issue(null, @"src\foo.cs", null, "Foo", 1, "Bar", "foo"); + + // Then + issue.Project.ShouldBe(null); + } + + [Fact] + public void Should_Handle_Projects_Which_Are_WhiteSpace() + { + // Given / When + var issue = new Issue(" ", @"src\foo.cs", null, "Foo", 1, "Bar", "foo"); + + // Then + issue.Project.ShouldBe(" "); + } + + [Fact] + public void Should_Handle_Projects_Which_Are_Empty() + { + // Given / When + var issue = new Issue(string.Empty, @"src\foo.cs", null, "Foo", 1, "Bar", "foo"); + + // Then + issue.Project.ShouldBe(string.Empty); + } + + [Theory] + [InlineData("project")] + public void Should_Set_Project(string project) + { + // Given / When + var issue = new Issue(project, @"src\foo.cs", null, "Foo", 1, "Bar", "foo"); + + // Then + issue.Project.ShouldBe(project); + } + [Fact] public void Should_Handle_File_Paths_Which_Are_Null() { diff --git a/src/Cake.Issues/IIssue.cs b/src/Cake.Issues/IIssue.cs index d10e1d8b6..af60e083c 100644 --- a/src/Cake.Issues/IIssue.cs +++ b/src/Cake.Issues/IIssue.cs @@ -8,6 +8,11 @@ /// public interface IIssue { + /// + /// Gets the name of the project to which the file affected by the issue belongs. + /// + string Project { get; } + /// /// Gets the path to the file affacted by the issue. /// The path is relative to the repository root. diff --git a/src/Cake.Issues/Issue.cs b/src/Cake.Issues/Issue.cs index f49f45d0f..b55b9d035 100644 --- a/src/Cake.Issues/Issue.cs +++ b/src/Cake.Issues/Issue.cs @@ -52,6 +52,58 @@ public Issue( string rule, Uri ruleUrl, string providerType) + : this(null, filePath, line, message, priority, rule, ruleUrl, providerType) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Name of the project to which the file affected by the issue belongs + /// The path to the file affacted by the issue. + /// The path needs to be relative to the repository root. + /// null or if issue is not related to a change in a file. + /// The line in the file where the issues has occurred. + /// Nothing if the issue affects the whole file or an asssembly. + /// The message of the issue. + /// The priority of the message. + /// The rule of the issue. + /// The type of the issue provider. + public Issue( + string project, + string filePath, + int? line, + string message, + int priority, + string rule, + string providerType) + : this(project, filePath, line, message, priority, rule, null, providerType) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Name of the project to which the file affected by the issue belongs + /// The path to the file affacted by the issue. + /// The path needs to be relative to the repository root. + /// null or if issue is not related to a change in a file. + /// The line in the file where the issues has occurred. + /// Nothing if the issue affects the whole file or an asssembly. + /// The message of the issue. + /// The priority of the message. + /// The rule of the issue. + /// The URL containing information about the failing rule. + /// The type of the issue provider. + public Issue( + string project, + string filePath, + int? line, + string message, + int priority, + string rule, + Uri ruleUrl, + string providerType) { line?.NotNegativeOrZero(nameof(line)); message.NotNullOrWhiteSpace(nameof(message)); @@ -79,6 +131,7 @@ public Issue( throw new ArgumentOutOfRangeException(nameof(line), "Cannot specify a line while not specifying a file."); } + this.Project = project; this.Line = line; this.Message = message; this.Priority = priority; @@ -87,6 +140,9 @@ public Issue( this.ProviderType = providerType; } + /// + public string Project { get; } + /// public FilePath AffectedFileRelativePath { get; } diff --git a/src/Cake.Issues/Issue{T}.cs b/src/Cake.Issues/Issue{T}.cs index d976aef8e..d40282236 100644 --- a/src/Cake.Issues/Issue{T}.cs +++ b/src/Cake.Issues/Issue{T}.cs @@ -53,6 +53,54 @@ public Issue( { } + /// + /// Initializes a new instance of the class. + /// + /// Name of the project to which the file affected by the issue belongs + /// The path to the file affacted by the issue. + /// The path needs to be relative to the repository root. + /// null or if issue is not related to a change in a file. + /// The line in the file where the issues has occurred. + /// Nothing if the issue affects the whole file or an asssembly. + /// The message of the issue. + /// The priority of the message. + /// The rule of the issue. + public Issue( + string project, + string filePath, + int? line, + string message, + int priority, + string rule) + : base(project, filePath, line, message, priority, rule, null, GetProviderTypeName()) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Name of the project to which the file affected by the issue belongs + /// The path to the file affacted by the issue. + /// The path needs to be relative to the repository root. + /// null or if issue is not related to a change in a file. + /// The line in the file where the issues has occurred. + /// Nothing if the issue affects the whole file or an asssembly. + /// The message of the issue. + /// The priority of the message. + /// The rule of the issue. + /// The URL containing information about the failing rule. + public Issue( + string project, + string filePath, + int? line, + string message, + int priority, + string rule, + Uri ruleUrl) + : base(project, filePath, line, message, priority, rule, ruleUrl, GetProviderTypeName()) + { + } + /// /// Gets the name of the issue provider as it will be set to in the property. ///