当前位置: 首页>>代码示例>>C#>>正文


C# Workspaces.TestWorkspace类代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace的典型用法代码示例。如果您正苦于以下问题:C# TestWorkspace类的具体用法?C# TestWorkspace怎么用?C# TestWorkspace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestWorkspace类属于Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces命名空间,在下文中一共展示了TestWorkspace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetErrorsFromUpdateSource

        internal static IList<ITagSpan<IErrorTag>> GetErrorsFromUpdateSource(TestWorkspace workspace, TestHostDocument document, DiagnosticsUpdatedArgs updateArgs)
        {
            var source = new TestDiagnosticUpdateSource();

            var diagnosticWaiter = new DiagnosticServiceWaiter();
            var diagnosticListeners = SpecializedCollections.SingletonEnumerable(new Lazy<IAsynchronousOperationListener, FeatureMetadata>(
                () => diagnosticWaiter, new FeatureMetadata(new Dictionary<string, object>() { { "FeatureName", FeatureAttribute.DiagnosticService } })));

            var optionsService = workspace.Services.GetService<IOptionService>();
            var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(source), diagnosticListeners);

            var squiggleWaiter = new ErrorSquiggleWaiter();
            var foregroundService = new TestForegroundNotificationService();

            var buffer = document.GetTextBuffer();
            var taggerSource = new DiagnosticsSquiggleTaggerProvider.TagSource(buffer, foregroundService, diagnosticService, optionsService, squiggleWaiter);

            source.RaiseDiagnosticsUpdated(updateArgs);

            diagnosticWaiter.CreateWaitTask().PumpingWait();
            squiggleWaiter.CreateWaitTask().PumpingWait();

            var snapshot = buffer.CurrentSnapshot;
            var intervalTree = taggerSource.GetTagIntervalTreeForBuffer(buffer);
            var spans = intervalTree.GetIntersectingSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));

            taggerSource.TestOnly_Dispose();

            return spans;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:30,代码来源:AbstractSquiggleProducerTests.cs

示例2: GetErrorsFromUpdateSource

        internal static IList<ITagSpan<IErrorTag>> GetErrorsFromUpdateSource(TestWorkspace workspace, TestHostDocument document, DiagnosticsUpdatedArgs updateArgs)
        {
            var source = new TestDiagnosticUpdateSource();

            var listener = new AsynchronousOperationListener();
            var listeners = AsynchronousOperationListener.CreateListeners(
                ValueTuple.Create(FeatureAttribute.DiagnosticService, listener),
                ValueTuple.Create(FeatureAttribute.ErrorSquiggles, listener));

            var optionsService = workspace.Services.GetService<IOptionService>();
            var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(source), listeners);

            var foregroundService = workspace.GetService<IForegroundNotificationService>();  //new TestForegroundNotificationService();

            var buffer = document.GetTextBuffer();
            var provider = new DiagnosticsSquiggleTaggerProvider(optionsService, diagnosticService, foregroundService, listeners);
            var tagger = provider.CreateTagger<IErrorTag>(buffer);

            source.RaiseDiagnosticsUpdated(updateArgs);

            listener.CreateWaitTask().PumpingWait();

            var snapshot = buffer.CurrentSnapshot;
            var spans = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, 0, snapshot.Length))).ToImmutableArray();

            ((IDisposable)tagger).Dispose();

            return spans;
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:29,代码来源:AbstractSquiggleProducerTests.cs

示例3: DiagnosticTaggerWrapper

        private DiagnosticTaggerWrapper(TestWorkspace workspace, DiagnosticAnalyzerService analyzerService, IDiagnosticUpdateSource updateSource)
        {
            if (updateSource == null)
            {
                updateSource = analyzerService;
            }

            this.workspace = workspace;

            this.registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
            registrationService.Register(workspace);

            this.asyncListener = new AsynchronousOperationListener();
            var listeners = AsynchronousOperationListener.CreateListeners(
                ValueTuple.Create(FeatureAttribute.DiagnosticService, asyncListener),
                ValueTuple.Create(FeatureAttribute.ErrorSquiggles, asyncListener));

            this.analyzerService = analyzerService;
            var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable(updateSource), listeners);

            this.TaggerProvider = new DiagnosticsSquiggleTaggerProvider(
                workspace.Services.GetService<IOptionService>(), diagnosticService,
                workspace.GetService<IForegroundNotificationService>(), listeners);

            if (analyzerService != null)
            {
                this.incrementalAnalyzers = ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace));
                this.solutionCrawlerService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;
            }
        }
