Skip to content

Commit

Permalink
(GH-179) Add run description to IIssue
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Jul 3, 2020
1 parent ad76e07 commit 7f9082c
Show file tree
Hide file tree
Showing 21 changed files with 513 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cs diff=csharp
9 changes: 9 additions & 0 deletions src/Cake.Issues.Testing/IssueChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static void Check(
issueToCheck,
expectedIssue.ProviderType,
expectedIssue.ProviderName,
expectedIssue.Run,
expectedIssue.ProjectFileRelativePath?.ToString(),
expectedIssue.ProjectName,
expectedIssue.AffectedFileRelativePath?.ToString(),
Expand All @@ -61,6 +62,7 @@ public static void Check(
/// <param name="issue">Issue which should be checked.</param>
/// <param name="providerType">Expected type of the issue provider.</param>
/// <param name="providerName">Expected human friendly name of the issue provider.</param>
/// <param name="run">Expected name of the run which reported the issue.</param>
/// <param name="projectFileRelativePath">Expected relative path of the project file.
/// <c>null</c> if the issue is not expected to be related to a project.</param>
/// <param name="projectName">Expected project name.
Expand All @@ -86,6 +88,7 @@ public static void Check(
IIssue issue,
string providerType,
string providerName,
string run,
string projectFileRelativePath,
string projectName,
string affectedFileRelativePath,
Expand Down Expand Up @@ -113,6 +116,12 @@ public static void Check(
$"Expected issue.ProviderName to be '{providerName}' but was '{issue.ProviderName}'.");
}

if (issue.Run != run)
{
throw new Exception(
$"Expected issue.Run to be '{run}' but was '{issue.Run}'.");
}

if (issue.ProjectFileRelativePath == null)
{
if (projectFileRelativePath != null)
Expand Down
76 changes: 76 additions & 0 deletions src/Cake.Issues.Tests/IIssueComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,25 @@ public void Should_Return_False_If_ProviderName_Is_Different()
CompareIssues(issue1, issue2, false);
}

[Fact]
public void Should_Return_False_If_Run_Is_Different()
{
// Given
var issue1 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run1")
.Create();
var issue2 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run2")
.Create();

// When / Then
CompareIssues(issue1, issue2, false);
}

[Fact]
public void Should_Return_True_If_Same_Reference()
{
Expand Down Expand Up @@ -711,6 +730,25 @@ public void Should_Return_True_If_ProviderName_Is_Same()
CompareIssues(issue1, issue2, true);
}

[Fact]
public void Should_Return_True_If_Run_Is_Same()
{
// Given
var issue1 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run")
.Create();
var issue2 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run")
.Create();

// When / Then
CompareIssues(issue1, issue2, true);
}

[Fact]
public void Should_Remove_Identical_Issues_From_List_Of_Issues()
{
Expand Down Expand Up @@ -1015,6 +1053,25 @@ public void Should_Return_False_If_ProviderName_Is_Different()
CompareIssues(issue1, issue2, false);
}

[Fact]
public void Should_Return_False_If_Run_Is_Different()
{
// Given
var issue1 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run1")
.Create();
var issue2 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run2")
.Create();

// When / Then
CompareIssues(issue1, issue2, false);
}

[Fact]
public void Should_Return_True_If_Same_Reference()
{
Expand Down Expand Up @@ -1463,6 +1520,25 @@ public void Should_Return_True_If_ProviderName_Is_Same()
CompareIssues(issue1, issue2, true);
}

[Fact]
public void Should_Return_True_If_Run_Is_Same()
{
// Given
var issue1 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run")
.Create();
var issue2 =
IssueBuilder
.NewIssue("message", "providerType", "providerName")
.ForRun("run")
.Create();

// When / Then
CompareIssues(issue1, issue2, true);
}

[Fact]
public void Should_Remove_Identical_Issues_From_List_Of_Issues()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Cake.Issues.Tests/IIssueExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public void Should_Throw_If_Issue_Is_Null()
[InlineData("{foo}", "{foo}")]
[InlineData("foo {ProviderType} bar", "foo ProviderType Foo bar")]
[InlineData("foo {ProviderName} bar", "foo ProviderName Foo bar")]
[InlineData("foo {Run} bar", "foo Run bar")]
[InlineData("foo {Priority} bar", "foo 400 bar")]
[InlineData("foo {PriorityName} bar", "foo Error bar")]
[InlineData("foo {ProjectPath} bar", "foo src/Cake.Issues/Cake.Issues.csproj bar")]
Expand All @@ -318,6 +319,7 @@ public void Should_Replace_Tokens(string pattern, string expectedResult)
var issue =
IssueBuilder
.NewIssue("MessageText Foo", "ProviderType Foo", "ProviderName Foo")
.ForRun("Run")
.WithMessageInHtmlFormat("MessageHtml Foo")
.WithMessageInMarkdownFormat("MessageMarkdown Foo")
.InFile(@"src/Cake.Issues/foo.cs", 42, 23)
Expand Down
62 changes: 62 additions & 0 deletions src/Cake.Issues.Tests/IssueBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,5 +988,67 @@ public void Should_Set_RuleUrl(string ruleUri)
issue.RuleUrl.ToString().ShouldBe(ruleUri);
}
}

public sealed class TheForRunMethod
{
[Fact]
public void Should_Throw_If_Run_Is_Null()
{
// Given
var fixture = new IssueBuilderFixture();
string run = null;

// When
var result = Record.Exception(() =>
fixture.IssueBuilder.ForRun(run));

// Then
result.IsArgumentNullException("run");
}

[Fact]
public void Should_Throw_If_Run_Is_Empty()
{
// Given
var fixture = new IssueBuilderFixture();
string run = string.Empty;

// When
var result = Record.Exception(() =>
fixture.IssueBuilder.ForRun(run));

// Then
result.IsArgumentException("run");
}

[Fact]
public void Should_Throw_If_Run_Is_WhiteSpace()
{
// Given
var fixture = new IssueBuilderFixture();
string run = " ";

// When
var result = Record.Exception(() =>
fixture.IssueBuilder.ForRun(run));

// Then
result.IsArgumentException("run");
}

[Theory]
[InlineData("run")]
public void Should_Set_Run(string run)
{
// Given
var fixture = new IssueBuilderFixture();

// When
var issue = fixture.IssueBuilder.ForRun(run).Create();

// Then
issue.Run.ToString().ShouldBe(run);
}
}
}
}
Loading

0 comments on commit 7f9082c

Please sign in to comment.