diff --git a/nuspec/nuget/Cake.Issues.Testing.nuspec b/nuspec/nuget/Cake.Issues.Testing.nuspec
index 7e2d46a55..afd01b326 100644
--- a/nuspec/nuget/Cake.Issues.Testing.nuspec
+++ b/nuspec/nuget/Cake.Issues.Testing.nuspec
@@ -16,7 +16,7 @@ Common helpers for testing add-ins based on Cake.Issues
false
Copyright © BBT Software AG and contributors
Cake Script Cake-Issues Issues Testing
- https://github.com/cake-contrib/Cake.Issues/releases/tag/0.2.0
+ https://github.com/cake-contrib/Cake.Issues/releases/tag/0.3.0
diff --git a/nuspec/nuget/Cake.Issues.nuspec b/nuspec/nuget/Cake.Issues.nuspec
index 505d2d2f2..774e29fe6 100644
--- a/nuspec/nuget/Cake.Issues.nuspec
+++ b/nuspec/nuget/Cake.Issues.nuspec
@@ -23,7 +23,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
false
Copyright © BBT Software AG and contributors
Cake Script Cake-Issues CodeAnalysis Linting Issues
- https://github.com/cake-contrib/Cake.Issues/releases/tag/0.2.0
+ https://github.com/cake-contrib/Cake.Issues/releases/tag/0.3.0
diff --git a/src/Cake.Issues.Testing/Cake.Issues.Testing.csproj b/src/Cake.Issues.Testing/Cake.Issues.Testing.csproj
index 267e309db..cee0186b1 100644
--- a/src/Cake.Issues.Testing/Cake.Issues.Testing.csproj
+++ b/src/Cake.Issues.Testing/Cake.Issues.Testing.csproj
@@ -24,7 +24,7 @@
-
+
diff --git a/src/Cake.Issues.Testing/FakeIssueProvider.cs b/src/Cake.Issues.Testing/FakeIssueProvider.cs
index 08ef70c3c..40d99d5f0 100644
--- a/src/Cake.Issues.Testing/FakeIssueProvider.cs
+++ b/src/Cake.Issues.Testing/FakeIssueProvider.cs
@@ -49,6 +49,9 @@ public FakeIssueProvider(ICakeLog log, IEnumerable issues)
///
public IssueCommentFormat Format { get; private set; }
+ ///
+ public override string ProviderName => "Fake Issue Provider";
+
///
protected override IEnumerable InternalReadIssues(IssueCommentFormat format)
{
diff --git a/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj b/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj
index 68c8829cd..aac2283a3 100644
--- a/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj
+++ b/src/Cake.Issues.Tests/Cake.Issues.Tests.csproj
@@ -15,9 +15,9 @@
-
-
-
+
+
+
diff --git a/src/Cake.Issues.Tests/IssueBuilderFixture.cs b/src/Cake.Issues.Tests/IssueBuilderFixture.cs
new file mode 100644
index 000000000..3b168ca30
--- /dev/null
+++ b/src/Cake.Issues.Tests/IssueBuilderFixture.cs
@@ -0,0 +1,12 @@
+namespace Cake.Issues.Tests
+{
+ public class IssueBuilderFixture
+ {
+ public IssueBuilderFixture()
+ {
+ this.IssueBuilder = IssueBuilder.NewIssue("Message", "ProviderType", "ProviderName");
+ }
+
+ public IssueBuilder IssueBuilder { get; private set; }
+ }
+}
diff --git a/src/Cake.Issues.Tests/IssueBuilderTests.cs b/src/Cake.Issues.Tests/IssueBuilderTests.cs
new file mode 100644
index 000000000..37e618b8b
--- /dev/null
+++ b/src/Cake.Issues.Tests/IssueBuilderTests.cs
@@ -0,0 +1,710 @@
+namespace Cake.Issues.Tests
+{
+ using System;
+ using Cake.Testing;
+ using Shouldly;
+ using Testing;
+ using Xunit;
+
+ public sealed class IssueBuilderTests
+ {
+ public sealed class TheNewIssueMethod
+ {
+ [Fact]
+ public void Should_Throw_If_Message_Is_Null()
+ {
+ // Given
+ string message = null;
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentNullException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Message_Is_Empty()
+ {
+ // Given
+ var message = string.Empty;
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Message_Is_WhiteSpace()
+ {
+ // Given
+ var message = " ";
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_ProviderType_Is_Null()
+ {
+ // Given
+ var message = "Message";
+ string providerType = null;
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentNullException("providerType");
+ }
+
+ [Fact]
+ public void Should_Throw_If_ProviderType_Is_Empty()
+ {
+ // Given
+ var message = "Message";
+ var providerType = string.Empty;
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerType");
+ }
+
+ [Fact]
+ public void Should_Throw_If_ProviderType_Is_WhiteSpace()
+ {
+ // Given
+ var message = "Message";
+ var providerType = " ";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerType");
+ }
+
+ [Fact]
+ public void Should_Throw_If_ProviderName_Is_Null()
+ {
+ // Given
+ var message = "Message";
+ var providerType = "ProviderType";
+ string providerName = null;
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentNullException("providerName");
+ }
+
+ [Fact]
+ public void Should_Throw_If_ProviderName_Is_Empty()
+ {
+ // Given
+ var message = "Message";
+ var providerType = "ProviderType";
+ var providerName = string.Empty;
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerName");
+ }
+
+ [Fact]
+ public void Should_Throw_If_ProviderName_Is_WhiteSpace()
+ {
+ // Given
+ var message = "Message";
+ var providerType = "ProviderType";
+ var providerName = " ";
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, providerType, providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerName");
+ }
+ }
+
+ public sealed class TheNewIssueOfTMethod
+ {
+ [Fact]
+ public void Should_Throw_If_Message_Is_Null()
+ {
+ // Given
+ string message = null;
+ var issueProvider = new FakeIssueProvider(new FakeLog());
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, issueProvider));
+
+ // Then
+ result.IsArgumentNullException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Message_Is_Empty()
+ {
+ // Given
+ var message = string.Empty;
+ var issueProvider = new FakeIssueProvider(new FakeLog());
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, issueProvider));
+
+ // Then
+ result.IsArgumentOutOfRangeException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Message_Is_WhiteSpace()
+ {
+ // Given
+ var message = " ";
+ var issueProvider = new FakeIssueProvider(new FakeLog());
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, issueProvider));
+
+ // Then
+ result.IsArgumentOutOfRangeException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_IssueProvider_Is_Null()
+ {
+ // Given
+ var message = "Message";
+ IIssueProvider issueProvider = null;
+
+ // When
+ var result = Record.Exception(() =>
+ IssueBuilder.NewIssue(message, issueProvider));
+
+ // Then
+ result.IsArgumentNullException("issueProvider");
+ }
+ }
+
+ public sealed class TheInProjectMethod
+ {
+ [Fact]
+ public void Should_Handle_Projects_Which_Are_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ string project = null;
+
+ // When
+ var issue = fixture.IssueBuilder.InProject(project).Create();
+
+ // Then
+ issue.Project.ShouldBe(project);
+ }
+
+ [Fact]
+ public void Should_Handle_Projects_Which_Are_Empty()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var project = string.Empty;
+
+ // When
+ var issue = fixture.IssueBuilder.InProject(project).Create();
+
+ // Then
+ issue.Project.ShouldBe(project);
+ }
+
+ [Fact]
+ public void Should_Handle_Projects_Which_Are_WhiteSpace()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var project = " ";
+
+ // When
+ var issue = fixture.IssueBuilder.InProject(project).Create();
+
+ // Then
+ issue.Project.ShouldBe(project);
+ }
+
+ [Theory]
+ [InlineData("project")]
+ public void Should_Set_Project(string project)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InProject(project).Create();
+
+ // Then
+ issue.Project.ShouldBe(project);
+ }
+ }
+
+ public sealed class TheInFileMethod
+ {
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(null).Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ShouldBe(null);
+ }
+
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_Empty()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(string.Empty).Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ShouldBe(null);
+ }
+
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_WhiteSpace()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(" ").Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ShouldBe(null);
+ }
+
+ [Theory]
+ [InlineData(@"foo", @"foo")]
+ [InlineData(@"foo\bar", @"foo/bar")]
+ [InlineData(@"foo/bar", @"foo/bar")]
+ [InlineData(@"foo\bar\", @"foo/bar")]
+ [InlineData(@"foo/bar/", @"foo/bar")]
+ [InlineData(@".\foo", @"foo")]
+ [InlineData(@"./foo", @"foo")]
+ [InlineData(@"foo\..\bar", @"foo/../bar")]
+ [InlineData(@"foo/../bar", @"foo/../bar")]
+ public void Should_Set_FilePath(string filePath, string expectedFilePath)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(filePath).Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ToString().ShouldBe(expectedFilePath);
+ issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "File path was not set as relative.");
+ }
+ }
+
+ public sealed class TheInFileLineMethod
+ {
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(null).Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ShouldBe(null);
+ }
+
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_Empty()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(string.Empty).Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ShouldBe(null);
+ }
+
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_WhiteSpace()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(" ").Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ShouldBe(null);
+ }
+
+ [Fact]
+ public void Should_Throw_If_Line_Is_Negative()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var result = Record.Exception(() =>
+ fixture.IssueBuilder.InFile("foo", -1));
+
+ // Then
+ result.IsArgumentOutOfRangeException("line");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Line_Is_Zero()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var result = Record.Exception(() =>
+ fixture.IssueBuilder.InFile("foo", 0));
+
+ // Then
+ result.IsArgumentOutOfRangeException("line");
+ }
+
+ [Fact]
+ public void Should_Handle_Line_Which_Is_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile("foo", null).Create();
+
+ // Then
+ issue.Line.ShouldBe(null);
+ }
+
+ [Theory]
+ [InlineData(@"foo", @"foo")]
+ [InlineData(@"foo\bar", @"foo/bar")]
+ [InlineData(@"foo/bar", @"foo/bar")]
+ [InlineData(@"foo\bar\", @"foo/bar")]
+ [InlineData(@"foo/bar/", @"foo/bar")]
+ [InlineData(@".\foo", @"foo")]
+ [InlineData(@"./foo", @"foo")]
+ [InlineData(@"foo\..\bar", @"foo/../bar")]
+ [InlineData(@"foo/../bar", @"foo/../bar")]
+ public void Should_Set_FilePath(string filePath, string expectedFilePath)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile(filePath, 10).Create();
+
+ // Then
+ issue.AffectedFileRelativePath.ToString().ShouldBe(expectedFilePath);
+ issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "File path was not set as relative.");
+ }
+
+ [Theory]
+ [InlineData(1)]
+ [InlineData(int.MaxValue)]
+ public void Should_Set_Line(int line)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.InFile("foo", line).Create();
+
+ // Then
+ issue.Line.ShouldBe(line);
+ }
+ }
+
+ public sealed class TheWithPriorityMethod
+ {
+ [Fact]
+ public void Should_Handle_PriorityNames_Which_Are_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ string priorityName = null;
+
+ // When
+ var issue = fixture.IssueBuilder.WithPriority(0, priorityName).Create();
+
+ // Then
+ issue.PriorityName.ShouldBe(priorityName);
+ }
+
+ [Fact]
+ public void Should_Handle_PriorityNames_Which_Are_Empty()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var priorityName = string.Empty;
+
+ // When
+ var issue = fixture.IssueBuilder.WithPriority(0, priorityName).Create();
+
+ // Then
+ issue.PriorityName.ShouldBe(priorityName);
+ }
+
+ [Fact]
+ public void Should_Handle_PriorityNames_Which_Are_WhiteSpace()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var priorityName = " ";
+
+ // When
+ var issue = fixture.IssueBuilder.WithPriority(0, priorityName).Create();
+
+ // Then
+ issue.PriorityName.ShouldBe(priorityName);
+ }
+
+ [Theory]
+ [InlineData(int.MinValue)]
+ [InlineData(-1)]
+ [InlineData(0)]
+ [InlineData(1)]
+ [InlineData(int.MaxValue)]
+ public void Should_Set_Priority(int priority)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.WithPriority(priority, "Foo").Create();
+
+ // Then
+ issue.Priority.ShouldBe(priority);
+ }
+
+ [Theory]
+ [InlineData("Warning")]
+ public void Should_Set_PriorityName(string priorityName)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.WithPriority(0, priorityName).Create();
+
+ // Then
+ issue.PriorityName.ShouldBe(priorityName);
+ }
+ }
+
+ public sealed class TheWithPriorityEnumMethod
+ {
+ [Theory]
+ [InlineData(IssuePriority.Hint, 100, "Hint")]
+ [InlineData(IssuePriority.Suggestion, 200, "Suggestion")]
+ [InlineData(IssuePriority.Warning, 300, "Warning")]
+ [InlineData(IssuePriority.Error, 400, "Error")]
+ public void Should_Set_Priority(IssuePriority issuePriority, int expectedPriority, string expectedPriorityName)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.WithPriority(issuePriority).Create();
+
+ // Then
+ issue.Priority.ShouldBe(expectedPriority);
+ issue.PriorityName.ShouldBe(expectedPriorityName);
+ }
+ }
+
+ public sealed class TheOfRuleMethod
+ {
+ [Fact]
+ public void Should_Handle_Rules_Which_Are_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ string rule = null;
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule).Create();
+
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
+
+ [Fact]
+ public void Should_Handle_Rules_Which_Are_Empty()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var rule = string.Empty;
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule).Create();
+
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
+
+ [Fact]
+ public void Should_Handle_Rules_Which_Are_WhiteSpace()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var rule = " ";
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule).Create();
+
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
+
+ [Theory]
+ [InlineData("rule")]
+ public void Should_Set_Rule(string rule)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule).Create();
+
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
+ }
+
+ public sealed class TheOfRuleWithUriMethod
+ {
+ [Fact]
+ public void Should_Handle_Names_Which_Are_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ string rule = null;
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule, new Uri("https://google.com")).Create();
+
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
+
+ [Fact]
+ public void Should_Handle_Name_Which_Are_Empty()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var rule = string.Empty;
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule, new Uri("https://google.com")).Create();
+
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
+
+ [Fact]
+ public void Should_Handle_Names_Which_Are_WhiteSpace()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var rule = " ";
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule, new Uri("https://google.com")).Create();
+
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
+
+ [Fact]
+ public void Should_Handle_Rule_Uri_Which_Are_Null()
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule("Rule", null).Create();
+
+ // Then
+ issue.RuleUrl.ShouldBe(null);
+ }
+
+ [Theory]
+ [InlineData("rule")]
+ public void Should_Set_Rule(string rule)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+ var ruleUri = "https://google.com/";
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule(rule, new Uri(ruleUri)).Create();
+
+ // Then
+ issue.RuleUrl.ToString().ShouldBe(ruleUri);
+ }
+
+ [Theory]
+ [InlineData("https://google.com/")]
+ public void Should_Set_RuleUrl(string ruleUri)
+ {
+ // Given
+ var fixture = new IssueBuilderFixture();
+
+ // When
+ var issue = fixture.IssueBuilder.OfRule("Rule", new Uri(ruleUri)).Create();
+
+ // Then
+ issue.RuleUrl.ToString().ShouldBe(ruleUri);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Cake.Issues.Tests/IssueOfTTests.cs b/src/Cake.Issues.Tests/IssueOfTTests.cs
deleted file mode 100644
index 93f1badc7..000000000
--- a/src/Cake.Issues.Tests/IssueOfTTests.cs
+++ /dev/null
@@ -1,500 +0,0 @@
-namespace Cake.Issues.Tests
-{
- using System;
- using Shouldly;
- using Testing;
- using Xunit;
-
- public class IssueOfTTests
- {
- public sealed class TheCtor
- {
- [Theory]
- [InlineData("foo\tbar")]
- public void Should_Throw_If_File_Path_Is_Invalid(string filePath)
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(filePath, 100, "Foo", 1, "Bar"));
-
- // Then
- result.IsArgumentException("filePath");
- }
-
- [Theory]
- [InlineData(@"c:\src\foo.cs")]
- [InlineData(@"/foo")]
- [InlineData(@"\foo")]
- public void Should_Throw_If_File_Path_Is_Absolute(string filePath)
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(filePath, 100, "Foo", 1, "Bar"));
-
- // Then
- result.IsArgumentOutOfRangeException("filePath");
- }
-
- [Fact]
- public void Should_Throw_If_Line_Is_Negative()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", -1, "Foo", 1, "Bar"));
-
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
-
- [Fact]
- public void Should_Throw_If_Line_Is_Zero()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 0, "Foo", 1, "Bar"));
-
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
-
- [Fact]
- public void Should_Throw_If_Line_Is_Set_But_No_File()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(null, 10, "Foo", 1, "Bar"));
-
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
-
- [Fact]
- public void Should_Throw_If_Message_Is_Null()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 100, null, 1, "Bar"));
-
- // Then
- result.IsArgumentNullException("message");
- }
-
- [Fact]
- public void Should_Throw_If_Message_Is_Empty()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 100, string.Empty, 1, "Bar"));
-
- // Then
- result.IsArgumentOutOfRangeException("message");
- }
-
- [Fact]
- public void Should_Throw_If_Message_Is_WhiteSpace()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 100, " ", 1, "Bar"));
-
- // Then
- result.IsArgumentOutOfRangeException("message");
- }
-
- [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()
- {
- // Given / When
- var issue = new Issue(null, null, "Foo", 1, "Bar");
-
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
-
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_Empty()
- {
- // Given / When
- var issue = new Issue(string.Empty, null, "Foo", 1, "Bar");
-
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
-
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_WhiteSpace()
- {
- // Given / When
- var issue = new Issue(" ", null, "Foo", 1, "Bar");
-
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
-
- [Theory]
- [InlineData(@"foo", @"foo")]
- [InlineData(@"foo\bar", @"foo/bar")]
- [InlineData(@"foo/bar", @"foo/bar")]
- [InlineData(@"foo\bar\", @"foo/bar")]
- [InlineData(@"foo/bar/", @"foo/bar")]
- [InlineData(@".\foo", @"foo")]
- [InlineData(@"./foo", @"foo")]
- [InlineData(@"foo\..\bar", @"foo/../bar")]
- [InlineData(@"foo/../bar", @"foo/../bar")]
- public void Should_Set_File_Path(string filePath, string expectedFilePath)
- {
- // Given / When
- var issue = new Issue(filePath, 100, "Foo", 1, "Bar");
-
- // Then
- issue.AffectedFileRelativePath.ToString().ShouldBe(expectedFilePath);
- issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "File path was not set as relative.");
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData(1)]
- [InlineData(int.MaxValue)]
- public void Should_Set_Line(int? line)
- {
- // Given / When
- var issue = new Issue(@"foo.cs", line, "Foo", 1, "Bar");
-
- // Then
- issue.Line.ShouldBe(line);
- }
-
- [Theory]
- [InlineData("message")]
- public void Should_Set_Message(string message)
- {
- // Given / When
- var issue = new Issue(@"foo.cs", 100, message, 1, "Bar");
-
- // Then
- issue.Message.ShouldBe(message);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- [InlineData("rule")]
- public void Should_Set_Rule(string rule)
- {
- // Given / When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, rule);
-
- // Then
- issue.Rule.ShouldBe(rule);
- }
-
- [Fact]
- public void Should_Set_ProviderType()
- {
- // Given / When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, "foo");
-
- // Then
- issue.ProviderType.ShouldBe("Cake.Issues.Testing.FakeIssueProvider");
- }
- }
-
- public sealed class TheIssueOfTCtorWithRuleId
- {
- [Theory]
- [InlineData("foo\tbar")]
- public void Should_Throw_If_File_Path_Is_Invalid(string filePath)
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(filePath, 100, "Foo", 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentException("filePath");
- }
-
- [Theory]
- [InlineData(@"c:\src\foo.cs")]
- [InlineData(@"/foo")]
- [InlineData(@"\foo")]
- public void Should_Throw_If_File_Path_Is_Absolute(string filePath)
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(filePath, 100, "Foo", 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentOutOfRangeException("filePath");
- }
-
- [Fact]
- public void Should_Throw_If_Line_Is_Negative()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", -1, "Foo", 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
-
- [Fact]
- public void Should_Throw_If_Line_Is_Zero()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 0, "Foo", 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
-
- [Fact]
- public void Should_Throw_If_Line_Is_Set_But_No_File()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(null, 10, "Foo", 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
-
- [Fact]
- public void Should_Throw_If_Message_Is_Null()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 100, null, 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentNullException("message");
- }
-
- [Fact]
- public void Should_Throw_If_Message_Is_Empty()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 100, string.Empty, 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentOutOfRangeException("message");
- }
-
- [Fact]
- public void Should_Throw_If_Message_Is_WhiteSpace()
- {
- // Given / When
- var result =
- Record.Exception(() =>
- new Issue(@"src\foo.cs", 100, " ", 1, "Bar", new Uri("https://google.com")));
-
- // Then
- result.IsArgumentOutOfRangeException("message");
- }
-
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_Null()
- {
- // Given / When
- var issue = new Issue(null, null, "Foo", 1, "Bar", new Uri("https://google.com"));
-
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
-
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_Empty()
- {
- // Given / When
- var issue = new Issue(string.Empty, null, "Foo", 1, "Bar", new Uri("https://google.com"));
-
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
-
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_WhiteSpace()
- {
- // Given / When
- var issue = new Issue(" ", null, "Foo", 1, "Bar", new Uri("https://google.com"));
-
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
-
- [Theory]
- [InlineData(@"foo", @"foo")]
- [InlineData(@"foo\bar", @"foo/bar")]
- [InlineData(@"foo/bar", @"foo/bar")]
- [InlineData(@"foo\bar\", @"foo/bar")]
- [InlineData(@"foo/bar/", @"foo/bar")]
- [InlineData(@".\foo", @"foo")]
- [InlineData(@"./foo", @"foo")]
- [InlineData(@"foo\..\bar", @"foo/../bar")]
- [InlineData(@"foo/../bar", @"foo/../bar")]
- public void Should_Set_File_Path(string filePath, string expectedFilePath)
- {
- // Given / When
- var issue = new Issue(filePath, 100, "Foo", 1, "Bar", new Uri("https://google.com"));
-
- // Then
- issue.AffectedFileRelativePath.ToString().ShouldBe(expectedFilePath);
- issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "File path was not set as relative.");
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData(1)]
- [InlineData(int.MaxValue)]
- public void Should_Set_Line(int? line)
- {
- // Given / When
- var issue = new Issue(@"foo.cs", line, "Foo", 1, "Bar", new Uri("https://google.com"));
-
- // Then
- issue.Line.ShouldBe(line);
- }
-
- [Theory]
- [InlineData("message")]
- public void Should_Set_Message(string message)
- {
- // Given / When
- var issue = new Issue(@"foo.cs", 100, message, 1, "Bar", new Uri("https://google.com"));
-
- // Then
- issue.Message.ShouldBe(message);
- }
-
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- [InlineData("rule")]
- public void Should_Set_Rule(string rule)
- {
- // Given / When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, rule, new Uri("https://google.com"));
-
- // Then
- issue.Rule.ShouldBe(rule);
- }
-
- [Fact]
- public void Should_Set_Rule_Url()
- {
- // Given
- var ruleUrl = new Uri("http://google.com");
-
- // When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, "foo", ruleUrl);
-
- // Then
- issue.RuleUrl.ShouldBe(ruleUrl);
- }
-
- [Fact]
- public void Should_Set_Rule_Url_If_Null()
- {
- // Given
- Uri ruleUrl = null;
-
- // When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, "foo", ruleUrl);
-
- // Then
- issue.RuleUrl.ShouldBe(ruleUrl);
- }
-
- [Fact]
- public void Should_Set_ProviderType()
- {
- // Given / When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, "foo", new Uri("https://google.com"));
-
- // Then
- issue.ProviderType.ShouldBe("Cake.Issues.Testing.FakeIssueProvider");
- }
- }
-
- public sealed class TheGetProviderTypeNameMethod
- {
- [Fact]
- public void Should_Return_Full_Type_Name()
- {
- // Given / When
- var result = Issue.GetProviderTypeName();
-
- // Then
- result.ShouldBe("Cake.Issues.Testing.FakeIssueProvider");
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Cake.Issues.Tests/IssueReaderTests.cs b/src/Cake.Issues.Tests/IssueReaderTests.cs
index 8a01961fb..d38a23f67 100644
--- a/src/Cake.Issues.Tests/IssueReaderTests.cs
+++ b/src/Cake.Issues.Tests/IssueReaderTests.cs
@@ -114,40 +114,36 @@ public void Should_Initialize_All_Issue_Provider()
fixture.Log,
new List
{
- new Issue(
- @"src\Cake.Issues.Tests\FakeIssueProvider.cs",
- 10,
- "Foo",
- 0,
- "Foo",
- "Foo"),
- new Issue(
- @"src\Cake.Issues.Tests\FakeIssueProvider.cs",
- 12,
- "Bar",
- 0,
- "Bar",
- "Bar")
+ IssueBuilder
+ .NewIssue("Foo", "ProviderTypeFoo", "ProviderNameFoo")
+ .InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
+ .OfRule("Foo")
+ .WithPriority(IssuePriority.Warning)
+ .Create(),
+ IssueBuilder
+ .NewIssue("Bar", "ProviderTypeBar", "ProviderNameBar")
+ .InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
+ .OfRule("Bar")
+ .WithPriority(IssuePriority.Warning)
+ .Create()
}));
fixture.IssueProviders.Add(
new FakeIssueProvider(
fixture.Log,
new List
{
- new Issue(
- @"src\Cake.Issues.Tests\Foo.cs",
- 5,
- "Foo",
- 0,
- "Foo",
- "Foo"),
- new Issue(
- @"src\Cake.Issues.Tests\Bar.cs",
- 7,
- "Bar",
- 0,
- "Bar",
- "Bar")
+ IssueBuilder
+ .NewIssue("Foo", "ProviderTypeFoo", "ProviderNameFoo")
+ .InFile(@"src\Cake.Issues.Tests\Foo.cs", 5)
+ .OfRule("Foo")
+ .WithPriority(IssuePriority.Warning)
+ .Create(),
+ IssueBuilder
+ .NewIssue("Bar", "ProviderTypeBar", "ProviderNameBar")
+ .InFile(@"src\Cake.Issues.Tests\Bar.cs", 7)
+ .OfRule("Bar")
+ .WithPriority(IssuePriority.Warning)
+ .Create()
}));
// When
@@ -162,21 +158,19 @@ public void Should_Read_Correct_Number_Of_Issues()
{
// Given
var issue1 =
- new Issue(
- @"src\Cake.Issues.Tests\FakeIssueProvider.cs",
- 10,
- "Foo",
- 0,
- "Foo",
- "Foo");
+ IssueBuilder
+ .NewIssue("Foo", "ProviderTypeFoo", "ProviderNameFoo")
+ .InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
+ .OfRule("Foo")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var issue2 =
- new Issue(
- @"src\Cake.Issues.Tests\FakeIssueProvider.cs",
- 12,
- "Bar",
- 0,
- "Bar",
- "Bar");
+ IssueBuilder
+ .NewIssue("Bar", "ProviderTypeBar", "ProviderNameBar")
+ .InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
+ .OfRule("Bar")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var fixture = new IssuesFixture();
fixture.IssueProviders.Clear();
fixture.IssueProviders.Add(
@@ -202,21 +196,17 @@ public void Should_Read_Correct_Number_Of_Issues_Not_Related_To_A_File()
{
// Given
var issue1 =
- new Issue(
- null,
- null,
- "Foo",
- 0,
- "Foo",
- "Foo");
+ IssueBuilder
+ .NewIssue("Foo", "ProviderTypeFoo", "ProviderNameFoo")
+ .OfRule("Foo")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var issue2 =
- new Issue(
- null,
- null,
- "Bar",
- 0,
- "Bar",
- "Bar");
+ IssueBuilder
+ .NewIssue("Bar", "ProviderTypeBar", "ProviderNameBar")
+ .OfRule("Bar")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var fixture = new IssuesFixture();
fixture.IssueProviders.Clear();
fixture.IssueProviders.Add(
@@ -242,37 +232,33 @@ public void Should_Read_Correct_Number_Of_Issues_From_Multiple_Providers()
{
// Given
var issue1 =
- new Issue(
- @"src\Cake.Issues.Tests\FakeIssueProvider.cs",
- 10,
- "Foo",
- 0,
- "Foo",
- "Foo");
+ IssueBuilder
+ .NewIssue("Foo", "ProviderTypeFoo", "ProviderNameFoo")
+ .InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 10)
+ .OfRule("Foo")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var issue2 =
- new Issue(
- @"src\Cake.Issues.Tests\FakeIssueProvider.cs",
- 12,
- "Bar",
- 0,
- "Bar",
- "Bar");
+ IssueBuilder
+ .NewIssue("Bar", "ProviderTypeBar", "ProviderNameBar")
+ .InFile(@"src\Cake.Issues.Tests\FakeIssueProvider.cs", 12)
+ .OfRule("Bar")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var issue3 =
- new Issue(
- @"src\Cake.Issues.Tests\Foo.cs",
- 5,
- "Foo",
- 0,
- "Foo",
- "Foo");
+ IssueBuilder
+ .NewIssue("Foo", "ProviderTypeFoo", "ProviderNameFoo")
+ .InFile(@"src\Cake.Issues.Tests\Foo.cs", 5)
+ .OfRule("Foo")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var issue4 =
- new Issue(
- @"src\Cake.Issues.Tests\Bar.cs",
- 7,
- "Bar",
- 0,
- "Bar",
- "Bar");
+ IssueBuilder
+ .NewIssue("Bar", "ProviderTypeBar", "ProviderNameBar")
+ .InFile(@"src\Cake.Issues.Tests\Bar.cs", 5)
+ .OfRule("Bar")
+ .WithPriority(IssuePriority.Warning)
+ .Create();
var fixture = new IssuesFixture();
fixture.IssueProviders.Clear();
fixture.IssueProviders.Add(
diff --git a/src/Cake.Issues.Tests/IssueTests.cs b/src/Cake.Issues.Tests/IssueTests.cs
index 71ebd0db1..863549c54 100644
--- a/src/Cake.Issues.Tests/IssueTests.cs
+++ b/src/Cake.Issues.Tests/IssueTests.cs
@@ -9,283 +9,1176 @@ public sealed class IssueTests
{
public sealed class TheCtor
{
- [Theory]
- [InlineData("foo\tbar")]
- public void Should_Throw_If_File_Path_Is_Invalid(string filePath)
+ public sealed class TheProjectArgument
{
- // Given / When
- var result = Record.Exception(() => new Issue(filePath, 100, "Foo", 1, "Bar", "foo"));
+ [Fact]
+ public void Should_Handle_Projects_Which_Are_Null()
+ {
+ // Given
+ string project = null;
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- result.IsArgumentException("filePath");
- }
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- [Theory]
- [InlineData(@"c:\src\foo.cs")]
- [InlineData(@"/foo")]
- [InlineData(@"\foo")]
- public void Should_Throw_If_File_Path_Is_Absolute(string filePath)
- {
- // Given / When
- var result = Record.Exception(() => new Issue(filePath, 100, "Foo", 1, "Bar", "foo"));
+ // Then
+ issue.Project.ShouldBe(null);
+ }
- // Then
- result.IsArgumentOutOfRangeException("filePath");
- }
+ [Fact]
+ public void Should_Handle_Projects_Which_Are_Empty()
+ {
+ // Given
+ var project = string.Empty;
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- [Fact]
- public void Should_Throw_If_Line_Is_Negative()
- {
- // Given / When
- var result = Record.Exception(() => new Issue(@"src\foo.cs", -1, "Foo", 1, "Bar", "foo"));
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
+ // Then
+ issue.Project.ShouldBe(string.Empty);
+ }
- [Fact]
- public void Should_Throw_If_Line_Is_Zero()
- {
- // Given / When
- var result = Record.Exception(() => new Issue(@"src\foo.cs", 0, "Foo", 1, "Bar", "foo"));
+ [Fact]
+ public void Should_Handle_Projects_Which_Are_WhiteSpace()
+ {
+ // Given
+ var project = " ";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- [Fact]
- public void Should_Throw_If_Line_Is_Set_But_No_File()
- {
- // Given / When
- var result = Record.Exception(() => new Issue(null, 10, "Foo", 1, "Bar", "foo"));
+ // Then
+ issue.Project.ShouldBe(" ");
+ }
- // Then
- result.IsArgumentOutOfRangeException("line");
- }
+ [Theory]
+ [InlineData("project")]
+ public void Should_Set_Project(string project)
+ {
+ // Given
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- [Fact]
- public void Should_Throw_If_Message_Is_Null()
- {
- // Given / When
- var result = Record.Exception(() => new Issue(@"src\foo.cs", 100, null, 1, "Bar", "foo"));
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- result.IsArgumentNullException("message");
+ // Then
+ issue.Project.ShouldBe(project);
+ }
}
- [Fact]
- public void Should_Throw_If_Message_Is_Empty()
+ public sealed class TheFilePathArgument
{
- // Given / When
- var result = Record.Exception(() => new Issue(@"src\foo.cs", 100, string.Empty, 1, "Bar", "foo"));
+ [Theory]
+ [InlineData("foo\tbar")]
+ public void Should_Throw_If_File_Path_Is_Invalid(string filePath)
+ {
+ // Given
+ var project = "Project";
+ var line = 100;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- result.IsArgumentOutOfRangeException("message");
- }
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
- [Fact]
- public void Should_Throw_If_Message_Is_WhiteSpace()
- {
- // Given / When
- var result = Record.Exception(() => new Issue(@"src\foo.cs", 100, " ", 1, "Bar", "foo"));
+ // Then
+ result.IsArgumentException("filePath");
+ }
- // Then
- result.IsArgumentOutOfRangeException("message");
- }
+ [Theory]
+ [InlineData(@"c:\src\foo.cs")]
+ [InlineData(@"/foo")]
+ [InlineData(@"\foo")]
+ public void Should_Throw_If_File_Path_Is_Absolute(string filePath)
+ {
+ // Given
+ var project = "Project";
+ var line = 100;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- [Fact]
- public void Should_Throw_If_Provider_Type_Is_Null()
- {
- // Given / When
- var result = Record.Exception(() => new Issue(@"src\foo.cs", 100, "foo", 1, "foo", null));
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
- // Then
- result.IsArgumentNullException("providerType");
- }
+ // Then
+ result.IsArgumentOutOfRangeException("filePath");
+ }
- [Fact]
- public void Should_Throw_If_Provider_Type_Is_Empty()
- {
- // Given / When
- var result = Record.Exception(() => new Issue(@"src\foo.cs", 100, "foo", 1, "foo", string.Empty));
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_Null()
+ {
+ // Given
+ var project = "Project";
+ string filePath = null;
+ int? line = null;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- result.IsArgumentOutOfRangeException("providerType");
- }
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- [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
+ issue.AffectedFileRelativePath.ShouldBe(null);
+ }
- // Then
- result.IsArgumentOutOfRangeException("providerType");
- }
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_Empty()
+ {
+ // Given
+ var project = "Project";
+ var filePath = string.Empty;
+ int? line = null;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- [Fact]
- public void Should_Handle_Projects_Which_Are_Null()
- {
- // Given / When
- var issue = new Issue(null, @"src\foo.cs", null, "Foo", 1, "Bar", "foo");
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- issue.Project.ShouldBe(null);
- }
+ // Then
+ issue.AffectedFileRelativePath.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");
+ [Fact]
+ public void Should_Handle_File_Paths_Which_Are_WhiteSpace()
+ {
+ // Given
+ var project = "Project";
+ var filePath = " ";
+ int? line = null;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- issue.Project.ShouldBe(" ");
- }
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- [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.AffectedFileRelativePath.ShouldBe(null);
+ }
- // Then
- issue.Project.ShouldBe(string.Empty);
- }
+ [Theory]
+ [InlineData(@"foo", @"foo")]
+ [InlineData(@"foo\bar", @"foo/bar")]
+ [InlineData(@"foo/bar", @"foo/bar")]
+ [InlineData(@"foo\bar\", @"foo/bar")]
+ [InlineData(@"foo/bar/", @"foo/bar")]
+ [InlineData(@".\foo", @"foo")]
+ [InlineData(@"./foo", @"foo")]
+ [InlineData(@"foo\..\bar", @"foo/../bar")]
+ [InlineData(@"foo/../bar", @"foo/../bar")]
+ public void Should_Set_File_Path(string filePath, string expectedFilePath)
+ {
+ // Given
+ var project = "Project";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- [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");
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- issue.Project.ShouldBe(project);
+ // Then
+ issue.AffectedFileRelativePath.ToString().ShouldBe(expectedFilePath);
+ issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "File path was not set as relative.");
+ }
}
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_Null()
+ public sealed class TheLineArgument
{
- // Given / When
- var issue = new Issue(null, null, "Foo", 1, "Bar", "foo");
+ [Fact]
+ public void Should_Throw_If_Line_Is_Negative()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = -1;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_Empty()
- {
- // Given / When
- var issue = new Issue(string.Empty, null, "Foo", 1, "Bar", "foo");
+ // Then
+ result.IsArgumentOutOfRangeException("line");
+ }
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
- }
+ [Fact]
+ public void Should_Throw_If_Line_Is_Zero()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 0;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- [Fact]
- public void Should_Handle_File_Paths_Which_Are_WhiteSpace()
- {
- // Given / When
- var issue = new Issue(" ", null, "Foo", 1, "Bar", "foo");
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
- // Then
- issue.AffectedFileRelativePath.ShouldBe(null);
+ // Then
+ result.IsArgumentOutOfRangeException("line");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Line_Is_Set_But_No_File()
+ {
+ // Given
+ var project = "Project";
+ string filePath = null;
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("line");
+ }
+
+ [Theory]
+ [InlineData(null)]
+ [InlineData(1)]
+ [InlineData(int.MaxValue)]
+ public void Should_Set_Line(int? line)
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.Line.ShouldBe(line);
+ }
}
- [Theory]
- [InlineData(@"foo", @"foo")]
- [InlineData(@"foo\bar", @"foo/bar")]
- [InlineData(@"foo/bar", @"foo/bar")]
- [InlineData(@"foo\bar\", @"foo/bar")]
- [InlineData(@"foo/bar/", @"foo/bar")]
- [InlineData(@".\foo", @"foo")]
- [InlineData(@"./foo", @"foo")]
- [InlineData(@"foo\..\bar", @"foo/../bar")]
- [InlineData(@"foo/../bar", @"foo/../bar")]
- public void Should_Set_File_Path(string filePath, string expectedFilePath)
+ public sealed class TheMessageArgument
{
- // Given / When
- var issue = new Issue(filePath, 100, "Foo", 1, "Bar", "foo");
+ [Fact]
+ public void Should_Throw_If_Message_Is_Null()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ string message = null;
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentNullException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Message_Is_Empty()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = string.Empty;
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
- // Then
- issue.AffectedFileRelativePath.ToString().ShouldBe(expectedFilePath);
- issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "File path was not set as relative.");
+ // Then
+ result.IsArgumentOutOfRangeException("message");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Message_Is_WhiteSpace()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = " ";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("message");
+ }
+
+ [Theory]
+ [InlineData("message")]
+ public void Should_Set_Message(string message)
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.Message.ShouldBe(message);
+ }
}
- [Theory]
- [InlineData(null)]
- [InlineData(1)]
- [InlineData(int.MaxValue)]
- public void Should_Set_Line(int? line)
+ public sealed class ThePriorityArgument
{
- // Given / When
- var issue = new Issue(@"foo.cs", line, "Foo", 1, "Bar", "foo");
+ [Theory]
+ [InlineData(null)]
+ [InlineData(int.MinValue)]
+ [InlineData(-1)]
+ [InlineData(0)]
+ [InlineData(1)]
+ [InlineData(int.MaxValue)]
+ public void Should_Set_Priority(int? priority)
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- issue.Line.ShouldBe(line);
+ // Then
+ issue.Priority.ShouldBe(priority);
+ }
}
- [Theory]
- [InlineData("message")]
- public void Should_Set_Message(string message)
+ public sealed class ThePriorityNameArgument
{
- // Given / When
- var issue = new Issue(@"foo.cs", 100, message, 1, "Bar", "foo");
+ [Fact]
+ public void Should_Handle_PriorityNames_Which_Are_Null()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ string priorityName = null;
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.PriorityName.ShouldBe(null);
+ }
+
+ [Fact]
+ public void Should_Handle_PriorityNames_Which_Are_Empty()
+ {
+ // Given
+ var project = "PRoject";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = string.Empty;
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- issue.Message.ShouldBe(message);
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.PriorityName.ShouldBe(string.Empty);
+ }
+
+ [Fact]
+ public void Should_Handle_PriorityNames_Which_Are_WhiteSpace()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = " ";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.PriorityName.ShouldBe(" ");
+ }
+
+ [Theory]
+ [InlineData("Warning")]
+ public void Should_Set_Priority_Name(string priorityName)
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.PriorityName.ShouldBe(priorityName);
+ }
}
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- [InlineData("rule")]
- public void Should_Set_Rule(string rule)
+ public sealed class TheRuleArgument
{
- // Given / When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, rule, "foo");
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData("rule")]
+ public void Should_Set_Rule(string rule)
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- issue.Rule.ShouldBe(rule);
+ // Then
+ issue.Rule.ShouldBe(rule);
+ }
}
- [Fact]
- public void Should_Set_Rule_Url()
+ public sealed class TheRuleUrlArgument
{
- // Given
- var ruleUrl = new Uri("http://google.com");
+ [Fact]
+ public void Should_Set_Rule_Url()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.RuleUrl.ShouldBe(ruleUri);
+ }
- // When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, "foo", ruleUrl, "foo");
+ [Fact]
+ public void Should_Set_Rule_Url_If_Null()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ Uri ruleUri = null;
+ var providerType = "ProviderType";
+ var providerName = "ProviderName";
- // Then
- issue.RuleUrl.ShouldBe(ruleUrl);
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
+
+ // Then
+ issue.RuleUrl.ShouldBe(ruleUri);
+ }
}
- [Fact]
- public void Should_Set_Rule_Url_If_Null()
+ public sealed class TheProviderTypeArgument
{
- // Given
- Uri ruleUrl = null;
+ [Fact]
+ public void Should_Throw_If_Provider_Type_Is_Null()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ string providerType = null;
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentNullException("providerType");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Provider_Type_Is_Empty()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = string.Empty;
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerType");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Provider_Type_Is_WhiteSpace()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = " ";
+ var providerName = "ProviderName";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerType");
+ }
+
+ [Theory]
+ [InlineData("foo")]
+ public void Should_Set_ProviderType(string providerType)
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerName = "ProviderName";
- // When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, "foo", ruleUrl, "foo");
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- issue.RuleUrl.ShouldBe(ruleUrl);
+ // Then
+ issue.ProviderType.ShouldBe(providerType);
+ }
}
- [Theory]
- [InlineData("foo")]
- public void Should_Set_ProviderType(string providerType)
+ public sealed class TheProviderNameArgument
{
- // Given / When
- var issue = new Issue(@"foo.cs", 100, "foo", 1, "foo", providerType);
+ [Fact]
+ public void Should_Throw_If_Provider_Name_Is_Null()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ string providerName = null;
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentNullException("providerName");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Provider_Name_Is_Empty()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = string.Empty;
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerName");
+ }
+
+ [Fact]
+ public void Should_Throw_If_Provider_Name_Is_WhiteSpace()
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+ var providerName = " ";
+
+ // When
+ var result = Record.Exception(() =>
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName));
+
+ // Then
+ result.IsArgumentOutOfRangeException("providerName");
+ }
+
+ [Theory]
+ [InlineData("providerName")]
+ public void Should_Set_ProviderName(string providerName)
+ {
+ // Given
+ var project = "Project";
+ var filePath = @"src\foo.cs";
+ var line = 10;
+ var message = "Message";
+ var priority = 1;
+ var priorityName = "Warning";
+ var rule = "Rule";
+ var ruleUri = new Uri("https://google.com");
+ var providerType = "ProviderType";
+
+ // When
+ var issue =
+ new Issue(
+ project,
+ filePath,
+ line,
+ message,
+ priority,
+ priorityName,
+ rule,
+ ruleUri,
+ providerType,
+ providerName);
- // Then
- issue.ProviderType.ShouldBe(providerType);
+ // Then
+ issue.ProviderName.ShouldBe(providerName);
+ }
}
}
}
diff --git a/src/Cake.Issues/Cake.Issues.csproj b/src/Cake.Issues/Cake.Issues.csproj
index 9fca9f598..3c41a992f 100644
--- a/src/Cake.Issues/Cake.Issues.csproj
+++ b/src/Cake.Issues/Cake.Issues.csproj
@@ -23,7 +23,7 @@
-
+
diff --git a/src/Cake.Issues/IIssue.cs b/src/Cake.Issues/IIssue.cs
index 954723119..8ffeb8d83 100644
--- a/src/Cake.Issues/IIssue.cs
+++ b/src/Cake.Issues/IIssue.cs
@@ -34,8 +34,15 @@ public interface IIssue
///
/// Gets the priority of the message. A higher value indicates a higher priority.
+ /// null if no priority was assigned.
///
- int Priority { get; }
+ int? Priority { get; }
+
+ ///
+ /// Gets the human friendly name of the priority.
+ /// null or if no priority was assigned.
+ ///
+ string PriorityName { get; }
///
/// Gets the rule of the issue.
@@ -53,5 +60,10 @@ public interface IIssue
/// Gets the type of the issue provider.
///
string ProviderType { get; }
+
+ ///
+ /// Gets the human friendly name of the issue provider.
+ ///
+ string ProviderName { get; }
}
}
\ No newline at end of file
diff --git a/src/Cake.Issues/IIssueProvider.cs b/src/Cake.Issues/IIssueProvider.cs
index bf146e23e..832a1e66b 100644
--- a/src/Cake.Issues/IIssueProvider.cs
+++ b/src/Cake.Issues/IIssueProvider.cs
@@ -7,6 +7,11 @@
///
public interface IIssueProvider : IBaseIssueComponent
{
+ ///
+ /// Gets the human friendly name of the issue provider.
+ ///
+ string ProviderName { get; }
+
///
/// Gets all issues.
///
diff --git a/src/Cake.Issues/Issue.cs b/src/Cake.Issues/Issue.cs
index 1bf9e8902..220738a8e 100644
--- a/src/Cake.Issues/Issue.cs
+++ b/src/Cake.Issues/Issue.cs
@@ -8,57 +8,6 @@
///
public class Issue : IIssue
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// 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.
- /// null 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.
- /// null or if issue has no specific rule ID.
- /// The type of the issue provider.
- public Issue(
- string filePath,
- int? line,
- string message,
- int priority,
- string rule,
- string providerType)
- : this(filePath, line, message, priority, rule, null, providerType)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// 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.
- /// null 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.
- /// null or if issue has no specific rule ID.
- /// The URL containing information about the failing rule.
- /// null if no URL is available.
- /// The type of the issue provider.
- public Issue(
- string filePath,
- int? line,
- string message,
- int priority,
- string rule,
- Uri ruleUrl,
- string providerType)
- : this(null, filePath, line, message, priority, rule, ruleUrl, providerType)
- {
- }
-
///
/// Initializes a new instance of the class.
///
@@ -70,52 +19,32 @@ public Issue(
/// The line in the file where the issues has occurred.
/// null 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.
- /// null or if issue has no specific rule ID.
- /// 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.
- /// null or if issue is not related to a project.
- /// 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.
- /// null if the issue affects the whole file or an asssembly.
- /// The message of the issue.
- /// The priority of the message.
+ /// The priority of the message.
+ /// null if no priority was assigned.
+ /// The human friendly name of the priority.
+ /// null or if no priority was assigned.
/// The rule of the issue.
/// null or if issue has no specific rule ID.
/// The URL containing information about the failing rule.
/// null if no URL is available.
/// The type of the issue provider.
+ /// The human friendly name of the issue provider.
public Issue(
string project,
string filePath,
int? line,
string message,
- int priority,
+ int? priority,
+ string priorityName,
string rule,
Uri ruleUrl,
- string providerType)
+ string providerType,
+ string providerName)
{
line?.NotNegativeOrZero(nameof(line));
message.NotNullOrWhiteSpace(nameof(message));
providerType.NotNullOrWhiteSpace(nameof(providerType));
+ providerName.NotNullOrWhiteSpace(nameof(providerName));
// File path needs to be relative to the repository root.
if (!string.IsNullOrWhiteSpace(filePath))
@@ -142,9 +71,11 @@ public Issue(
this.Line = line;
this.Message = message;
this.Priority = priority;
+ this.PriorityName = priorityName;
this.Rule = rule;
this.RuleUrl = ruleUrl;
this.ProviderType = providerType;
+ this.ProviderName = providerName;
}
///
@@ -160,7 +91,10 @@ public Issue(
public string Message { get; }
///
- public int Priority { get; }
+ public int? Priority { get; }
+
+ ///
+ public string PriorityName { get; }
///
public string Rule { get; }
@@ -170,5 +104,8 @@ public Issue(
///
public string ProviderType { get; }
+
+ ///
+ public string ProviderName { get; }
}
}
diff --git a/src/Cake.Issues/IssueBuilder.cs b/src/Cake.Issues/IssueBuilder.cs
new file mode 100644
index 000000000..aba4dae3e
--- /dev/null
+++ b/src/Cake.Issues/IssueBuilder.cs
@@ -0,0 +1,203 @@
+namespace Cake.Issues
+{
+ using System;
+
+ ///
+ /// Class to create instances of with a fluent API.
+ ///
+ public class IssueBuilder
+ {
+ private readonly string message;
+ private readonly string providerType;
+ private readonly string providerName;
+ private string project;
+ private string filePath;
+ private int? line;
+ private int priority;
+ private string priorityName;
+ private string rule;
+ private Uri ruleUrl;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The message of the issue.
+ /// The type of the issue provider.
+ /// The human friendly name of the issue provider.
+ private IssueBuilder(
+ string message,
+ string providerType,
+ string providerName)
+ {
+ message.NotNullOrWhiteSpace(nameof(message));
+ providerType.NotNullOrWhiteSpace(nameof(providerType));
+ providerName.NotNullOrWhiteSpace(nameof(providerName));
+
+ this.message = message;
+ this.providerType = providerType;
+ this.providerName = providerName;
+ }
+
+ ///
+ /// Creates a new instance of the class.
+ ///
+ /// The message of the issue.
+ /// The type of the issue provider.
+ /// The human friendly name of the issue provider.
+ /// New issue
+ public static IssueBuilder NewIssue(
+ string message,
+ string providerType,
+ string providerName)
+ {
+ message.NotNullOrWhiteSpace(nameof(message));
+ providerType.NotNullOrWhiteSpace(nameof(providerType));
+ providerName.NotNullOrWhiteSpace(nameof(providerName));
+
+ return new IssueBuilder(message, providerType, providerName);
+ }
+
+ ///
+ /// Creates a new instance of the class.
+ ///
+ /// Type of the issue provider which has the issue created.
+ /// The message of the issue.
+ /// Issue provider which has the issue created.
+ /// New issue
+ public static IssueBuilder NewIssue(
+ string message,
+ T issueProvider)
+ where T : IIssueProvider
+ {
+ if (issueProvider == null)
+ {
+ throw new ArgumentNullException(nameof(issueProvider));
+ }
+
+ message.NotNullOrWhiteSpace(nameof(message));
+
+ return new IssueBuilder(message, typeof(T).FullName, issueProvider.ProviderName);
+ }
+
+ ///
+ /// Sets the name of the project to which the file affected by the issue belongs.
+ ///
+ /// Name of the project to which the file affected by the issue belongs.
+ /// null or if issue is not related to a project.
+ /// Issue Builder instance.
+ public IssueBuilder InProject(string name)
+ {
+ this.project = name;
+
+ return this;
+ }
+
+ ///
+ /// Sets the path to the file affected by the issue.
+ ///
+ /// 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.
+ /// Issue Builder instance.
+ public IssueBuilder InFile(string filePath)
+ {
+ this.filePath = filePath;
+
+ return this;
+ }
+
+ ///
+ /// Sets the path to the file affected by the issue and the line in the file where the issues has occurred.
+ ///
+ /// 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.
+ /// null if the issue affects the whole file or an asssembly.
+ /// Issue Builder instance.
+ public IssueBuilder InFile(string filePath, int? line)
+ {
+ line?.NotNegativeOrZero(nameof(line));
+
+ this.filePath = filePath;
+ this.line = line;
+
+ return this;
+ }
+
+ ///
+ /// Sets the priority of the message.
+ ///
+ /// The priority of the message.
+ /// Issue Builder instance.
+ public IssueBuilder WithPriority(IssuePriority priority)
+ {
+ return this.WithPriority((int)priority, priority.ToString());
+ }
+
+ ///
+ /// Sets the priority of the message.
+ ///
+ /// The priority of the message.
+ /// null if no priority should be assigned.
+ /// The human friendly name of the priority.
+ /// null or if no priority should be assigned.
+ /// Issue Builder instance.
+ public IssueBuilder WithPriority(int value, string name)
+ {
+ this.priority = value;
+ this.priorityName = name;
+
+ return this;
+ }
+
+ ///
+ /// Sets the rule of the issue.
+ ///
+ /// The rule of the issue.
+ /// null or if issue has no specific rule ID.
+ /// Issue Builder instance.
+ public IssueBuilder OfRule(string name)
+ {
+ this.rule = name;
+
+ return this;
+ }
+
+ ///
+ /// Sets the rule of the issue.
+ ///
+ /// The rule of the issue.
+ /// null or if issue has no specific rule ID.
+ /// The URL containing information about the failing rule.
+ /// null if no URL is available.
+ /// Issue Builder instance.
+ public IssueBuilder OfRule(string name, Uri uri)
+ {
+ this.rule = name;
+ this.ruleUrl = uri;
+
+ return this;
+ }
+
+ ///
+ /// Creates a new .
+ ///
+ /// New issue object.
+ public IIssue Create()
+ {
+ return
+ new Issue(
+ this.project,
+ this.filePath,
+ this.line,
+ this.message,
+ this.priority,
+ this.priorityName,
+ this.rule,
+ this.ruleUrl,
+ this.providerType,
+ this.providerName);
+ }
+ }
+}
diff --git a/src/Cake.Issues/IssuePriority.cs b/src/Cake.Issues/IssuePriority.cs
new file mode 100644
index 000000000..561b599d0
--- /dev/null
+++ b/src/Cake.Issues/IssuePriority.cs
@@ -0,0 +1,33 @@
+namespace Cake.Issues
+{
+ ///
+ /// Default priorities for .
+ ///
+ public enum IssuePriority
+ {
+ ///
+ /// Undefined priority.
+ ///
+ Undefined = 0,
+
+ ///
+ /// Issues which brings attention to a specific part of the code or recommends a way of improvement.
+ ///
+ Hint = 100,
+
+ ///
+ /// Issues which aren't necessarily bad or wrong, but probably useful to know.
+ ///
+ Suggestion = 200,
+
+ ///
+ /// Issues that do not prevent code from compiling but may nevertheless represent serious coding inefficiencies.
+ ///
+ Warning = 300,
+
+ ///
+ /// Issues that either prevent code from compiling or result in runtime errors.
+ ///
+ Error = 400
+ }
+}
diff --git a/src/Cake.Issues/IssueProvider.cs b/src/Cake.Issues/IssueProvider.cs
index 7eacbea4a..5bacba8f7 100644
--- a/src/Cake.Issues/IssueProvider.cs
+++ b/src/Cake.Issues/IssueProvider.cs
@@ -17,6 +17,9 @@ protected IssueProvider(ICakeLog log)
{
}
+ ///
+ public abstract string ProviderName { get; }
+
///
public IEnumerable ReadIssues(IssueCommentFormat format)
{
diff --git a/src/Cake.Issues/Issue{T}.cs b/src/Cake.Issues/Issue{T}.cs
deleted file mode 100644
index a30944791..000000000
--- a/src/Cake.Issues/Issue{T}.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-namespace Cake.Issues
-{
- using System;
-
- ///
- /// Base class for an issue.
- ///
- /// Type of the issue provider which has raised the issue.
- public class Issue : Issue
- where T : IIssueProvider
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// 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.
- /// null 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.
- /// null or if issue has no specific rule ID.
- public Issue(
- string filePath,
- int? line,
- string message,
- int priority,
- string rule)
- : base(filePath, line, message, priority, rule, typeof(T).FullName)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// 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.
- /// null 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.
- /// null or if issue has no specific rule ID.
- /// The URL containing information about the failing rule.
- /// null if no URL is available.
- public Issue(
- string filePath,
- int? line,
- string message,
- int priority,
- string rule,
- Uri ruleUrl)
- : base(filePath, line, message, priority, rule, ruleUrl, GetProviderTypeName())
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Name of the project to which the file affected by the issue belongs.
- /// null or if issue is not related to a project.
- /// 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.
- /// null 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.
- /// null or if issue has no specific rule ID.
- 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.
- /// null or if issue is not related to a project.
- /// 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.
- /// null 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.
- /// null or if issue has no specific rule ID.
- /// The URL containing information about the failing rule.
- /// null if no URL is available.
- 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.
- ///
- /// Name of the issue provider.
- public static string GetProviderTypeName()
- {
- return typeof(T).FullName;
- }
- }
-}