开发者ID:noahfalk,项目名称:roslyn,代码行数:30,代码来源:DiagnosticsSquiggleTaggerProviderTests.cs

示例4: TestActionsOnLinkedFiles

        protected async Task TestActionsOnLinkedFiles(
            TestWorkspace workspace,
            string expectedText,
            int index,
            IList<CodeAction> actions,
            string expectedPreviewContents = null,
            bool compareTokens = true)
        {
            var operations = await VerifyInputsAndGetOperationsAsync(index, actions);

            await VerifyPreviewContents(workspace, expectedPreviewContents, operations);

            var applyChangesOperation = operations.OfType<ApplyChangesOperation>().First();
            applyChangesOperation.Apply(workspace, new ProgressTracker(), CancellationToken.None);

            foreach (var document in workspace.Documents)
            {
                var fixedRoot = await workspace.CurrentSolution.GetDocument(document.Id).GetSyntaxRootAsync();
                var actualText = compareTokens ? fixedRoot.ToString() : fixedRoot.ToFullString();

                if (compareTokens)
                {
                    TokenUtilities.AssertTokensEqual(expectedText, actualText, GetLanguage());
                }
                else
                {
                    Assert.Equal(expectedText, actualText);
                }
            }
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:30,代码来源:AbstractCodeActionTest.cs

示例5: GetDiagnosticAndFixesAsync

        internal override async Task<IEnumerable<Tuple<Diagnostic, CodeFixCollection>>> GetDiagnosticAndFixesAsync(
            TestWorkspace workspace, string fixAllActionId, object fixProviderData)
        {
            var providerAndFixer = GetOrCreateDiagnosticProviderAndFixer(workspace, fixProviderData);

            var provider = providerAndFixer.Item1;
            Document document;
            TextSpan span;
            string annotation = null;
            if (!TryGetDocumentAndSelectSpan(workspace, out document, out span))
            {
                document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
            }

            using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider))
            {
                var diagnostics = await testDriver.GetAllDiagnosticsAsync(provider, document, span);
                AssertNoAnalyzerExceptionDiagnostics(diagnostics);

                var fixer = providerAndFixer.Item2;
                var ids = new HashSet<string>(fixer.FixableDiagnosticIds);
                var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList();
                return await GetDiagnosticAndFixesAsync(dxs, provider, fixer, testDriver, document, span, annotation, fixAllActionId);
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:25,代码来源:AbstractDiagnosticProviderBasedUserDiagnosticTest.cs

示例6: AdornmentManagerTester

            public AdornmentManagerTester()
            {
                _subjectBuffer = EditorFactory.CreateBuffer(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "Hi There");

                _textView = new Mock<IWpfTextView>();
                var aggregatorService = new Mock<IViewTagAggregatorFactoryService>();
                _adornmentLayer = new Mock<IAdornmentLayer>();
                _aggregator = new Mock<ITagAggregator<Tag>>();

                var layerName = "LayerName";

                _textView.Setup(tv => tv.GetAdornmentLayer(layerName)).Returns(_adornmentLayer.Object);
                _textView.SetupGet(tv => tv.VisualElement).Returns(new FrameworkElement());

                aggregatorService.Setup(a => a.CreateTagAggregator<Tag>(_textView.Object)).Returns(_aggregator.Object);

                var textViewModel = new Mock<ITextViewModel>();
                textViewModel.Setup(tvm => tvm.VisualBuffer).Returns(_subjectBuffer);
                _textView.Setup(tv => tv.TextViewModel).Returns(textViewModel.Object);

                var workspace = new TestWorkspace();

                var listener = new AggregateAsynchronousOperationListener(
                    Enumerable.Empty<Lazy<IAsynchronousOperationListener, FeatureMetadata>>(),
                    FeatureAttribute.LineSeparators);
                Manager = AdornmentManager<Tag>.Create(_textView.Object,
                                                       aggregatorService.Object,
                                                       listener,
                                                       adornmentLayerName: layerName);
            }
开发者ID:natidea,项目名称:roslyn,代码行数:30,代码来源:AdornmentManagerTests.cs

示例7: TestGetDiagnostics1

        public void TestGetDiagnostics1()
        {
            using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic))
            {
                var set = new ManualResetEvent(false);
                var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", string.Empty);

                var source = new TestDiagnosticUpdateSource(false, null);
                var diagnosticService = new DiagnosticService(AggregateAsynchronousOperationListener.EmptyListeners);
                diagnosticService.Register(source);

                diagnosticService.DiagnosticsUpdated += (s, o) => { set.Set(); };

                var id = Tuple.Create(workspace, document);
                var diagnostic = RaiseDiagnosticEvent(set, source, workspace, document.Project.Id, document.Id, id);

                var data1 = diagnosticService.GetDiagnostics(workspace, null, null, null, false, CancellationToken.None);
                Assert.Equal(diagnostic, data1.Single());

                var data2 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, null, null, false, CancellationToken.None);
                Assert.Equal(diagnostic, data2.Single());

                var data3 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, null, false, CancellationToken.None);
                Assert.Equal(diagnostic, data3.Single());

                var data4 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, id, false, CancellationToken.None);
                Assert.Equal(diagnostic, data4.Single());
            }
        }
