public async Task ApplyChangesAsync_VirtualHtmlDocumentNotFound_ReturnsEmptyDiagnosticResponse()
        {
            // Arrange
            var diagnosticsProvider = Mock.Of <LSPDiagnosticsTranslator>(MockBehavior.Strict);

            var testVirtualDocument          = new TestVirtualDocumentSnapshot(RazorUri, hostDocumentVersion: 0);
            LSPDocumentSnapshot testDocument = new TestLSPDocumentSnapshot(RazorUri, version: 0, testVirtualDocument);
            var documentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);

            documentManager.Setup(manager => manager.TryGetDocument(It.IsAny <Uri>(), out testDocument))
            .Returns(true);

            var htmlDiagnosticsInterceptor = new RazorHtmlPublishDiagnosticsInterceptor(documentManager.Object, diagnosticsProvider, LoggerProvider);
            var diagnosticRequest          = new VSPublishDiagnosticParams()
            {
                Diagnostics = Diagnostics,
                Mode        = null,
                Uri         = RazorVirtualHtmlUri
            };

            // Act
            var result = await htmlDiagnosticsInterceptor.ApplyChangesAsync(JToken.FromObject(diagnosticRequest), string.Empty, cancellationToken : default).ConfigureAwait(false);

            // Assert
            var updatedParams = result.UpdatedToken.ToObject <VSPublishDiagnosticParams>();

            Assert.Empty(updatedParams.Diagnostics);
            Assert.Equal(RazorUri, updatedParams.Uri);
            Assert.True(result.ChangedDocumentUri);
        }
        public async Task ApplyChangesAsync_RazorUriNotSupported_ReturnsDefaultResponse()
        {
            // Arrange
            var documentManager     = new TestDocumentManager();
            var diagnosticsProvider = Mock.Of <LSPDiagnosticsTranslator>(MockBehavior.Strict);

            var htmlDiagnosticsInterceptor = new RazorHtmlPublishDiagnosticsInterceptor(documentManager, diagnosticsProvider, LoggerProvider);
            var diagnosticRequest          = new PublishDiagnosticParams()
            {
                Diagnostics = s_diagnostics,
                Uri         = s_razorUri
            };
            var token = JToken.FromObject(diagnosticRequest);

            // Act
            var result = await htmlDiagnosticsInterceptor.ApplyChangesAsync(token, containedLanguageName : string.Empty, cancellationToken : default).ConfigureAwait(false);

            // Assert
            Assert.Same(token, result.UpdatedToken);
            Assert.False(result.ChangedDocumentUri);
        }
        public async Task ApplyChangesAsync_InvalidParams_ThrowsException()
        {
            // Arrange
            var documentManager     = new TestDocumentManager();
            var diagnosticsProvider = Mock.Of <LSPDiagnosticsTranslator>(MockBehavior.Strict);

            var htmlDiagnosticsInterceptor = new RazorHtmlPublishDiagnosticsInterceptor(documentManager, diagnosticsProvider, LoggerProvider);
            var diagnosticRequest          = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = RazorUri
                }
            };

            // Act
            await Assert.ThrowsAnyAsync <ArgumentException>(async() =>
                                                            await htmlDiagnosticsInterceptor.ApplyChangesAsync(
                                                                JToken.FromObject(diagnosticRequest),
                                                                containedLanguageName : string.Empty,
                                                                cancellationToken : default).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task ApplyChangesAsync_ProcessesDiagnostics_ReturnsDiagnosticResponse()
        {
            // Arrange
            var documentManager     = CreateDocumentManager();
            var diagnosticsProvider = GetDiagnosticsProvider();

            var htmlDiagnosticsInterceptor = new RazorHtmlPublishDiagnosticsInterceptor(documentManager, diagnosticsProvider, LoggerProvider);
            var diagnosticRequest          = new PublishDiagnosticParams()
            {
                Diagnostics = s_diagnostics,
                Uri         = s_razorVirtualHtmlUri
            };

            // Act
            var result = await htmlDiagnosticsInterceptor.ApplyChangesAsync(JToken.FromObject(diagnosticRequest), string.Empty, cancellationToken : default).ConfigureAwait(false);

            // Assert
            var updatedParams = result.UpdatedToken.ToObject <PublishDiagnosticParams>();

            Assert.Equal(s_diagnostics, updatedParams.Diagnostics);
            Assert.Equal(s_razorUri, updatedParams.Uri);
            Assert.True(result.ChangedDocumentUri);
        }
        public async Task ApplyChangesAsync_EmptyDiagnostics_ReturnsEmptyDiagnosticResponse()
        {
            // Arrange
            var documentManager     = CreateDocumentManager();
            var diagnosticsProvider = Mock.Of <LSPDiagnosticsTranslator>(MockBehavior.Strict);

            var htmlDiagnosticsInterceptor = new RazorHtmlPublishDiagnosticsInterceptor(documentManager, diagnosticsProvider, LoggerProvider);
            var diagnosticRequest          = new VSPublishDiagnosticParams()
            {
                Diagnostics = Array.Empty <Diagnostic>(),
                Mode        = null,
                Uri         = RazorVirtualHtmlUri
            };

            // Act
            var result = await htmlDiagnosticsInterceptor.ApplyChangesAsync(JToken.FromObject(diagnosticRequest), string.Empty, cancellationToken : default).ConfigureAwait(false);

            // Assert
            var updatedParams = result.UpdatedToken.ToObject <VSPublishDiagnosticParams>();

            Assert.Empty(updatedParams.Diagnostics);
            Assert.Equal(RazorUri, updatedParams.Uri);
            Assert.True(result.ChangedDocumentUri);
        }