コード例 #1
0
        public void UpdateGuestProjectManager_ProjectAdded()
        {
            // Arrange
            var newHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                "project",
                ProjectWorkspaceStateWithTagHelpers);
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionContext,
                Mock.Of <IProjectSnapshotManagerProxy>(),
                ProjectSnapshotManager);
            var args = new ProjectChangeEventProxyArgs(older: null, newHandle, ProjectProxyChangeKind.ProjectAdded);

            // Act
            synchronizationService.UpdateGuestProjectManager(args);

            // Assert
            var project = Assert.Single(ProjectSnapshotManager.Projects);

            Assert.Equal("/guest/path/project.csproj", project.FilePath);
            Assert.Same(RazorConfiguration.Default, project.Configuration);
            Assert.Same(ProjectWorkspaceStateWithTagHelpers.TagHelpers, project.TagHelpers);
        }
コード例 #2
0
        public async Task InitializeAsync_RetrievesHostProjectManagerStateAndInitializesGuestManager()
        {
            // Arrange
            var projectHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                "project",
                ProjectWorkspaceStateWithTagHelpers);
            var state = new ProjectSnapshotManagerProxyState(new[] { projectHandle });
            var hostProjectManagerProxy = Mock.Of <IProjectSnapshotManagerProxy>(
                proxy => proxy.GetProjectManagerStateAsync(It.IsAny <CancellationToken>()) == Task.FromResult(state));
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionContext,
                hostProjectManagerProxy,
                ProjectSnapshotManager);

            // Act
            await synchronizationService.InitializeAsync(CancellationToken.None);

            // Assert
            var project = Assert.Single(ProjectSnapshotManager.Projects);

            Assert.Equal("/guest/path/project.csproj", project.FilePath);
            Assert.Same(RazorConfiguration.Default, project.Configuration);
            Assert.Same(ProjectWorkspaceStateWithTagHelpers.TagHelpers, project.TagHelpers);
        }
コード例 #3
0
        public void UpdateGuestProjectManager_ProjectChanged_ConfigurationChange()
        {
            // Arrange
            var oldHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                "project",
                projectWorkspaceState: null);
            var newConfiguration = RazorConfiguration.Create(RazorLanguageVersion.Version_1_0, "Custom-1.0", Enumerable.Empty <RazorExtension>());
            var newHandle        = new ProjectSnapshotHandleProxy(
                oldHandle.FilePath,
                newConfiguration,
                oldHandle.RootNamespace,
                oldHandle.ProjectWorkspaceState);
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionContext,
                Mock.Of <IProjectSnapshotManagerProxy>(),
                ProjectSnapshotManager);
            var hostProject = new HostProject("/guest/path/project.csproj", RazorConfiguration.Default, "project");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.ProjectConfigurationChanged(hostProject);
            var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged);

            // Act
            synchronizationService.UpdateGuestProjectManager(args);

            // Assert
            var project = Assert.Single(ProjectSnapshotManager.Projects);

            Assert.Equal("/guest/path/project.csproj", project.FilePath);
            Assert.Same(newConfiguration, project.Configuration);
            Assert.Empty(project.TagHelpers);
        }
        public void UpdateGuestProjectManager_ProjectChanged_ProjectWorkspaceStateChange()
        {
            // Arrange
            var oldHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                "project",
                ProjectWorkspaceState.Default);
            var newProjectWorkspaceState = ProjectWorkspaceStateWithTagHelpers;
            var newHandle = new ProjectSnapshotHandleProxy(
                oldHandle.FilePath,
                oldHandle.Configuration,
                oldHandle.RootNamespace,
                newProjectWorkspaceState);
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionContext,
                Mock.Of <IProjectSnapshotManagerProxy>(MockBehavior.Strict),
                ProjectSnapshotManager);
            var hostProject = new HostProject("/guest/path/project.csproj", RazorConfiguration.Default, "project");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.FilePath, oldHandle.ProjectWorkspaceState);
            var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged);

            // Act
            synchronizationService.UpdateGuestProjectManager(args);

            // Assert
            var project = Assert.Single(ProjectSnapshotManager.Projects);

            Assert.Equal("/guest/path/project.csproj", project.FilePath);
            Assert.Same(RazorConfiguration.Default, project.Configuration);
            Assert.Same(newProjectWorkspaceState.TagHelpers, project.TagHelpers);
        }
コード例 #5
0
        public async Task <ICollaborationService> CreateServiceAsync(CollaborationSession sessionContext, CancellationToken cancellationToken)
        {
            // This collaboration service depends on these serializers being immediately available so we need to register these now so the
            // guest project snapshot manager can retrieve the hosts project state.
            var serializer = (JsonSerializer)sessionContext.GetService(typeof(JsonSerializer));

            serializer.Converters.RegisterRazorLiveShareConverters();

            var languageServices = _workspace.Services.GetLanguageServices(RazorLanguage.Name);
            var projectManager   = (ProjectSnapshotManagerBase)languageServices.GetRequiredService <ProjectSnapshotManager>();

            var projectSnapshotManagerProxy = await sessionContext.GetRemoteServiceAsync <IProjectSnapshotManagerProxy>(typeof(IProjectSnapshotManagerProxy).Name, cancellationToken);

            var synchronizationService = new ProjectSnapshotSynchronizationService(
                _joinableTaskContext.Factory,
                sessionContext,
                projectSnapshotManagerProxy,
                projectManager);

            await synchronizationService.InitializeAsync(cancellationToken);

            return(synchronizationService);
        }
        public void UpdateGuestProjectManager_ProjectRemoved()
        {
            // Arrange
            var olderHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                projectWorkspaceState: null);
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionAccessor,
                Mock.Of <IProjectSnapshotManagerProxy>(),
                ProjectSnapshotManager);
            var hostProject = new HostProject("/guest/path/project.csproj", RazorConfiguration.Default);

            ProjectSnapshotManager.ProjectAdded(hostProject);
            var args = new ProjectChangeEventProxyArgs(olderHandle, newer: null, ProjectProxyChangeKind.ProjectRemoved);

            // Act
            synchronizationService.UpdateGuestProjectManager(args);

            // Assert
            Assert.Empty(ProjectSnapshotManager.Projects);
        }