Beispiel #1
0
        public async Task CheckAllFiles(string filename1, string filename2)
        {
            var testFile1 = new TestFile(filename1, "class C1 { int n = true; }");
            var testFile2 = new TestFile(filename2, "class C2 { int n = true; }");

            SharedOmniSharpTestHost.AddFilesToWorkspace(testFile1, testFile2);
            var messages  = new List <DiagnosticMessage>();
            var emitter   = new DiagnosticTestEmitter(messages);
            var forwarder = new DiagnosticEventForwarder(emitter);
            var service   = new CSharpDiagnosticService(SharedOmniSharpTestHost.Workspace, forwarder, this.LoggerFactory);

            var controller = new DiagnosticsService(SharedOmniSharpTestHost.Workspace, forwarder, service);
            var response   = await controller.Handle(new DiagnosticsRequest());

            await emitter.Emitted;

            Assert.Single(messages);
            var message = messages.First();

            Assert.Equal(2, message.Results.Count());

            var a = message.Results.First(x => x.FileName == filename1);

            Assert.Single(a.QuickFixes);
            Assert.Equal(filename1, a.FileName);

            var b = message.Results.First(x => x.FileName == filename2);

            Assert.Single(b.QuickFixes);
            Assert.Equal(filename2, b.FileName);
        }
Beispiel #2
0
        public async Task CodeCheckSpecifiedFileOnly(string filename)
        {
            var testFile = new TestFile(filename, "class C { int n = true; }");

            SharedOmniSharpTestHost.AddFilesToWorkspace(testFile);
            var messages  = new List <DiagnosticMessage>();
            var emitter   = new DiagnosticTestEmitter(messages);
            var forwarder = new DiagnosticEventForwarder(emitter)
            {
                IsEnabled = true
            };

            var service = new CSharpDiagnosticService(SharedOmniSharpTestHost.Workspace, forwarder, this.LoggerFactory);

            service.QueueDiagnostics(filename);

            await emitter.Emitted;

            Assert.Single(messages);
            var message = messages.First();

            Assert.Single(message.Results);
            var result = message.Results.First();

            Assert.Single(result.QuickFixes);
            Assert.Equal(filename, result.FileName);
        }
Beispiel #3
0
        public async Task CheckAllFiles()
        {
            var workspace = await TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string>
            {
                { "a.cs", "class C1 { int n = true; }" },
                { "b.cs", "class C2 { int n = true; }" },
            });

            var fakeLoggerFactory = new FakeLoggerFactory();
            var messages          = new List <OmniSharp.Models.DiagnosticMessage>();
            var emitter           = new DiagnosticTestEmitter(messages);
            var forwarder         = new DiagnosticEventForwarder(emitter);
            var service           = new CSharpDiagnosticService(workspace, forwarder, fakeLoggerFactory);

            var controller = new DiagnosticsService(workspace, forwarder, service);
            var response   = await controller.Handle(new OmniSharp.Models.DiagnosticsRequest());

            await emitter.Emitted;

            Assert.Equal(1, messages.Count);
            var message = messages.First();

            Assert.Equal(2, message.Results.Count());

            var a = message.Results.First(x => x.FileName == "a.cs");

            Assert.Equal(1, a.QuickFixes.Count());
            Assert.Equal("a.cs", a.FileName);

            var b = message.Results.First(x => x.FileName == "b.cs");

            Assert.Equal(1, b.QuickFixes.Count());
            Assert.Equal("b.cs", b.FileName);
        }
Beispiel #4
0
        public async Task CodeCheckSpecifiedFileOnly()
        {
            var workspace = await TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string>
            {
                { "a.cs", "class C { int n = true; }" }
            });

            var fakeLoggerFactory = new FakeLoggerFactory();
            var messages          = new List <OmniSharp.Models.DiagnosticMessage>();
            var emitter           = new DiagnosticTestEmitter(messages);
            var forwarder         = new DiagnosticEventForwarder(emitter);

            forwarder.IsEnabled = true;
            var service = new CSharpDiagnosticService(workspace, forwarder, fakeLoggerFactory);

            service.QueueDiagnostics("a.cs");

            await emitter.Emitted;

            Assert.Equal(1, messages.Count);
            var message = messages.First();

            Assert.Equal(1, message.Results.Count());
            var result = message.Results.First();

            Assert.Equal(1, result.QuickFixes.Count());
            Assert.Equal("a.cs", result.FileName);
        }
Beispiel #5
0
        public async Task EnablesWhenEndPointIsHit(string filename1, string filename2)
        {
            var testFile1 = new TestFile(filename1, "class C1 { int n = true; }");
            var testFile2 = new TestFile(filename2, "class C2 { int n = true; }");

            SharedOmniSharpTestHost.AddFilesToWorkspace(testFile1, testFile2);
            var messages  = new List <DiagnosticMessage>();
            var emitter   = new DiagnosticTestEmitter(messages);
            var forwarder = new DiagnosticEventForwarder(emitter);
            var service   = new CSharpDiagnosticService(SharedOmniSharpTestHost.Workspace, forwarder, this.LoggerFactory);

            var controller = new DiagnosticsService(SharedOmniSharpTestHost.Workspace, forwarder, service);
            var response   = await controller.Handle(new DiagnosticsRequest());

            Assert.True(forwarder.IsEnabled);
        }
Beispiel #6
0
        public async Task EnablesWhenEndPointIsHit()
        {
            var workspace = await TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string>
            {
                { "a.cs", "class C1 { int n = true; }" },
                { "b.cs", "class C2 { int n = true; }" },
            });

            var fakeLoggerFactory = new FakeLoggerFactory();
            var messages          = new List <OmniSharp.Models.DiagnosticMessage>();
            var emitter           = new DiagnosticTestEmitter(messages);
            var forwarder         = new DiagnosticEventForwarder(emitter);
            var service           = new CSharpDiagnosticService(workspace, forwarder, fakeLoggerFactory);

            var controller = new DiagnosticsService(workspace, forwarder, service);
            var response   = await controller.Handle(new OmniSharp.Models.DiagnosticsRequest());

            Assert.Equal(true, forwarder.IsEnabled);
        }
 public DiagnosticsService(OmnisharpWorkspace workspace, DiagnosticEventForwarder forwarder, CSharpDiagnosticService diagnostics)
 {
     _forwarder   = forwarder;
     _workspace   = workspace;
     _diagnostics = diagnostics;
 }