diff --git a/Analyzers.ruleset b/Analyzers.ruleset index d0919155..d88504ff 100644 --- a/Analyzers.ruleset +++ b/Analyzers.ruleset @@ -2,7 +2,7 @@ - + diff --git a/Directory.Build.props b/Directory.Build.props index 72fdeaad..d7072517 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,6 +7,6 @@ - + diff --git a/src/NSubstitute.Analyzers.CSharp.Vsix/NSubstitute.Analyzers.CSharp.Vsix.csproj b/src/NSubstitute.Analyzers.CSharp.Vsix/NSubstitute.Analyzers.CSharp.Vsix.csproj index c2742552..59d113fd 100644 --- a/src/NSubstitute.Analyzers.CSharp.Vsix/NSubstitute.Analyzers.CSharp.Vsix.csproj +++ b/src/NSubstitute.Analyzers.CSharp.Vsix/NSubstitute.Analyzers.CSharp.Vsix.csproj @@ -1,13 +1,11 @@  - net461 NSubstitute.Analyzers.CSharp NSubstitute.Analyzers.CSharp.Vsix - false false @@ -17,35 +15,26 @@ false Roslyn - False - - + - - - - - - - \ No newline at end of file diff --git a/src/NSubstitute.Analyzers.CSharp/CodeFixProviders/SubstituteForInternalMemberCodeFixProvider.cs b/src/NSubstitute.Analyzers.CSharp/CodeFixProviders/SubstituteForInternalMemberCodeFixProvider.cs new file mode 100644 index 00000000..dd92a736 --- /dev/null +++ b/src/NSubstitute.Analyzers.CSharp/CodeFixProviders/SubstituteForInternalMemberCodeFixProvider.cs @@ -0,0 +1,43 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers; +using NSubstitute.Analyzers.Shared.CodeFixProviders; +using NSubstitute.Analyzers.Shared.DiagnosticAnalyzers; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +namespace NSubstitute.Analyzers.CSharp.CodeFixProviders +{ + [ExportCodeFixProvider(LanguageNames.CSharp)] + internal class SubstituteForInternalMemberCodeFixProvider : AbstractSubstituteForInternalMemberCodeFixProvider + { + protected override AbstractSubstituteProxyAnalysis GetSubstituteProxyAnalysis() + { + return new SubstituteProxyAnalysis(); + } + + protected override CompilationUnitSyntax AppendInternalsVisibleToAttribute(CompilationUnitSyntax compilationUnitSyntax) + { + return compilationUnitSyntax.AddAttributeLists( + AttributeList( + AttributeTargetSpecifier( + Token(SyntaxKind.AssemblyKeyword)), + SingletonSeparatedList( + Attribute( + QualifiedName( + QualifiedName( + QualifiedName( + IdentifierName("System"), + IdentifierName("Runtime")), + IdentifierName("CompilerServices")), + IdentifierName("InternalsVisibleTo")), + AttributeArgumentList( + SingletonSeparatedList( + AttributeArgument( + LiteralExpression( + SyntaxKind.StringLiteralExpression, + Literal("DynamicProxyGenAssembly2"))))))))); + } + } +} \ No newline at end of file diff --git a/src/NSubstitute.Analyzers.Shared/CodeFixProviders/AbstractSubstituteForInternalMemberCodeFixProvider.cs b/src/NSubstitute.Analyzers.Shared/CodeFixProviders/AbstractSubstituteForInternalMemberCodeFixProvider.cs new file mode 100644 index 00000000..1a82a4fe --- /dev/null +++ b/src/NSubstitute.Analyzers.Shared/CodeFixProviders/AbstractSubstituteForInternalMemberCodeFixProvider.cs @@ -0,0 +1,82 @@ +using System.Collections.Immutable; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeActions; +using Microsoft.CodeAnalysis.CodeFixes; +using NSubstitute.Analyzers.Shared.DiagnosticAnalyzers; + +namespace NSubstitute.Analyzers.Shared.CodeFixProviders +{ + internal abstract class AbstractSubstituteForInternalMemberCodeFixProvider : AbstractSuppressDiagnosticsCodeFixProvider + where TInvocationExpressionSyntax : SyntaxNode + where TExpressionSyntax : SyntaxNode + where TCompilationUnitSyntax : SyntaxNode + { + public override ImmutableArray FixableDiagnosticIds { get; } = ImmutableArray.Create(DiagnosticIdentifiers.SubstituteForInternalMember); + + public override async Task RegisterCodeFixesAsync(CodeFixContext context) + { + var diagnostic = context.Diagnostics.FirstOrDefault(diag => diag.Descriptor.Id == DiagnosticIdentifiers.SubstituteForInternalMember); + if (diagnostic == null) + { + return; + } + + var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); + + var findNode = root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true); + if (!(findNode is TInvocationExpressionSyntax invocationExpression)) + { + return; + } + + var syntaxReference = await GetDeclaringSyntaxReference(context, invocationExpression); + + if (syntaxReference == null) + { + return; + } + + var syntaxNode = await syntaxReference.GetSyntaxAsync(); + var document = context.Document.Project.Solution.GetDocument(syntaxNode.SyntaxTree); + var compilationUnitSyntax = FindCompilationUnitSyntax(syntaxNode); + + if (compilationUnitSyntax == null) + { + return; + } + + var codeAction = CodeAction.Create("Add InternalsVisibleTo attribute", token => CreateChangedDocument(token, compilationUnitSyntax, document), nameof(AbstractSubstituteForInternalMemberCodeFixProvider)); + context.RegisterCodeFix(codeAction, diagnostic); + } + + protected abstract AbstractSubstituteProxyAnalysis GetSubstituteProxyAnalysis(); + + protected abstract TCompilationUnitSyntax AppendInternalsVisibleToAttribute(TCompilationUnitSyntax compilationUnitSyntax); + + private async Task CreateChangedDocument(CancellationToken cancellationToken, TCompilationUnitSyntax compilationUnitSyntax, Document document) + { + var updatedCompilationUnitSyntax = AppendInternalsVisibleToAttribute(compilationUnitSyntax); + var root = await document.GetSyntaxRootAsync(cancellationToken); + var replaceNode = root.ReplaceNode(compilationUnitSyntax, updatedCompilationUnitSyntax); + return document.WithSyntaxRoot(replaceNode); + } + + private async Task GetDeclaringSyntaxReference(CodeFixContext context, TInvocationExpressionSyntax invocationExpression) + { + var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken); + var methodSymbol = semanticModel.GetSymbolInfo(invocationExpression).Symbol as IMethodSymbol; + var proxyAnalysis = GetSubstituteProxyAnalysis(); + var actualProxyTypeSymbol = proxyAnalysis.GetActualProxyTypeSymbol(semanticModel, invocationExpression, methodSymbol); + var syntaxReference = actualProxyTypeSymbol.DeclaringSyntaxReferences.FirstOrDefault(); + return syntaxReference; + } + + private TCompilationUnitSyntax FindCompilationUnitSyntax(SyntaxNode syntaxNode) + { + return syntaxNode.Parent.Ancestors().OfType().LastOrDefault(); + } + } +} \ No newline at end of file diff --git a/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs b/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs index fb380224..9ffb9fe1 100644 --- a/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs +++ b/src/NSubstitute.Analyzers.Shared/DiagnosticAnalyzers/AbstractSubstituteProxyAnalysis.cs @@ -11,21 +11,31 @@ internal abstract class AbstractSubstituteProxyAnalysis substituteContext) { - var proxies = GetProxySymbols(substituteContext).ToList(); + return GetActualProxyTypeSymbol(substituteContext.SyntaxNodeAnalysisContext.SemanticModel, substituteContext.InvocationExpression, substituteContext.MethodSymbol); + } + + public ImmutableArray GetProxySymbols(SubstituteContext substituteContext) + { + return GetProxySymbols(substituteContext.SyntaxNodeAnalysisContext.SemanticModel, substituteContext.InvocationExpression, substituteContext.MethodSymbol); + } + + public ITypeSymbol GetActualProxyTypeSymbol(SemanticModel semanticModel, TInvocationExpressionSyntax invocationExpressionSyntax, IMethodSymbol methodSymbol) + { + var proxies = GetProxySymbols(semanticModel, invocationExpressionSyntax, methodSymbol).ToList(); var classSymbol = proxies.FirstOrDefault(symbol => symbol.TypeKind == TypeKind.Class); return classSymbol ?? proxies.FirstOrDefault(); } - public ImmutableArray GetProxySymbols(SubstituteContext substituteContext) + public ImmutableArray GetProxySymbols(SemanticModel semanticModel, TInvocationExpressionSyntax invocationExpressionSyntax, IMethodSymbol methodSymbol) { - if (substituteContext.MethodSymbol.IsGenericMethod) + if (methodSymbol.IsGenericMethod) { - return substituteContext.MethodSymbol.TypeArguments; + return methodSymbol.TypeArguments; } - var arrayParameters = GetArrayInitializerArguments(substituteContext.InvocationExpression)?.ToList(); + var arrayParameters = GetArrayInitializerArguments(invocationExpressionSyntax)?.ToList(); if (arrayParameters == null) { @@ -34,7 +44,7 @@ public ImmutableArray GetProxySymbols(SubstituteContext - substituteContext.SyntaxNodeAnalysisContext.SemanticModel + semanticModel .GetTypeInfo(exp.DescendantNodes().First())) .Where(model => model.Type != null) .Select(model => model.Type) diff --git a/src/NSubstitute.Analyzers.VisualBasic.Vsix/NSubstitute.Analyzers.VisualBasic.Vsix.csproj b/src/NSubstitute.Analyzers.VisualBasic.Vsix/NSubstitute.Analyzers.VisualBasic.Vsix.csproj index 032d662f..70a6bf7d 100644 --- a/src/NSubstitute.Analyzers.VisualBasic.Vsix/NSubstitute.Analyzers.VisualBasic.Vsix.csproj +++ b/src/NSubstitute.Analyzers.VisualBasic.Vsix/NSubstitute.Analyzers.VisualBasic.Vsix.csproj @@ -1,13 +1,11 @@  - net461 NSubstitute.Analyzers.VisualBasic NSubstitute.Analyzers.VisualBasic.Vsix - false false @@ -17,35 +15,26 @@ false Roslyn - False - - + - - - - - - - \ No newline at end of file diff --git a/src/NSubstitute.Analyzers.VisualBasic/CodeFixProviders/SubstituteForInternalMemberCodeFixProvider.cs b/src/NSubstitute.Analyzers.VisualBasic/CodeFixProviders/SubstituteForInternalMemberCodeFixProvider.cs new file mode 100644 index 00000000..81b5fb1b --- /dev/null +++ b/src/NSubstitute.Analyzers.VisualBasic/CodeFixProviders/SubstituteForInternalMemberCodeFixProvider.cs @@ -0,0 +1,39 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.VisualBasic; +using Microsoft.CodeAnalysis.VisualBasic.Syntax; +using NSubstitute.Analyzers.Shared.CodeFixProviders; +using NSubstitute.Analyzers.Shared.DiagnosticAnalyzers; +using NSubstitute.Analyzers.VisualBasic.DiagnosticAnalyzers; +using static Microsoft.CodeAnalysis.VisualBasic.SyntaxFactory; + +namespace NSubstitute.Analyzers.VisualBasic.CodeFixProviders +{ + [ExportCodeFixProvider(LanguageNames.VisualBasic)] + internal class SubstituteForInternalMemberCodeFixProvider : AbstractSubstituteForInternalMemberCodeFixProvider + { + protected override AbstractSubstituteProxyAnalysis GetSubstituteProxyAnalysis() + { + return new SubstituteProxyAnalysis(); + } + + protected override CompilationUnitSyntax AppendInternalsVisibleToAttribute(CompilationUnitSyntax compilationUnitSyntax) + { + return compilationUnitSyntax.AddAttributes( + AttributesStatement(SingletonList( + AttributeList(SingletonSeparatedList(Attribute( + AttributeTarget(Token(SyntaxKind.AssemblyKeyword)), + QualifiedName( + QualifiedName( + QualifiedName( + IdentifierName("System"), + IdentifierName("Runtime")), + IdentifierName("CompilerServices")), + IdentifierName("InternalsVisibleTo")), + ArgumentList(SingletonSeparatedList(SimpleArgument( + LiteralExpression( + SyntaxKind.StringLiteralExpression, + Literal("DynamicProxyGenAssembly2"))))))))))); + } + } +} \ No newline at end of file diff --git a/src/NSubstitute.Analyzers.VisualBasic/DiagnosticAnalyzers/NonVirtualSetupWhenAnalyzer.cs b/src/NSubstitute.Analyzers.VisualBasic/DiagnosticAnalyzers/NonVirtualSetupWhenAnalyzer.cs index d4da02f8..085a76d1 100644 --- a/src/NSubstitute.Analyzers.VisualBasic/DiagnosticAnalyzers/NonVirtualSetupWhenAnalyzer.cs +++ b/src/NSubstitute.Analyzers.VisualBasic/DiagnosticAnalyzers/NonVirtualSetupWhenAnalyzer.cs @@ -50,16 +50,16 @@ private IEnumerable GetExpressionsForAnalysys(SyntaxNodeAnalysisCont } break; - case UnaryExpressionSyntax unaryExpressionSyntax: - foreach (var syntaxNode in GetExpressionsForAnalysys(syntaxNodeContext, unaryExpressionSyntax.Operand)) + case UnaryExpressionSyntax unaryExpressionSyntax: + foreach (var syntaxNode in GetExpressionsForAnalysys(syntaxNodeContext, unaryExpressionSyntax.Operand)) { yield return syntaxNode; } - break; - case IdentifierNameSyntax identifierNameSyntax: - var symbol = syntaxNodeContext.SemanticModel.GetSymbolInfo(identifierNameSyntax); - if (symbol.Symbol != null && symbol.Symbol.Locations.Any()) + break; + case IdentifierNameSyntax identifierNameSyntax: + var symbol = syntaxNodeContext.SemanticModel.GetSymbolInfo(identifierNameSyntax); + if (symbol.Symbol != null && symbol.Symbol.Locations.Any()) { var location = symbol.Symbol.Locations.First(); var syntaxNode = location.SourceTree.GetRoot().FindNode(location.SourceSpan); @@ -77,7 +77,7 @@ private IEnumerable GetExpressionsForAnalysys(SyntaxNodeAnalysisCont } } - break; + break; } if (body == null) diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsGenericMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsGenericMethodTests.cs new file mode 100644 index 00000000..4d105266 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsGenericMethodTests.cs @@ -0,0 +1,206 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using NSubstitute.Analyzers.Shared; +using NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.SubstituteAnalyzerTests; +using NSubstitute.Analyzers.Tests.Shared.DiagnosticAnalyzers; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class ForAsGenericMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"using System.Reflection; +using NSubstitute; +[assembly: AssemblyVersion(""1.0.0"")] +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } +}"; + var newSource = @"using System.Reflection; +using NSubstitute; +[assembly: AssemblyVersion(""1.0.0"")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + public class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(); + } + } +}"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsNonGenericMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsNonGenericMethodTests.cs new file mode 100644 index 00000000..694483e8 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsNonGenericMethodTests.cs @@ -0,0 +1,206 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using NSubstitute.Analyzers.Shared; +using NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.SubstituteAnalyzerTests; +using NSubstitute.Analyzers.Tests.Shared.DiagnosticAnalyzers; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class ForAsNonGenericMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo)}, null); + } + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo)}, null); + } + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo)}, null); + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"using System.Reflection; +using NSubstitute; +[assembly: AssemblyVersion(""1.0.0"")] +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo)}, null); + } + } +}"; + var newSource = @"using System.Reflection; +using NSubstitute; +[assembly: AssemblyVersion(""1.0.0"")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo.Bar)}, null); + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo.Bar)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + public class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.For(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForPartsOfMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForPartsOfMethodTests.cs new file mode 100644 index 00000000..c098bc62 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/ForPartsOfMethodTests.cs @@ -0,0 +1,206 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using NSubstitute.Analyzers.Shared; +using NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.SubstituteAnalyzerTests; +using NSubstitute.Analyzers.Tests.Shared.DiagnosticAnalyzers; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class ForPartsOfMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"using System.Reflection; +using NSubstitute; +[assembly: AssemblyVersion(""1.0.0"")] +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } +}"; + var newSource = @"using System.Reflection; +using NSubstitute; +[assembly: AssemblyVersion(""1.0.0"")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } +}"; + var newSource = @"using NSubstitute; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"using NSubstitute; +namespace MyNamespace +{ + public class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = Substitute.ForPartsOf(); + } + } +}"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreateMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreateMethodTests.cs new file mode 100644 index 00000000..d35d33dd --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreateMethodTests.cs @@ -0,0 +1,206 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using NSubstitute.Analyzers.Shared; +using NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.SubstituteAnalyzerTests; +using NSubstitute.Analyzers.Tests.Shared.DiagnosticAnalyzers; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class SubstituteFactoryCreateMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + } + } + } +}"; + var newSource = @"using NSubstitute.Core; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + } + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + } + } +}"; + var newSource = @"using NSubstitute.Core; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"using System.Reflection; +using NSubstitute.Core; +[assembly: AssemblyVersion(""1.0.0"")] +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + } + } +}"; + var newSource = @"using System.Reflection; +using NSubstitute.Core; +[assembly: AssemblyVersion(""1.0.0"")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo.Bar)}, null); + } + } +}"; + var newSource = @"using NSubstitute.Core; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo.Bar)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + public class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.Create(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreatePartialMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreatePartialMethodTests.cs new file mode 100644 index 00000000..e177f77e --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreatePartialMethodTests.cs @@ -0,0 +1,206 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using NSubstitute.Analyzers.Shared; +using NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests.SubstituteAnalyzerTests; +using NSubstitute.Analyzers.Tests.Shared.DiagnosticAnalyzers; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class SubstituteFactoryCreatePartialMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } + } +}"; + var newSource = @"using NSubstitute.Core; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } +}"; + var newSource = @"using NSubstitute.Core; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"using System.Reflection; +using NSubstitute.Core; +[assembly: AssemblyVersion(""1.0.0"")] +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } +}"; + var newSource = @"using System.Reflection; +using NSubstitute.Core; +[assembly: AssemblyVersion(""1.0.0"")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo.Bar)}, null); + } + } +}"; + var newSource = @"using NSubstitute.Core; + +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""DynamicProxyGenAssembly2"")] + +namespace MyNamespace +{ + internal class Foo + { + internal class Bar + { + + } + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo.Bar)}, null); + } + } +}"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"using NSubstitute.Core; +namespace MyNamespace +{ + public class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } +}"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixActionsTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixActionsTests.cs new file mode 100644 index 00000000..5ae10237 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixActionsTests.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Diagnostics; +using NSubstitute.Analyzers.CSharp.CodeFixProviders; +using NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers; +using NSubstitute.Analyzers.Tests.Shared.CodeFixProviders; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class SubstituteForInternalMemberCodeFixActionsTests : CSharpCodeFixActionsVerifier, ISubstituteForInternalMemberCodeFixActionsVerifier + { + [Fact] + public async Task CreatesCorrectCodeFixActions_WhenSourceForInternalType_IsAvailable() + { + var source = @"using NSubstitute.Core; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + internal class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } + } +}"; + await VerifyCodeActions(source, "Add InternalsVisibleTo attribute"); + } + + [Fact] + public async Task Does_Not_CreateCodeFixActions_WhenType_IsNotInternal() + { + var source = @"using NSubstitute.Core; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + public class Foo + { + } + + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(Foo)}, null); + } + } + } +}"; + await VerifyCodeActions(source); + } + + [Fact] + public async Task Does_Not_CreateCodeFixActions_WhenSourceForInternalType_IsNotAvailable() + { + var source = @"using NSubstitute.Core; +using ExternalNamespace; +namespace MyNamespace +{ + namespace MyInnerNamespace + { + public class FooTests + { + public void Test() + { + var substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial(new[] {typeof(InternalFoo)}, null); + } + } + } +}"; + await VerifyCodeActions(source); + } + + protected override DiagnosticAnalyzer GetDiagnosticAnalyzer() + { + return new SubstituteAnalyzer(); + } + + protected override CodeFixProvider GetCodeFixProvider() + { + return new SubstituteForInternalMemberCodeFixProvider(); + } + + protected override IEnumerable GetAdditionalMetadataReferences() + { + return new[] { GetInternalLibraryMetadataReference() }; + } + + private static PortableExecutableReference GetInternalLibraryMetadataReference() + { + var syntaxTree = CSharpSyntaxTree.ParseText($@" +using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo(""{TestProjectName}"")] +namespace ExternalNamespace +{{ + internal class InternalFoo + {{ + }} +}}"); + + var references = new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }; + var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + var compilation = CSharpCompilation.Create("Internal", new[] { syntaxTree }, references, compilationOptions); + + using (var ms = new MemoryStream()) + { + var result = compilation.Emit(ms); + + if (result.Success == false) + { + var errors = result.Diagnostics.Where(diag => diag.IsWarningAsError || diag.Severity == DiagnosticSeverity.Error); + throw new InvalidOperationException($"Internal library compilation failed: {string.Join(",", errors)}"); + } + + ms.Seek(0, SeekOrigin.Begin); + return MetadataReference.CreateFromStream(ms); + } + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixVerifier.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixVerifier.cs new file mode 100644 index 00000000..eb1ba841 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/CodeFixProviderTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixVerifier.cs @@ -0,0 +1,33 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.Diagnostics; +using NSubstitute.Analyzers.CSharp.CodeFixProviders; +using NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers; +using NSubstitute.Analyzers.Tests.Shared.CodeFixProviders; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.CSharp.CodeFixProviderTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public abstract class SubstituteForInternalMemberCodeFixVerifier : CSharpCodeFixVerifier, ISubstituteForInternalMemberCodeFixVerifier + { + public abstract Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass(); + + public abstract Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass(); + + public abstract Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty(); + + public abstract Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass(); + + public abstract Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass(); + + protected override DiagnosticAnalyzer GetDiagnosticAnalyzer() + { + return new SubstituteAnalyzer(); + } + + protected override CodeFixProvider GetCodeFixProvider() + { + return new SubstituteForInternalMemberCodeFixProvider(); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CSharpDiagnosticVerifier.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CSharpDiagnosticVerifier.cs index 4bc765eb..f4916b25 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CSharpDiagnosticVerifier.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/CSharpDiagnosticVerifier.cs @@ -1,7 +1,5 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Diagnostics; -using NSubstitute.Analyzers.Tests.Shared; using NSubstitute.Analyzers.Tests.Shared.DiagnosticAnalyzers; namespace NSubstitute.Analyzers.Tests.CSharp.DiagnosticAnalyzerTests diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs index a2545944..c69535e4 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs @@ -795,7 +795,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -836,7 +836,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -870,7 +870,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodWithGenericTypeSpecifiedTests.cs index ab2d330d..0c8e7ecd 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodWithGenericTypeSpecifiedTests.cs @@ -797,7 +797,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -838,7 +838,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -872,7 +872,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs index 15ca0c2a..4fc34967 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs @@ -798,7 +798,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -839,7 +839,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -873,7 +873,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index a85d0006..f604fe2d 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -815,7 +815,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -856,7 +856,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -890,7 +890,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs index 186b128d..070b76ba 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs @@ -797,7 +797,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -838,7 +838,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -872,7 +872,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs index 181ba003..b2eed8bb 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs @@ -797,7 +797,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -838,7 +838,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -872,7 +872,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs index b674d972..e6a240c2 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs @@ -798,7 +798,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -839,7 +839,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -873,7 +873,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs index 96c487d3..504ce095 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs @@ -819,7 +819,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using NSubstitute; + var source = @"using NSubstitute; namespace MyNamespace { @@ -860,7 +860,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -894,7 +894,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs index 5fd72376..7591e4dd 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs @@ -843,7 +843,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -886,7 +886,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -920,7 +920,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodWithGenericTypeSpecifiedTests.cs index e3f405a7..6711cc78 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodWithGenericTypeSpecifiedTests.cs @@ -844,7 +844,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -887,7 +887,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -921,7 +921,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs index 62fa3277..b809b821 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs @@ -846,7 +846,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -889,7 +889,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -923,7 +923,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index 0530d3a8..f36f7568 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -846,7 +846,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -889,7 +889,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -923,7 +923,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs index cdaaf0de..d6a7139b 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs @@ -843,7 +843,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -886,7 +886,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -920,7 +920,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs index e8b59cff..bb91b662 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodWithGenericTypeSpecifiedTests.cs @@ -844,7 +844,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -887,7 +887,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -921,7 +921,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs index 27da9a59..68f3d677 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs @@ -846,7 +846,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -889,7 +889,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -923,7 +923,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index b691bbd8..51a9d86f 100644 --- a/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.CSharp/DiagnosticAnalyzerTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -846,7 +846,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"using System; + var source = @"using System; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -889,7 +889,7 @@ public void Test() } }"; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -923,7 +923,7 @@ public void Test() } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/ISubstituteForInternalMemberCodeFixActionsVerifier.cs b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/ISubstituteForInternalMemberCodeFixActionsVerifier.cs new file mode 100644 index 00000000..d757f437 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/ISubstituteForInternalMemberCodeFixActionsVerifier.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; + +namespace NSubstitute.Analyzers.Tests.Shared.CodeFixProviders +{ + public interface ISubstituteForInternalMemberCodeFixActionsVerifier + { + Task CreatesCorrectCodeFixActions_WhenSourceForInternalType_IsAvailable(); + + Task Does_Not_CreateCodeFixActions_WhenType_IsNotInternal(); + + Task Does_Not_CreateCodeFixActions_WhenSourceForInternalType_IsNotAvailable(); + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/ISubstituteForInternalMemberCodeFixVerifier.cs b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/ISubstituteForInternalMemberCodeFixVerifier.cs new file mode 100644 index 00000000..a9401cd2 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.Shared/CodeFixProviders/ISubstituteForInternalMemberCodeFixVerifier.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; + +namespace NSubstitute.Analyzers.Tests.Shared.CodeFixProviders +{ + public interface ISubstituteForInternalMemberCodeFixVerifier + { + Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass(); + + Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass(); + + Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty(); + + Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass(); + + Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass(); + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsGenericMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsGenericMethodTests.cs new file mode 100644 index 00000000..80024043 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsGenericMethodTests.cs @@ -0,0 +1,169 @@ +using System.Threading.Tasks; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class ForAsGenericMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo)() + End Sub + End Class + End Namespace +End Namespace +"; + var newSource = @"Imports NSubstitute + + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo)() + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo)() + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"Imports System.Reflection +Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo)() + End Sub + End Class +End Namespace +"; + var newSource = @"Imports System.Reflection +Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo.Bar)() + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.For(Of Foo.Bar)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Public Class Foo + End Class + + Public Class FooTests + Public Sub Test() + NSubstitute.Substitute.For(Of Foo)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, oldSource); + } + } +} diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsNonGenericMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsNonGenericMethodTests.cs new file mode 100644 index 00000000..75904066 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForAsNonGenericMethodTests.cs @@ -0,0 +1,169 @@ +using System.Threading.Tasks; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class ForAsNonGenericMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"Imports System.Reflection +Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports System.Reflection +Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo.Bar)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo.Bar)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Public Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.[For]({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForPartsOfMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForPartsOfMethodTests.cs new file mode 100644 index 00000000..8995cdda --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/ForPartsOfMethodTests.cs @@ -0,0 +1,169 @@ +using System.Threading.Tasks; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class ForPartsOfMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo)() + End Sub + End Class + End Namespace +End Namespace +"; + var newSource = @"Imports NSubstitute + + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo)() + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo)() + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"Imports System.Reflection +Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo)() + End Sub + End Class +End Namespace +"; + var newSource = @"Imports System.Reflection +Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo.Bar)() + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = NSubstitute.Substitute.ForPartsOf(Of Foo.Bar)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Public Class Foo + End Class + + Public Class FooTests + Public Sub Test() + NSubstitute.Substitute.ForPartsOf(Of Foo)() + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreateMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreateMethodTests.cs new file mode 100644 index 00000000..eaf6e6b3 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreateMethodTests.cs @@ -0,0 +1,169 @@ +using System.Threading.Tasks; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class SubstituteFactoryCreateMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"Imports System.Reflection +Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports System.Reflection +Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo.Bar)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo.Bar)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Public Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.Create({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreatePartialMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreatePartialMethodTests.cs new file mode 100644 index 00000000..be54db5b --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteFactoryCreatePartialMethodTests.cs @@ -0,0 +1,171 @@ +using System.Threading.Tasks; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class SubstituteFactoryCreatePartialMethodTests : SubstituteForInternalMemberCodeFixVerifier + { + [Fact] + public override async Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty() + { + var oldSource = @"Imports System.Reflection +Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports System.Reflection +Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo.Bar)}, Nothing) + End Sub + End Class +End Namespace +"; + var newSource = @"Imports NSubstitute.Core + + +Namespace MyNamespace + Friend Class Foo + Friend Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo.Bar)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, newSource); + } + + [Fact] + public override async Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass() + { + var oldSource = @"Imports NSubstitute.Core + +Namespace MyNamespace + Public Class Foo + Public Class Bar + End Class + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class +End Namespace +"; + await VerifyFix(oldSource, oldSource); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixActionsTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixActionsTests.cs new file mode 100644 index 00000000..c3834b63 --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixActionsTests.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.VisualBasic; +using NSubstitute.Analyzers.Tests.Shared.CodeFixProviders; +using NSubstitute.Analyzers.VisualBasic.CodeFixProviders; +using NSubstitute.Analyzers.VisualBasic.DiagnosticAnalyzers; +using Xunit; + +namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public class SubstituteForInternalMemberCodeFixActionsTests : VisualBasicCodeFixActionsVerifier, ISubstituteForInternalMemberCodeFixActionsVerifier + { + [Fact] + public async Task CreatesCorrectCodeFixActions_WhenSourceForInternalType_IsAvailable() + { + var source = @"Imports NSubstitute.Core + +Namespace MyNamespace + Namespace MyInnerNamespace + Friend Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyCodeActions(source, "Add InternalsVisibleTo attribute"); + } + + [Fact] + public async Task Does_Not_CreateCodeFixActions_WhenType_IsNotInternal() + { + var source = @"Imports NSubstitute.Core + +Namespace MyNamespace + Namespace MyInnerNamespace + Public Class Foo + End Class + + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(Foo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyCodeActions(source); + } + + [Fact] + public async Task Does_Not_CreateCodeFixActions_WhenSourceForInternalType_IsNotAvailable() + { + var source = @"Imports NSubstitute.Core +Imports ExternalNamespace + +Namespace MyNamespace + Namespace MyInnerNamespace + Public Class FooTests + Public Sub Test() + Dim substitute = SubstitutionContext.Current.SubstituteFactory.CreatePartial({GetType(InternalFoo)}, Nothing) + End Sub + End Class + End Namespace +End Namespace +"; + await VerifyCodeActions(source); + } + + protected override DiagnosticAnalyzer GetDiagnosticAnalyzer() + { + return new SubstituteAnalyzer(); + } + + protected override CodeFixProvider GetCodeFixProvider() + { + return new SubstituteForInternalMemberCodeFixProvider(); + } + + protected override IEnumerable GetAdditionalMetadataReferences() + { + return new[] { GetInternalLibraryMetadataReference() }; + } + + private static PortableExecutableReference GetInternalLibraryMetadataReference() + { + var syntaxTree = VisualBasicSyntaxTree.ParseText($@" +Imports System.Runtime.CompilerServices + + +Namespace ExternalNamespace + Friend Class InternalFoo + End Class +End Namespace +"); + + var references = new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }; + var compilationOptions = new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + var compilation = VisualBasicCompilation.Create("Internal", new[] { syntaxTree }, references, compilationOptions); + + using (var ms = new MemoryStream()) + { + var result = compilation.Emit(ms); + + if (result.Success == false) + { + var errors = result.Diagnostics.Where(diag => diag.IsWarningAsError || diag.Severity == DiagnosticSeverity.Error); + throw new InvalidOperationException($"Internal library compilation failed: {string.Join(",", errors)}"); + } + + ms.Seek(0, SeekOrigin.Begin); + return MetadataReference.CreateFromStream(ms); + } + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixVerifier.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixVerifier.cs new file mode 100644 index 00000000..6324926a --- /dev/null +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/CodeFixProvidersTests/SubstituteForInternalMemberCodeFixProviderTests/SubstituteForInternalMemberCodeFixVerifier.cs @@ -0,0 +1,32 @@ +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.Diagnostics; +using NSubstitute.Analyzers.Tests.Shared.CodeFixProviders; +using NSubstitute.Analyzers.VisualBasic.CodeFixProviders; +using NSubstitute.Analyzers.VisualBasic.DiagnosticAnalyzers; + +namespace NSubstitute.Analyzers.Tests.VisualBasic.CodeFixProvidersTests.SubstituteForInternalMemberCodeFixProviderTests +{ + public abstract class SubstituteForInternalMemberCodeFixVerifier : VisualBasicCodeFixVerifier, ISubstituteForInternalMemberCodeFixVerifier + { + public abstract Task AppendsInternalsVisibleTo_ToTopLevelCompilationUnit_WhenUsedWithInternalClass(); + + public abstract Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass(); + + public abstract Task AppendsInternalsVisibleTo_WhenUsedWithInternalClass_AndArgumentListNotEmpty(); + + public abstract Task AppendsInternalsVisibleTo_WhenUsedWithNestedInternalClass(); + + public abstract Task DoesNot_AppendsInternalsVisibleTo_WhenUsedWithPublicClass(); + + protected override DiagnosticAnalyzer GetDiagnosticAnalyzer() + { + return new SubstituteAnalyzer(); + } + + protected override CodeFixProvider GetCodeFixProvider() + { + return new SubstituteForInternalMemberCodeFixProvider(); + } + } +} \ No newline at end of file diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs index 9b8d290d..924912d2 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsExtensionMethodTests.cs @@ -802,7 +802,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports NSubstitute + var source = @"Imports NSubstitute Namespace MyNamespace Public Class Foo @@ -848,7 +848,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -882,7 +882,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs index bf2e2703..769d4460 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodTests.cs @@ -807,7 +807,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports NSubstitute + var source = @"Imports NSubstitute Namespace MyNamespace Public Class Foo @@ -853,7 +853,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -887,7 +887,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index 3381d8bd..57fd9d19 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -824,7 +824,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports NSubstitute + var source = @"Imports NSubstitute Namespace MyNamespace Public Class Foo @@ -870,7 +870,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -904,7 +904,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs index d0e86f75..d95f05fd 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsExtensionMethodTests.cs @@ -802,7 +802,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports NSubstitute + var source = @"Imports NSubstitute Namespace MyNamespace Public Class Foo @@ -848,7 +848,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -882,7 +882,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs index 51efa26a..d71567c4 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodTests.cs @@ -807,7 +807,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports NSubstitute + var source = @"Imports NSubstitute Namespace MyNamespace Public Class Foo @@ -853,7 +853,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -887,7 +887,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs index eee6cb88..f7f26f61 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ReturnsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecified.cs @@ -824,7 +824,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports NSubstitute + var source = @"Imports NSubstitute Namespace MyNamespace Public Class Foo @@ -870,7 +870,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -904,7 +904,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs index a7a0e874..a50b0da5 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsExtensionMethodTests.cs @@ -847,7 +847,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports System + var source = @"Imports System Imports NSubstitute Imports NSubstitute.ExceptionExtensions @@ -895,7 +895,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -929,7 +929,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs index 7fbd6d7e..96054706 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodTests.cs @@ -851,7 +851,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports System + var source = @"Imports System Imports NSubstitute Imports NSubstitute.ExceptionExtensions @@ -899,7 +899,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -933,7 +933,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index 42e7af33..714bed8d 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -851,7 +851,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports System + var source = @"Imports System Imports NSubstitute Imports NSubstitute.ExceptionExtensions @@ -899,7 +899,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -933,7 +933,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs index 018bdc55..14ba1b3f 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsExtensionMethodTests.cs @@ -847,7 +847,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports System + var source = @"Imports System Imports NSubstitute Imports NSubstitute.ExceptionExtensions @@ -895,7 +895,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -929,7 +929,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs index 1f421540..6c00df03 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodTests.cs @@ -851,7 +851,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports System + var source = @"Imports System Imports NSubstitute Imports NSubstitute.ExceptionExtensions @@ -899,7 +899,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -933,7 +933,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType() diff --git a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs index d36aaa0a..2a5904e0 100644 --- a/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs +++ b/tests/NSubstitute.Analyzers.Tests.VisualBasic/DiagnosticAnalyzersTests/NonVirtualSetupAnalyzerTests/ThrowsForAnyArgsAsOrdinaryMethodWithGenericTypeSpecifiedTests.cs @@ -851,7 +851,7 @@ public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressi { Settings = AnalyzersSettings.CreateWithSuppressions("T:MyNamespace.Foo", DiagnosticIdentifiers.NonVirtualSetupSpecification); - var source = @"Imports System + var source = @"Imports System Imports NSubstitute Imports NSubstitute.ExceptionExtensions @@ -899,7 +899,7 @@ End Class End Namespace "; - var expectedDiagnostic = new[] + var expectedDiagnostic = new[] { new DiagnosticResult { @@ -933,7 +933,7 @@ End Namespace } }; - await VerifyDiagnostic(source, expectedDiagnostic); + await VerifyDiagnostic(source, expectedDiagnostic); } public override async Task ReportsNoDiagnosticsForSuppressedMember_WhenSuppressingMembersFromEntireGenericType()