public async Task InitializedAsync_StartsFileChangeDetectors()
        {
            // Arrange
            var initialWorkspaceDirectory = "\\\\testpath";

            var clientSettings = new InitializeParams()
            {
                RootUri = new DocumentUri("file", authority: null, path: initialWorkspaceDirectory, query: null, fragment: null),
            };
            var languageServer = new Mock <IClientLanguageServer>(MockBehavior.Strict);

            languageServer.SetupGet(s => s.ClientSettings)
            .Returns(clientSettings);
            var detector1 = new Mock <IFileChangeDetector>(MockBehavior.Strict);
            var expectedWorkspaceDirectory = "/" + initialWorkspaceDirectory;

            detector1.Setup(detector => detector.StartAsync(expectedWorkspaceDirectory, It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var detector2 = new Mock <IFileChangeDetector>(MockBehavior.Strict);

            detector2.Setup(detector => detector.StartAsync(expectedWorkspaceDirectory, It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var workspaceDirectoryPathResolver = new DefaultWorkspaceDirectoryPathResolver(languageServer.Object);
            var detectorManager = new RazorFileChangeDetectorManager(workspaceDirectoryPathResolver, new[] { detector1.Object, detector2.Object });

            // Act
            await detectorManager.InitializedAsync();

            // Assert
            detector1.VerifyAll();
            detector2.VerifyAll();
            languageServer.VerifyAll();
        }
예제 #2
0
        public async Task InitializedAsync_Disposed_ReStopsFileChangeDetectors()
        {
            // Arrange
            var expectedWorkspaceDirectory = "\\\\testpath";
            var clientSettings             = new InitializeParams()
            {
                RootUri = new Uri(expectedWorkspaceDirectory),
            };
            var languageServer = Mock.Of <ILanguageServer>(server => server.ClientSettings == clientSettings);
            var detector       = new Mock <IFileChangeDetector>(MockBehavior.Strict);
            var cts            = new TaskCompletionSource <bool>();

            detector.Setup(d => d.StartAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(cts.Task);
            var stopCount = 0;

            detector.Setup(d => d.Stop()).Callback(() => stopCount++);
            var workspaceDirectoryPathResolver = new DefaultWorkspaceDirectoryPathResolver(languageServer);
            var detectorManager = new RazorFileChangeDetectorManager(workspaceDirectoryPathResolver, new[] { detector.Object });

            // Act
            var initializeTask = detectorManager.InitializedAsync();

            detectorManager.Dispose();

            // Unblock the detector start
            cts.SetResult(true);
            await initializeTask;

            // Assert
            Assert.Equal(2, stopCount);
        }
예제 #3
0
        public async Task InitializedAsync_StartsFileChangeDetectors()
        {
            // Arrange
            var expectedWorkspaceDirectory = "\\\\testpath";
            var clientSettings             = new InitializeParams()
            {
                RootUri = new Uri(expectedWorkspaceDirectory),
            };
            var languageServer = Mock.Of <ILanguageServer>(server => server.ClientSettings == clientSettings);
            var detector1      = new Mock <IFileChangeDetector>(MockBehavior.Strict);

            detector1.Setup(detector => detector.StartAsync(expectedWorkspaceDirectory, It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var detector2 = new Mock <IFileChangeDetector>(MockBehavior.Strict);

            detector2.Setup(detector => detector.StartAsync(expectedWorkspaceDirectory, It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var workspaceDirectoryPathResolver = new DefaultWorkspaceDirectoryPathResolver(languageServer);
            var detectorManager = new RazorFileChangeDetectorManager(workspaceDirectoryPathResolver, new[] { detector1.Object, detector2.Object });

            // Act
            await detectorManager.InitializedAsync();

            // Assert
            detector1.VerifyAll();
            detector2.VerifyAll();
        }
예제 #4
0
        public void Resolve_RootUriUnavailable_UsesRootPath()
        {
            // Arrange
            var expectedWorkspaceDirectory = "/testpath";
            var clientSettings             = new InitializeParams()
            {
                RootPath = expectedWorkspaceDirectory
            };
            var server = Mock.Of <IClientLanguageServer>(server => server.ClientSettings == clientSettings, MockBehavior.Strict);
            var workspaceDirectoryPathResolver = new DefaultWorkspaceDirectoryPathResolver(server);

            // Act
            var workspaceDirectoryPath = workspaceDirectoryPathResolver.Resolve();

            // Assert
            Assert.Equal(expectedWorkspaceDirectory, workspaceDirectoryPath);
        }
예제 #5
0
        public void Resolve_RootUriPrefered()
        {
            // Arrange
            var expectedWorkspaceDirectory = "\\\\testpath";
            var clientSettings             = new InitializeParams()
            {
                RootPath = "/somethingelse",
                RootUri  = new Uri(expectedWorkspaceDirectory),
            };
            var server = Mock.Of <ILanguageServer>(server => server.ClientSettings == clientSettings);
            var workspaceDirectoryPathResolver = new DefaultWorkspaceDirectoryPathResolver(server);

            // Act
            var workspaceDirectoryPath = workspaceDirectoryPathResolver.Resolve();

            // Assert
            Assert.Equal(expectedWorkspaceDirectory, workspaceDirectoryPath);
        }
예제 #6
0
        public void Resolve_RootUriPrefered()
        {
            // Arrange
            var initialWorkspaceDirectory = "\\\\testpath";
            var clientSettings            = new InitializeParams()
            {
                RootPath = "/somethingelse",
                RootUri  = new DocumentUri("file", authority: null, path: initialWorkspaceDirectory, query: null, fragment: null),
            };
            var server = Mock.Of <IClientLanguageServer>(server => server.ClientSettings == clientSettings, MockBehavior.Strict);
            var workspaceDirectoryPathResolver = new DefaultWorkspaceDirectoryPathResolver(server);

            // Act
            var workspaceDirectoryPath = workspaceDirectoryPathResolver.Resolve();

            // Assert
            var expectedWorkspaceDirectory = "/" + initialWorkspaceDirectory;

            Assert.Equal(expectedWorkspaceDirectory, workspaceDirectoryPath);
        }