示例#1
0
文件: PortCoreTests.cs 项目: aws/cta
        public async Task TestWebApiWithReferencesUsingGenerator(string version)
        {
            var solutionPath = CopySolutionFolderToTemp("WebApiWithReferences.sln", tempDir);

            AnalyzerConfiguration configuration = new AnalyzerConfiguration(LanguageOptions.CSharp)
            {
                ExportSettings =
                {
                    GenerateJsonOutput = false,
                    OutputPath         = @"/tmp/UnitTests"
                },

                MetaDataSettings =
                {
                    LiteralExpressions = true,
                    MethodInvocations  = true,
                    Annotations        = true,
                    DeclarationNodes   = true,
                    LocationData       = false,
                    ReferenceData      = true,
                    LoadBuildData      = true,
                    ElementAccess      = true,
                    MemberAccess       = true
                }
            };

            CodeAnalyzer analyzer     = CodeAnalyzerFactory.GetAnalyzer(configuration, NullLogger.Instance);
            SolutionPort solutionPort = new SolutionPort(solutionPath);

            var resultEnumerator = analyzer.AnalyzeSolutionGeneratorAsync(solutionPath).GetAsyncEnumerator();

            while (await resultEnumerator.MoveNextAsync())
            {
                using var result = resultEnumerator.Current;
                PortCoreConfiguration projectConfiguration = new PortCoreConfiguration()
                {
                    SolutionPath    = solutionPath,
                    ProjectPath     = result.ProjectResult.ProjectFilePath,
                    IsMockRun       = false,
                    UseDefaultRules = true,
                    PortCode        = true,
                    PortProject     = true,
                    TargetVersions  = new List <string> {
                        version
                    }
                };

                solutionPort.RunProject(result, projectConfiguration);
            }
            var portSolutionResult = solutionPort.GenerateResults();
            var testSolutionResult = GenerateSolutionResult(solutionPath, solutionPort.GetAnalysisResult(), portSolutionResult);

            ValidateWebApiWithReferences(testSolutionResult);
        }
示例#2
0
        public async IAsyncEnumerable <ProjectAnalysisResult> AnalyzeSolutionGeneratorAsync(string solutionFilename, List <string> projects, string targetFramework = "netcoreapp3.1")
        {
            var configuration = GetAnalyzerConfiguration();
            var analyzer      = CodeAnalyzerFactory.GetAnalyzer(configuration, _logger);

            var resultEnumerator = analyzer.AnalyzeSolutionGeneratorAsync(solutionFilename).GetAsyncEnumerator();

            try
            {
                SolutionPort solutionPort = new SolutionPort(solutionFilename);

                while (await resultEnumerator.MoveNextAsync().ConfigureAwait(false))
                {
                    var result      = resultEnumerator.Current;
                    var projectPath = result?.ProjectResult?.ProjectFilePath;
                    PortCoreConfiguration projectConfiguration = new PortCoreConfiguration()
                    {
                        ProjectPath     = projectPath,
                        UseDefaultRules = true,
                        TargetVersions  = new List <string> {
                            targetFramework
                        },
                        PortCode    = false,
                        PortProject = false
                    };

                    var projectResult = solutionPort.RunProject(result, projectConfiguration);

                    var analysisActions = AnalyzeActions(new List <string> {
                        projectPath
                    }, targetFramework, new List <AnalyzerResult> {
                        result
                    }, solutionFilename);

                    var analysisResult = AnalyzeProject(projectPath, solutionFilename, new List <AnalyzerResult> {
                        result
                    }, analysisActions, isIncremental: false, targetFramework);
                    result.Dispose();
                    yield return(analysisResult);
                }
            }
            finally
            {
                await resultEnumerator.DisposeAsync();
            }
        }