예제 #1
0
        public async Task Build_Recognizes_Class_Type(Type targetType, string testFileName, string testDocumentText)
        {
            _workspaceManager.NotifyNewExpectedDocument();

            var testDocumentPath = Path.Combine("C:", "Directory1", "Directory2", testFileName);
            var did   = _workspaceManager.AddDocument(_primaryProjectId, "TestDocument", testDocumentText);
            var model = await _workspaceManager.GetCurrentDocumentSemanticModel(did);

            var classConverter = _classConverterFactory.BuildMany(testDocumentPath, model).Single();

            Assert.IsInstanceOf(targetType, classConverter);
        }
예제 #2
0
        public CodeFileConverter(
            string sourceProjectPath,
            string fullPath,
            WorkspaceManagerService blazorWorkspaceManager,
            ProjectAnalyzer webFormsProjectAnalyzer,
            ClassConverterFactory classConverterFactory,
            TaskManagerService taskManagerService,
            WebFormMetricContext metricsContext) : base(sourceProjectPath, fullPath, taskManagerService)
        {
            // May not need this anymore but not sure yet
            _blazorWorkspaceBuilder  = blazorWorkspaceManager;
            _webFormsProjectAnaylzer = webFormsProjectAnalyzer;
            _classConverterFactory   = classConverterFactory;
            _metricsContext          = metricsContext;

            try
            {
                _fileModel = _webFormsProjectAnaylzer.AnalyzerResult.ProjectBuildResult?.SourceFileBuildResults?
                             .Single(r => r.SourceFileFullPath.Equals(fullPath, StringComparison.OrdinalIgnoreCase))?.SemanticModel;
            }
            catch (Exception e)
            {
                LogHelper.LogError(e, $"{Rules.Config.Constants.WebFormsErrorTag}Exception occurred when trying to retrieve semantic model for the file {FullPath}. " +
                                   "Semantic Model will default to null.");
            }

            if (_fileModel != null)
            {
                _classConverters = _classConverterFactory.BuildMany(RelativePath, _fileModel);
            }
            else
            {
                _classConverters = new List <ClassConverter>();
                LogHelper.LogWarning($"Semantic model was not found so class conversion cannot take place. Returning zero class converters for file: {FullPath}");
            }
        }