public void ClearClosedDocuments_RestartsTimerIfDocumentsStillOpen() { // Arrange var languageServer = new Mock <ITextDocumentLanguageServer>(); using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory)) { publisher._publishedDiagnostics[ClosedDocument.FilePath] = EmptyDiagnostics; publisher._publishedDiagnostics[OpenedDocument.FilePath] = EmptyDiagnostics; publisher.Initialize(ProjectManager); // Act publisher.ClearClosedDocuments(); // Assert Assert.NotNull(publisher._documentClosedTimer); } }
public async Task PublishDiagnosticsAsync_NoopsIfDiagnosticsAreSameAsPreviousPublish() { // Arrange var languageServer = new Mock <ILanguageServer>(); languageServer.Setup(server => server.Document).Throws <XunitException>(); 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); } }
public void ClearClosedDocuments_ClearsDiagnosticsForClosedDocument() { // Arrange var languageServer = new Mock <ITextDocumentLanguageServer>(MockBehavior.Strict); languageServer.Setup(server => server.SendNotification(It.IsAny <IRequest>())).Callback <IRequest>((@params) => { var diagnosticParams = (PublishDiagnosticsParams)@params; Assert.Equal(ClosedDocument.FilePath.TrimStart('/'), diagnosticParams.Uri.ToUri().AbsolutePath); Assert.Empty(diagnosticParams.Diagnostics); }); using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory)) { publisher._publishedDiagnostics[ClosedDocument.FilePath] = SingleDiagnosticCollection; publisher.Initialize(ProjectManager); // Act publisher.ClearClosedDocuments(); // Assert languageServer.VerifyAll(); } }
public async Task PublishDiagnosticsAsync_NewDiagnosticsGetPublished() { // 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._publishedDiagnostics[processedOpenDocument.FilePath] = EmptyDiagnostics; publisher.Initialize(ProjectManager); // Act await publisher.PublishDiagnosticsAsync(processedOpenDocument); // Assert languageServerDocument.VerifyAll(); } }