Exemple #1
0
        public async Task Handle_DidCloseTextDocument_ClosesDocument()
        {
            // Arrange
            var documentPath   = "C:/path/to/document.cshtml";
            var projectService = new Mock <RazorProjectService>(MockBehavior.Strict);

            projectService.Setup(service => service.CloseDocument(It.IsAny <string>()))
            .Callback <string>((path) =>
            {
                Assert.Equal(documentPath, path);
            });
            var endpoint = new RazorDocumentSynchronizationEndpoint(Dispatcher, DocumentResolver, projectService.Object, LoggerFactory);
            var request  = new DidCloseTextDocumentParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = new Uri(documentPath)
                }
            };

            // Act
            await Task.Run(() => endpoint.Handle(request, default));

            // Assert
            projectService.VerifyAll();
        }
Exemple #2
0
        public async Task Handle_DidOpenTextDocument_AddsDocument()
        {
            // Arrange
            var documentPath   = "C:/path/to/document.cshtml";
            var projectService = new Mock <RazorProjectService>(MockBehavior.Strict);

            projectService.Setup(service => service.OpenDocument(It.IsAny <string>(), It.IsAny <SourceText>(), It.IsAny <long>()))
            .Callback <string, SourceText, long>((path, text, version) =>
            {
                var resultString = GetString(text);
                Assert.Equal("hello", resultString);
                Assert.Equal(documentPath, path);
                Assert.Equal(1337, version);
            });
            var endpoint = new RazorDocumentSynchronizationEndpoint(Dispatcher, DocumentResolver, projectService.Object, LoggerFactory);
            var request  = new DidOpenTextDocumentParams()
            {
                TextDocument = new TextDocumentItem()
                {
                    Text    = "hello",
                    Uri     = new Uri(documentPath),
                    Version = 1337,
                }
            };

            // Act
            await Task.Run(() => endpoint.Handle(request, default));

            // Assert
            projectService.VerifyAll();
        }
Exemple #3
0
        public async Task Handle_DidChangeTextDocument_UpdatesDocument()
        {
            // Arrange
            var documentPath     = "C:/path/to/document.cshtml";
            var sourceText       = SourceText.From("<p>");
            var documentResolver = CreateDocumentResolver(documentPath, sourceText);
            var projectService   = new Mock <RazorProjectService>(MockBehavior.Strict);

            projectService.Setup(service => service.UpdateDocument(It.IsAny <string>(), It.IsAny <SourceText>(), It.IsAny <long>()))
            .Callback <string, SourceText, long>((path, text, version) =>
            {
                var resultString = GetString(text);
                Assert.Equal("<p></p>", resultString);
                Assert.Equal(documentPath, path);
                Assert.Equal(1337, version);
            });
            var endpoint = new RazorDocumentSynchronizationEndpoint(Dispatcher, documentResolver, projectService.Object, LoggerFactory);
            var change   = new TextDocumentContentChangeEvent()
            {
                Range       = new Range(new Position(0, 3), new Position(0, 3)),
                RangeLength = 0,
                Text        = "</p>"
            };
            var request = new DidChangeTextDocumentParams()
            {
                ContentChanges = new Container <TextDocumentContentChangeEvent>(change),
                TextDocument   = new VersionedTextDocumentIdentifier()
                {
                    Uri     = new Uri(documentPath),
                    Version = 1337,
                }
            };

            // Act
            await Task.Run(() => endpoint.Handle(request, default));

            // Assert
            projectService.VerifyAll();
        }