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();
        }
Beispiel #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);
        }
Beispiel #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();
        }
        public void ResolveWorkspaceDirectory_RootUriUnavailable_UsesRootPath()
        {
            // Arrange
            var expectedWorkspaceDirectory = "/testpath";
            var clientSettings             = new InitializeParams()
            {
                RootPath = expectedWorkspaceDirectory
            };

            // Act
            var workspaceDirectory = RazorFileChangeDetectorManager.ResolveWorkspaceDirectory(clientSettings);

            // Assert
            Assert.Equal(expectedWorkspaceDirectory, workspaceDirectory);
        }
        public void ResolveWorkspaceDirectory_RootUriPrefered()
        {
            // Arrange
            var expectedWorkspaceDirectory = "\\\\testpath";
            var clientSettings             = new InitializeParams()
            {
                RootPath = "/somethingelse",
                RootUri  = new Uri(expectedWorkspaceDirectory),
            };

            // Act
            var workspaceDirectory = RazorFileChangeDetectorManager.ResolveWorkspaceDirectory(clientSettings);

            // Assert
            Assert.Equal(expectedWorkspaceDirectory, workspaceDirectory);
        }