private async Task <bool> IsProblematicParameterTest([CallerMemberName] string testMethod = "") { var testSource = MvcTestSource.Read(GetType().Name, testMethod); var project = DiagnosticProject.Create(GetType().Assembly, new[] { testSource.Source }); var compilation = await project.GetCompilationAsync(); var modelType = compilation.GetTypeByMetadataName($"Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzerTestFiles.{testMethod}"); var method = (IMethodSymbol)modelType.GetMembers("ActionMethod").First(); var parameter = method.Parameters[0]; Assert.True(TopLevelParameterNameAnalyzer.SymbolCache.TryCreate(compilation, out var symbolCache)); var result = TopLevelParameterNameAnalyzer.IsProblematicParameter(symbolCache, parameter); return(result); }
public async Task IsProblematicParameter_ReturnsFalse_ForSimpleTypes() { var testName = nameof(IsProblematicParameter_ReturnsFalse_ForSimpleTypes); var testSource = MvcTestSource.Read(GetType().Name, testName); var project = DiagnosticProject.Create(GetType().Assembly, new[] { testSource.Source }); var compilation = await project.GetCompilationAsync(); var modelType = compilation.GetTypeByMetadataName($"Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzerTestFiles.{testName}"); var method = (IMethodSymbol)modelType.GetMembers("ActionMethod").First(); Assert.True(TopLevelParameterNameAnalyzer.SymbolCache.TryCreate(compilation, out var symbolCache)); Assert.Collection( method.Parameters, p => Assert.False(TopLevelParameterNameAnalyzer.IsProblematicParameter(symbolCache, p)), p => Assert.False(TopLevelParameterNameAnalyzer.IsProblematicParameter(symbolCache, p)), p => Assert.False(TopLevelParameterNameAnalyzer.IsProblematicParameter(symbolCache, p)), p => Assert.False(TopLevelParameterNameAnalyzer.IsProblematicParameter(symbolCache, p)), p => Assert.False(TopLevelParameterNameAnalyzer.IsProblematicParameter(symbolCache, p))); }