Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-5) Add project to issue #7

Merged
merged 1 commit into from
Oct 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/Cake.Issues.Tests/IssueOfTTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FakeIssueProvider>(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<FakeIssueProvider>(" ", @"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<FakeIssueProvider>(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<FakeIssueProvider>(project, @"src\foo.cs", null, "Foo", 1, "Bar");

// Then
issue.Project.ShouldBe(project);
}

[Fact]
public void Should_Handle_File_Paths_Which_Are_Null()
{
Expand Down
41 changes: 41 additions & 0 deletions src/Cake.Issues.Tests/IssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Cake.Issues/IIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
/// </summary>
public interface IIssue
{
/// <summary>
/// Gets the name of the project to which the file affected by the issue belongs.
/// </summary>
string Project { get; }

/// <summary>
/// Gets the path to the file affacted by the issue.
/// The path is relative to the repository root.
Expand Down
56 changes: 56 additions & 0 deletions src/Cake.Issues/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,58 @@ public Issue(
string rule,
Uri ruleUrl,
string providerType)
: this(null, filePath, line, message, priority, rule, ruleUrl, providerType)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Issue"/> class.
/// </summary>
/// <param name="project">Name of the project to which the file affected by the issue belongs</param>
/// <param name="filePath">The path to the file affacted by the issue.
/// The path needs to be relative to the repository root.
/// <c>null</c> or <see cref="string.Empty"/> if issue is not related to a change in a file.</param>
/// <param name="line">The line in the file where the issues has occurred.
/// Nothing if the issue affects the whole file or an asssembly.</param>
/// <param name="message">The message of the issue.</param>
/// <param name="priority">The priority of the message.</param>
/// <param name="rule">The rule of the issue.</param>
/// <param name="providerType">The type of the issue provider.</param>
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)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Issue"/> class.
/// </summary>
/// <param name="project">Name of the project to which the file affected by the issue belongs</param>
/// <param name="filePath">The path to the file affacted by the issue.
/// The path needs to be relative to the repository root.
/// <c>null</c> or <see cref="string.Empty"/> if issue is not related to a change in a file.</param>
/// <param name="line">The line in the file where the issues has occurred.
/// Nothing if the issue affects the whole file or an asssembly.</param>
/// <param name="message">The message of the issue.</param>
/// <param name="priority">The priority of the message.</param>
/// <param name="rule">The rule of the issue.</param>
/// <param name="ruleUrl">The URL containing information about the failing rule.</param>
/// <param name="providerType">The type of the issue provider.</param>
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));
Expand Down Expand Up @@ -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;
Expand All @@ -87,6 +140,9 @@ public Issue(
this.ProviderType = providerType;
}

/// <inheritdoc/>
public string Project { get; }

/// <inheritdoc/>
public FilePath AffectedFileRelativePath { get; }

Expand Down
48 changes: 48 additions & 0 deletions src/Cake.Issues/Issue{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,54 @@ public Issue(
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Issue{T}"/> class.
/// </summary>
/// <param name="project">Name of the project to which the file affected by the issue belongs</param>
/// <param name="filePath">The path to the file affacted by the issue.
/// The path needs to be relative to the repository root.
/// <c>null</c> or <see cref="string.Empty"/> if issue is not related to a change in a file.</param>
/// <param name="line">The line in the file where the issues has occurred.
/// Nothing if the issue affects the whole file or an asssembly.</param>
/// <param name="message">The message of the issue.</param>
/// <param name="priority">The priority of the message.</param>
/// <param name="rule">The rule of the issue.</param>
public Issue(
string project,
string filePath,
int? line,
string message,
int priority,
string rule)
: base(project, filePath, line, message, priority, rule, null, GetProviderTypeName())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Issue{T}"/> class.
/// </summary>
/// <param name="project">Name of the project to which the file affected by the issue belongs</param>
/// <param name="filePath">The path to the file affacted by the issue.
/// The path needs to be relative to the repository root.
/// <c>null</c> or <see cref="string.Empty"/> if issue is not related to a change in a file.</param>
/// <param name="line">The line in the file where the issues has occurred.
/// Nothing if the issue affects the whole file or an asssembly.</param>
/// <param name="message">The message of the issue.</param>
/// <param name="priority">The priority of the message.</param>
/// <param name="rule">The rule of the issue.</param>
/// <param name="ruleUrl">The URL containing information about the failing rule.</param>
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())
{
}

/// <summary>
/// Gets the name of the issue provider as it will be set to in the <see cref="IIssue.ProviderType"/> property.
/// </summary>
Expand Down