public async Task PublishDiagnosticsAsync_NewDocumentDiagnosticsGetPublished() { // Arrange var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath); var codeDocument = CreateCodeDocument(SingleDiagnosticCollection); processedOpenDocument.With(codeDocument); var languageServerDocument = new Mock <ILanguageServerDocument>(); languageServerDocument.Setup(lsd => lsd.SendNotification(It.IsAny <string>(), It.IsAny <PublishDiagnosticsParams>())) .Callback <string, PublishDiagnosticsParams>((method, diagnosticParams) => { Assert.Equal(processedOpenDocument.FilePath.TrimStart('/'), diagnosticParams.Uri.AbsolutePath); var diagnostic = Assert.Single(diagnosticParams.Diagnostics); var razorDiagnostic = SingleDiagnosticCollection[0]; processedOpenDocument.TryGetText(out var sourceText); var expectedDiagnostic = RazorDiagnosticConverter.Convert(razorDiagnostic, sourceText); Assert.Equal(expectedDiagnostic.Message, diagnostic.Message); Assert.Equal(expectedDiagnostic.Severity, diagnostic.Severity); Assert.Equal(expectedDiagnostic.Range, diagnostic.Range); }).Verifiable(); var languageServer = new Mock <ILanguageServer>(); languageServer.Setup(server => server.Document).Returns(languageServerDocument.Object); using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory)) { publisher.Initialize(ProjectManager); // Act await publisher.PublishDiagnosticsAsync(processedOpenDocument); // Assert languageServerDocument.VerifyAll(); } }
public async Task PublishDiagnosticsAsync_NewDiagnosticsGetPublished() { // Arrange var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath); var codeDocument = CreateCodeDocument(SingleDiagnosticCollection); processedOpenDocument.With(codeDocument); var languageServer = new Mock <ITextDocumentLanguageServer>(MockBehavior.Strict); languageServer.Setup(server => server.SendNotification((It.IsAny <IRequest>()))).Callback <IRequest>((@params) => { var diagnosticParams = (PublishDiagnosticsParams)@params; Assert.Equal(processedOpenDocument.FilePath.TrimStart('/'), diagnosticParams.Uri.ToUri().AbsolutePath); var diagnostic = Assert.Single(diagnosticParams.Diagnostics); var razorDiagnostic = SingleDiagnosticCollection[0]; processedOpenDocument.TryGetText(out var sourceText); var expectedDiagnostic = RazorDiagnosticConverter.Convert(razorDiagnostic, sourceText); Assert.Equal(expectedDiagnostic.Message, diagnostic.Message); Assert.Equal(expectedDiagnostic.Severity, diagnostic.Severity); Assert.Equal(expectedDiagnostic.Range, diagnostic.Range); }); using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory)) { publisher._publishedDiagnostics[processedOpenDocument.FilePath] = EmptyDiagnostics; publisher.Initialize(ProjectManager); // Act await publisher.PublishDiagnosticsAsync(processedOpenDocument); // Assert languageServer.VerifyAll(); } }
public async Task PublishDiagnosticsAsync_NoopsIfDiagnosticsAreSameAsPreviousPublish() { // Arrange var languageServer = new Mock <ITextDocumentLanguageServer>(); var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath); var codeDocument = CreateCodeDocument(SingleDiagnosticCollection); processedOpenDocument.With(codeDocument); using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory)) { publisher._publishedDiagnostics[processedOpenDocument.FilePath] = SingleDiagnosticCollection; publisher.Initialize(ProjectManager); // Act & Assert await publisher.PublishDiagnosticsAsync(processedOpenDocument); } }