-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GH-11] - adding tests for code action titles
- Loading branch information
Showing
26 changed files
with
366 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...zers.Shared/CodeFixProviders/AbstractNonVirtualSetupSuppressDiagnosticsCodeFixProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Immutable; | ||
|
||
namespace NSubstitute.Analyzers.Shared.CodeFixProviders | ||
{ | ||
internal class AbstractNonVirtualSetupSuppressDiagnosticsCodeFixProvider : AbstractSuppressDiagnosticsCodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(DiagnosticIdentifiers.NonVirtualSetupSpecification); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...s/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/CSharpCodeFixActionsVerifier.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using NSubstitute.Analyzers.Tests.Shared.CodeFixProviders; | ||
|
||
namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests | ||
{ | ||
public abstract class CSharpCodeFixActionsVerifier : CodeFixCodeActionsVerifier | ||
{ | ||
protected override string Language { get; } = LanguageNames.CSharp; | ||
|
||
protected override CompilationOptions GetCompilationOptions() | ||
{ | ||
return new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...sDiagnosticsCodeFixProviderTests/NonVirtualSetupSuppressDiagnosticsCodeFixActionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using NSubstitute.Analyzers.CSharp.CodeFixProviders; | ||
using NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers; | ||
using Xunit; | ||
|
||
namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.NonVirtualSetupAnalyzerSuppressDiagnosticsCodeFixProviderTests | ||
{ | ||
public class NonVirtualSetupSuppressDiagnosticsCodeFixActionsTests : CSharpCodeFixActionsVerifier | ||
{ | ||
[Fact] | ||
public async Task CreatesCorrectCodeFixActions_ForIndexer() | ||
{ | ||
var source = @"using NSubstitute; | ||
namespace MyNamespace | ||
{ | ||
public class Foo | ||
{ | ||
public int this[int x] => 0; | ||
} | ||
public class FooTests | ||
{ | ||
public void Test() | ||
{ | ||
var substitute = NSubstitute.Substitute.For<Foo>(); | ||
substitute[1].Returns(1); | ||
} | ||
} | ||
}"; | ||
await VerifyCodeActions(source, new[] | ||
{ | ||
"Suppress NS001 for indexer this[] in nsubstitute.json", | ||
"Suppress NS001 for class Foo in nsubstitute.json", | ||
"Suppress NS001 for namespace MyNamespace in nsubstitute.json" | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task CreatesCorrectCodeFixActions_ForProperty() | ||
{ | ||
var source = @"using NSubstitute; | ||
namespace MyNamespace | ||
{ | ||
public class Foo | ||
{ | ||
public int Bar { get; } | ||
} | ||
public class FooTests | ||
{ | ||
public void Test() | ||
{ | ||
var substitute = NSubstitute.Substitute.For<Foo>(); | ||
substitute.Bar.Returns(1); | ||
} | ||
} | ||
}"; | ||
await VerifyCodeActions(source, new[] | ||
{ | ||
"Suppress NS001 for property Bar in nsubstitute.json", | ||
"Suppress NS001 for class Foo in nsubstitute.json", | ||
"Suppress NS001 for namespace MyNamespace in nsubstitute.json" | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task CreatesCorrectCodeFixActions_ForMethod() | ||
{ | ||
var source = @"using NSubstitute; | ||
namespace MyNamespace | ||
{ | ||
public class Foo | ||
{ | ||
public int Bar() | ||
{ | ||
return 2; | ||
} | ||
} | ||
public class FooTests | ||
{ | ||
public void Test() | ||
{ | ||
var substitute = NSubstitute.Substitute.For<Foo>(); | ||
substitute.Bar().Returns(1); | ||
} | ||
} | ||
}"; | ||
await VerifyCodeActions(source, new[] | ||
{ | ||
"Suppress NS001 for method Bar in nsubstitute.json", | ||
"Suppress NS001 for class Foo in nsubstitute.json", | ||
"Suppress NS001 for namespace MyNamespace in nsubstitute.json" | ||
}); | ||
} | ||
|
||
protected override DiagnosticAnalyzer GetDiagnosticAnalyzer() | ||
{ | ||
return new NonVirtualSetupAnalyzer(); | ||
} | ||
|
||
protected override CodeFixProvider GetCodeFixProvider() | ||
{ | ||
return new NonVirtualSetupSuppressDiagnosticsCodeFixProvider(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.