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

DiagnosticResult builder simplification #526

Merged
merged 12 commits into from
Mar 15, 2015
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Xunit;
using StyleCop.Analyzers.DocumentationRules;
using TestHelper;
using Xunit;

/// <summary>
/// This class contains unit tests for <see cref="SA1601PartialElementsMustBeDocumented"/>-
Expand Down Expand Up @@ -47,23 +45,8 @@ public partial {0}
{{
}}";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "Partial elements must be documented",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 3, 1)
}
}
};
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 1);

await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "class"), expected, CancellationToken.None);
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "struct"), expected, CancellationToken.None);
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "interface"), expected, CancellationToken.None);
Expand All @@ -81,23 +64,8 @@ public partial {0}
{{
}}";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "Partial elements must be documented",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 6, 1)
}
}
};
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1);

await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "class"), expected, CancellationToken.None);
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "struct"), expected, CancellationToken.None);
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "interface"), expected, CancellationToken.None);
Expand Down Expand Up @@ -132,23 +100,7 @@ public partial class TypeName
partial void MemberName();
}}";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "Partial elements must be documented",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 7, 18)
}
}
};
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 18);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}
Expand All @@ -168,23 +120,7 @@ public partial class TypeName
partial void MemberName();
}}";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "Partial elements must be documented",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 10, 18)
}
}
};
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 18);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Xunit;
using StyleCop.Analyzers.DocumentationRules;
using TestHelper;
using Xunit;

/// <summary>
/// This class contains unit tests for <see cref="SA1602EnumerationItemsMustBeDocumented"/>-
Expand Down Expand Up @@ -49,23 +47,8 @@ enum TypeName
Bar
}}";

DiagnosticResult[] expected;
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 5);

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "Enumeration items must be documented",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 4, 5)
}
}
};
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}

Expand All @@ -84,23 +67,8 @@ enum TypeName
Bar
}}";

DiagnosticResult[] expected;
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 5);

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "Enumeration items must be documented",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 10, 5)
}
}
};
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Xunit;
using StyleCop.Analyzers.DocumentationRules;
using TestHelper;
using Xunit;

/// <summary>
/// This class contains unit tests for <see cref="SA1603DocumentationMustContainValidXml"/>-
Expand Down Expand Up @@ -65,23 +64,8 @@ public async Task TestElementStartTagSkippedToken()
/// <summary=></summary>
public class Foo { }";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "The documentation header is composed of invalid XML: Invalid token.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 2, 13)
}
}
};
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}

Expand All @@ -92,23 +76,8 @@ public async Task TestElementEndTagSkippedToken()
/// <summary></summary=>
public class Foo { }";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "The documentation header is composed of invalid XML: Invalid token.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 2, 23)
}
}
};
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 23);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}

Expand All @@ -119,23 +88,8 @@ public async Task TestEmptyElementSkippedToken()
/// <summary=/>
public class Foo { }";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "The documentation header is composed of invalid XML: Invalid token.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 2, 13)
}
}
};
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}

Expand All @@ -146,24 +100,11 @@ public async Task TestElementTagsNotMatching()
/// <summary>a</sumary>
public class Foo { }";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "The documentation header is composed of invalid XML: The 'summary' start tag does not match the end tag of 'sumary'.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 2, 5),
new DiagnosticResultLocation("Test0.cs", 2, 15)
}
}
};
DiagnosticResult expected =
this.CSharpDiagnostic().WithArguments("The 'summary' start tag does not match the end tag of 'sumary'.")
.WithLocation(2, 5)
.WithLocation(2, 15);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}

Expand All @@ -174,23 +115,10 @@ public async Task TestElementMissingEndTag()
/// <summary>a
public class Foo { }";

DiagnosticResult[] expected;

expected =
new[]
{
new DiagnosticResult
{
Id = this.DiagnosticId,
Message = "The documentation header is composed of invalid XML: The XML tag 'summary' is not closed.",
Severity = DiagnosticSeverity.Warning,
Locations =
new[]
{
new DiagnosticResultLocation("Test0.cs", 2, 5)
}
}
};
DiagnosticResult expected =
this.CSharpDiagnostic().WithArguments("The XML tag 'summary' is not closed.")
.WithLocation(2, 5);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None);
}

Expand Down
Loading