Skip to content

Commit

Permalink
Add additional tests for DotNetAnalyzers#1829
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Nov 26, 2015
1 parent 6877292 commit 3cb77ce
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ public async Task VerifyWrongFileNameMultipleExtensionsAsync(string typeKeyword)
await this.VerifyRenameAsync(testCode, "WrongFileName.svc.cs", "TestType.svc.cs", CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that a wrong file name with no extension is correctly reported and fixed. This is a regression test
/// for DotNetAnalyzers/StyleCopAnalyzers#1829.
/// </summary>
/// <param name="typeKeyword">The type keyword to use during the test.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Theory]
[MemberData(nameof(TypeKeywords))]
public async Task VerifyWrongFileNameNoExtensionAsync(string typeKeyword)
{
var testCode = $@"namespace TestNameSpace
{{
public {typeKeyword} TestType
{{
}}
}}
";

var fixedCode = $@"namespace TestNamespace
{{
public {typeKeyword} TestType
{{
}}
}}
";

var expectedDiagnostic = this.CSharpDiagnostic().WithLocation("WrongFileName", 3, 13 + typeKeyword.Length);
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None, "WrongFileName").ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None, "TestType").ConfigureAwait(false);
await this.VerifyRenameAsync(testCode, "WrongFileName", "TestType", CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the file name is not case sensitive.
/// </summary>
Expand Down Expand Up @@ -234,6 +266,40 @@ public async Task VerifyMetadataNamingConventionForGenericTypeAsync(string typeK
await this.VerifyRenameAsync(testCode, "TestType.cs", "TestType`3.cs", CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that a wrong metadata file name with multiple extensions is correctly reported and fixed. This is a
/// regression test for DotNetAnalyzers/StyleCopAnalyzers#1829.
/// </summary>
/// <param name="typeKeyword">The type keyword to use during the test.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Theory]
[MemberData(nameof(TypeKeywords))]
public async Task VerifyMetadataNamingConventionForGenericTypeMultipleExtensionsAsync(string typeKeyword)
{
this.useMetadataSettings = true;

var testCode = $@"namespace TestNameSpace
{{
public {typeKeyword} TestType<T>
{{
}}
}}
";

var fixedCode = $@"namespace TestNamespace
{{
public {typeKeyword} TestType<T>
{{
}}
}}
";

var expectedDiagnostic = this.CSharpDiagnostic().WithLocation("TestType.svc.cs", 3, 13 + typeKeyword.Length);
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None, "TestType.svc.cs").ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None, "TestType`1.svc.cs").ConfigureAwait(false);
await this.VerifyRenameAsync(testCode, "TestType.svc.cs", "TestType`1.svc.cs", CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that no diagnostic is generated if there is no first type.
/// </summary>
Expand Down

0 comments on commit 3cb77ce

Please sign in to comment.