开发者ID:uwe-baumann,项目名称:roslyn,代码行数:29,代码来源:DiagnosticServiceTests.cs

示例8: WaitForWorkspaceOperationsToComplete

 private static void WaitForWorkspaceOperationsToComplete(TestWorkspace workspace)
 {
     var workspasceWaiter = workspace.ExportProvider
         .GetExports<IAsynchronousOperationListener, FeatureMetadata>()
         .First(l => l.Metadata.FeatureName == FeatureAttribute.Workspace).Value as IAsynchronousOperationWaiter;
     workspasceWaiter.CreateWaitTask().PumpingWait();
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:7,代码来源:WorkspaceTests.cs

示例9: GetDiagnosticAndFixesAsync

        internal override async Task<IEnumerable<Tuple<Diagnostic, CodeFixCollection>>> GetDiagnosticAndFixesAsync(
            TestWorkspace workspace, string fixAllActionId, object fixProviderData)
        {
            var providerAndFixer = CreateDiagnosticProviderAndFixer(workspace);

            var provider = providerAndFixer.Item1;
            Document document;
            TextSpan span;
            string annotation = null;
            if (!TryGetDocumentAndSelectSpan(workspace, out document, out span))
            {
                document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
            }

            using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics))
            {
                var fixer = providerAndFixer.Item2;
                var diagnostics = (await testDriver.GetAllDiagnosticsAsync(provider, document, span))
                    .Where(d => fixer.CanBeSuppressedOrUnsuppressed(d));

                var filteredDiagnostics = FilterDiagnostics(diagnostics);

                var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, filteredDiagnostics.Select(d => d.Id));
                return await GetDiagnosticAndFixesAsync(filteredDiagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, fixAllActionId);
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:26,代码来源:AbstractSuppressionDiagnosticTest.cs

示例10: DiagnosticTaggerWrapper

 public DiagnosticTaggerWrapper(
     TestWorkspace workspace,
     IDiagnosticUpdateSource updateSource,
     bool createTaggerProvider = true)
     : this(workspace, null, updateSource, createTaggerProvider)
 {
 }
开发者ID:nbsoftwarecsjava,项目名称:roslyn,代码行数:7,代码来源:DiagnosticsSquiggleTaggerProviderTests.cs

