Exemple #1
0
        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());
            }
        }
        public void TestGetDiagnostics2()
        {
            using var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic);
            var mutex     = new ManualResetEvent(false);
            var document  = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", string.Empty);
            var document2 = document.Project.AddDocument("TestDocument2", string.Empty);

            var source            = new TestDiagnosticUpdateSource(false, null);
            var diagnosticService = new DiagnosticService(
                AsynchronousOperationListenerProvider.NullProvider, Array.Empty <Lazy <IEventListener, EventListenerMetadata> >());

            diagnosticService.Register(source);

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

            var id = Tuple.Create(workspace, document);

            RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, document.Id, id);

            var id2 = Tuple.Create(workspace, document.Project, document);

            RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, document.Id, id2);

            RaiseDiagnosticEvent(mutex, source, workspace, document2.Project.Id, document2.Id, Tuple.Create(workspace, document2));

            var id3 = Tuple.Create(workspace, document.Project);

            RaiseDiagnosticEvent(mutex, source, workspace, document.Project.Id, null, id3);
            RaiseDiagnosticEvent(mutex, source, workspace, null, null, Tuple.Create(workspace));

            var data1 = diagnosticService.GetDiagnostics(workspace, null, null, null, false, CancellationToken.None);

            Assert.Equal(5, data1.Count());

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

            Assert.Equal(4, data2.Count());

            var data3 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, null, id3, false, CancellationToken.None);

            Assert.Equal(1, data3.Count());

            var data4 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, null, false, CancellationToken.None);

            Assert.Equal(2, data4.Count());

            var data5 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, id, false, CancellationToken.None);

            Assert.Equal(1, data5.Count());
        }
        public void TestGetDiagnostics2()
        {
            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 document2 = document.Project.AddDocument("TestDocument2", string.Empty);

                var source            = new TestDiagnosticUpdateSource(false, null);
                var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonCollection(source), AggregateAsynchronousOperationListener.EmptyListeners);
                diagnosticService.DiagnosticsUpdated += (s, o) => { set.Set(); };

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

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

                RaiseDiagnosticEvent(set, source, workspace, document2.Project.Id, document2.Id, Tuple.Create(workspace, document2));

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

                var data1 = diagnosticService.GetDiagnostics(workspace, null, null, null, CancellationToken.None);
                Assert.Equal(5, data1.Count());

                var data2 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, null, null, CancellationToken.None);
                Assert.Equal(4, data2.Count());

                var data3 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, null, id3, CancellationToken.None);
                Assert.Equal(1, data3.Count());

                var data4 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, null, CancellationToken.None);
                Assert.Equal(2, data4.Count());

                var data5 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, id, CancellationToken.None);
                Assert.Equal(1, data5.Count());
            }
        }
Exemple #4
0
        public void TestCleared()
        {
            using var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic);
            var mutex     = new ManualResetEvent(false);
            var document  = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", string.Empty);
            var document2 = document.Project.AddDocument("TestDocument2", string.Empty);

            var diagnosticService = new DiagnosticService(AsynchronousOperationListenerProvider.NullProvider);

            var source1 = new TestDiagnosticUpdateSource(support: false, diagnosticData: null);

            diagnosticService.Register(source1);

            var source2 = new TestDiagnosticUpdateSource(support: false, diagnosticData: null);

            diagnosticService.Register(source2);

            diagnosticService.DiagnosticsUpdated += MarkSet;

            // add bunch of data to the service for both sources
            RaiseDiagnosticEvent(mutex, source1, workspace, document.Project.Id, document.Id, Tuple.Create(workspace, document));
            RaiseDiagnosticEvent(mutex, source1, workspace, document.Project.Id, document.Id, Tuple.Create(workspace, document.Project, document));
            RaiseDiagnosticEvent(mutex, source1, workspace, document2.Project.Id, document2.Id, Tuple.Create(workspace, document2));

            RaiseDiagnosticEvent(mutex, source2, workspace, document.Project.Id, null, Tuple.Create(workspace, document.Project));
            RaiseDiagnosticEvent(mutex, source2, workspace, null, null, Tuple.Create(workspace));

            // confirm data is there.
            var data1 = diagnosticService.GetDiagnostics(workspace, null, null, null, false, CancellationToken.None);

            Assert.Equal(5, data1.Count());

            diagnosticService.DiagnosticsUpdated -= MarkSet;

            // confirm clear for a source
            mutex.Reset();
            var count = 0;

            diagnosticService.DiagnosticsUpdated += MarkCalled;

            source1.RaiseDiagnosticsClearedEvent();

            mutex.WaitOne();

            // confirm there are 2 data left
            var data2 = diagnosticService.GetDiagnostics(workspace, null, null, null, false, CancellationToken.None);

            Assert.Equal(2, data2.Count());

            void MarkCalled(object sender, DiagnosticsUpdatedArgs args)
            {
                // event is serialized. no concurrent call
                if (++count == 3)
                {
                    mutex.Set();
                }
            }

            void MarkSet(object sender, DiagnosticsUpdatedArgs args)
            {
                mutex.Set();
            }
        }