From 27d36be57c7f365c467570a77274b0c713d3ffd7 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 27 Nov 2015 13:44:49 -0600 Subject: [PATCH] Add tests for containing type and contained member conflicts --- .../NamingRules/SA1302UnitTests.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs index b0ff7c17b..8008d768a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs @@ -208,6 +208,27 @@ public interface IFoo { }"; await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false); } + [Fact] + public async Task TestInterfaceDeclarationDoesNotStartWithIWithMemberConflictAsync() + { + string testCode = @" +public interface Foo +{ + int IFoo { get; } +}"; + string fixedCode = @" +public interface IFoo1 +{ + int IFoo { get; } +}"; + + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(2, 18); + + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false); + } + [Fact] public async Task TestNestedInterfaceDeclarationDoesNotStartWithIWithConflictAsync() { @@ -237,6 +258,31 @@ public interface IFoo { } await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false); } + [Fact] + public async Task TestNestedInterfaceDeclarationDoesNotStartWithIWithContainingTypeConflictAsync() + { + string testCode = @" +public class IFoo +{ + public interface Foo + { + } +}"; + string fixedCode = @" +public class IFoo +{ + public interface IFoo1 + { + } +}"; + + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 22); + + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false); + } + [Fact] public async Task TestNestedInterfaceDeclarationDoesNotStartWithIWithNonInterfaceConflictAsync() {