示例11: GetDiagnosticAndFixes

        internal override IEnumerable<Tuple<Diagnostic, CodeFixCollection>> GetDiagnosticAndFixes(TestWorkspace workspace, string fixAllActionId)
        {
            var providerAndFixer = CreateDiagnosticProviderAndFixer(workspace);

            var provider = providerAndFixer.Item1;
            Document document;
            TextSpan span;
            string annotation = null;
            if (!TryGetDocumentAndSelectSpan(workspace, out document, out span))
            {
                document = GetDocumentAndAnnotatedSpan(workspace, out annotation, out span);
            }           

            using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider, includeSuppressedDiagnostics: IncludeSuppressedDiagnostics))
            {
                var fixer = providerAndFixer.Item2;
                var diagnostics = testDriver.GetAllDiagnostics(provider, document, span)
                    .Where(d => fixer.CanBeSuppressedOrUnsuppressed(d))
                    .ToImmutableArray();

                if (!IncludeUnsuppressedDiagnostics)
                {
                    diagnostics = diagnostics.WhereAsArray(d => d.IsSuppressed);
                }

                var wrapperCodeFixer = new WrapperCodeFixProvider(fixer, diagnostics);
                return GetDiagnosticAndFixes(diagnostics, provider, wrapperCodeFixer, testDriver, document, span, annotation, fixAllActionId);
            }
        }
开发者ID:nemec,项目名称:roslyn,代码行数:29,代码来源:AbstractSuppressionDiagnosticTest.cs

示例12: WaitForWorkspaceOperationsToComplete

 private static async Task WaitForWorkspaceOperationsToComplete(TestWorkspace workspace)
 {
     var workspaceWaiter = workspace.ExportProvider
         .GetExports<IAsynchronousOperationListener, FeatureMetadata>()
         .First(l => l.Metadata.FeatureName == FeatureAttribute.Workspace).Value as IAsynchronousOperationWaiter;
     await workspaceWaiter.CreateWaitTask().ConfigureAwait(true);
 }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:7,代码来源:WorkspaceTests.cs

示例13: TestWithOptionsAsync

        private async Task TestWithOptionsAsync(TestWorkspace workspace, params Action<object>[] expectedResults)
        {
            var testDocument = workspace.DocumentWithCursor;
            var position = testDocument.CursorPosition.GetValueOrDefault();
            var documentId = workspace.GetDocumentId(testDocument);
            var document = workspace.CurrentSolution.GetDocument(documentId);

            var provider = new SemanticQuickInfoProvider(
                workspace.GetService<IProjectionBufferFactoryService>(),
                workspace.GetService<IEditorOptionsFactoryService>(),
                workspace.GetService<ITextEditorFactoryService>(),
                workspace.GetService<IGlyphService>(),
                workspace.GetService<ClassificationTypeMap>());

            await TestWithOptionsAsync(document, provider, position, expectedResults);

            // speculative semantic model
            if (await CanUseSpeculativeSemanticModelAsync(document, position))
            {
                var buffer = testDocument.TextBuffer;
                using (var edit = buffer.CreateEdit())
                {
                    var currentSnapshot = buffer.CurrentSnapshot;
                    edit.Replace(0, currentSnapshot.Length, currentSnapshot.GetText());
                    edit.Apply();
                }

                await TestWithOptionsAsync(document, provider, position, expectedResults);
            }
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:30,代码来源:SemanticQuickInfoSourceTests.cs

示例14: AssertNoContent

 protected override void AssertNoContent(
     TestWorkspace workspace,
     Document document,
     int position)
 {
     var provider = CreateProvider(workspace);
     Assert.Null(provider.GetItemAsync(document, position, CancellationToken.None).Result);
 }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:8,代码来源:SyntacticQuickInfoSourceTests.cs

示例15: GetDocumentAndAnnotatedSpan

 protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out string annotation, out TextSpan span)
 {
     var hostDocument = workspace.Documents.Single(d => d.AnnotatedSpans.Any());
     var annotatedSpan = hostDocument.AnnotatedSpans.Single();
     annotation = annotatedSpan.Key;
     span = annotatedSpan.Value.Single();
     return workspace.CurrentSolution.GetDocument(hostDocument.Id);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:8,代码来源:AbstractUserDiagnosticTest.cs


注:本文中的Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。