예제 #1
0
 public OptionViewModelTests()
 {
     WpfTestRunner.RequireWpfFact("Tests create WPF ViewModels and updates previews with them");
 }
예제 #2
0
        public async Task LargeNumberOfSpans()
        {
            using (var workspace = TestWorkspace.CreateCSharp(@"class Program
{
    void M()
    {
        int z = 0;
        z = z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z +
            z + z + z + z + z + z + z + z + z + z;
    }
}"))
            {
                List <ITagSpan <TestTag> > tagProducer(SnapshotSpan span, CancellationToken cancellationToken)
                {
                    return(new List <ITagSpan <TestTag> >()
                    {
                        new TagSpan <TestTag>(span, new TestTag())
                    });
                }

                var asyncListener = new AsynchronousOperationListener();

                WpfTestRunner.RequireWpfFact($"{nameof(AsynchronousTaggerTests)}.{nameof(LargeNumberOfSpans)} creates asynchronous taggers");

                var notificationService = workspace.GetService <IForegroundNotificationService>();

                var eventSource    = CreateEventSource();
                var taggerProvider = new TestTaggerProvider(
                    workspace.ExportProvider.GetExportedValue <IThreadingContext>(),
                    tagProducer,
                    eventSource,
                    workspace,
                    asyncListener,
                    notificationService);

                var document   = workspace.Documents.First();
                var textBuffer = document.TextBuffer;
                var snapshot   = textBuffer.CurrentSnapshot;
                var tagger     = taggerProvider.CreateTagger <TestTag>(textBuffer);

                using (IDisposable disposable = (IDisposable)tagger)
                {
                    var spans         = Enumerable.Range(0, 101).Select(i => new Span(i * 4, 1));
                    var snapshotSpans = new NormalizedSnapshotSpanCollection(snapshot, spans);

                    eventSource.SendUpdateEvent();

                    await asyncListener.CreateWaitTask();

                    var tags = tagger.GetTags(snapshotSpans);

                    Assert.Equal(1, tags.Count());
                }
            }
        }
예제 #3
0
        public async Task TestPreviewDiagnosticTaggerInPreviewPane()
        {
            // TODO: WPF required due to https://github.com/dotnet/roslyn/issues/46153
            using var workspace = TestWorkspace.CreateCSharp(
                      "class { }",
                      composition: EditorTestCompositions.EditorFeaturesWpf
                      );

            workspace.TryApplyChanges(
                workspace.CurrentSolution.WithAnalyzerReferences(
                    new[]
            {
                DiagnosticExtensions.GetCompilerDiagnosticAnalyzerReference(
                    LanguageNames.CSharp
                    )
            }
                    )
                );

            // set up listener to wait until diagnostic finish running
            _ = workspace.ExportProvider.GetExportedValue <IDiagnosticService>();

            var hostDocument = workspace.Projects.First().Documents.First();

            // make a change to remove squiggle
            var oldDocument = workspace.CurrentSolution.GetRequiredDocument(hostDocument.Id);
            var oldText     = oldDocument.GetTextAsync().Result;

            var newDocument = oldDocument.WithText(
                oldText.WithChanges(new TextChange(new TextSpan(0, oldText.Length), "class C { }"))
                );

            // create a diff view
            WpfTestRunner.RequireWpfFact(
                $"{nameof(TestPreviewDiagnosticTaggerInPreviewPane)} creates a {nameof(DifferenceViewerPreview)}"
                );

            var previewFactoryService =
                (PreviewFactoryService)workspace.ExportProvider.GetExportedValue <IPreviewFactoryService>();

            using var diffView = await previewFactoryService.CreateChangedDocumentPreviewViewAsync(
                      oldDocument,
                      newDocument,
                      CancellationToken.None
                      );

            AssertEx.NotNull(diffView);

            var listenerProvider =
                workspace.ExportProvider.GetExportedValue <AsynchronousOperationListenerProvider>();

            // set up tagger for both buffers
            var leftBuffer = diffView.Viewer.LeftView.BufferGraph
                             .GetTextBuffers(t => t.ContentType.IsOfType(ContentTypeNames.CSharpContentType))
                             .First();
            var provider = workspace.ExportProvider
                           .GetExportedValues <ITaggerProvider>()
                           .OfType <DiagnosticsSquiggleTaggerProvider>()
                           .Single();
            var leftTagger = provider.CreateTagger <IErrorTag>(leftBuffer);

            using var leftDisposable = leftTagger as IDisposable;
            var rightBuffer = diffView.Viewer.RightView.BufferGraph
                              .GetTextBuffers(t => t.ContentType.IsOfType(ContentTypeNames.CSharpContentType))
                              .First();
            var rightTagger = provider.CreateTagger <IErrorTag>(rightBuffer);

            using var rightDisposable = rightTagger as IDisposable;
            // wait for diagnostics and taggers
            await listenerProvider.WaitAllDispatcherOperationAndTasksAsync(
                workspace,
                FeatureAttribute.DiagnosticService,
                FeatureAttribute.ErrorSquiggles
                );

            // check left buffer
            var leftSnapshot = leftBuffer.CurrentSnapshot;
            var leftSpans    = leftTagger.GetTags(leftSnapshot.GetSnapshotSpanCollection()).ToList();

            Assert.Equal(1, leftSpans.Count);

            // check right buffer
            var rightSnapshot = rightBuffer.CurrentSnapshot;
            var rightSpans    = rightTagger
                                .GetTags(rightSnapshot.GetSnapshotSpanCollection())
                                .ToList();

            Assert.Equal(0, rightSpans.Count);
        }
예제 #4
0
 public AsynchronousWorkerTests()
 {
     WpfTestRunner.RequireWpfFact($"Tests are testing {nameof(AsynchronousSerialWorkQueue)} which is designed to run methods on the UI thread");
     _foregroundSyncContext = SynchronizationContext.Current;
     Assert.NotNull(_foregroundSyncContext);
 }