public async Task Changed_TriggersOnSnapshotManagerChanged()
        {
            // Arrange
            var projectSnapshotManager = new TestProjectSnapshotManager(ProjectSnapshot1);

            using var proxy = new DefaultProjectSnapshotManagerProxy(
                      new TestCollaborationSession(true),
                      Dispatcher,
                      projectSnapshotManager,
                      JoinableTaskFactory);
            var changedArgs = new ProjectChangeEventArgs(ProjectSnapshot1, ProjectSnapshot1, ProjectChangeKind.ProjectChanged);
            var called      = false;

            proxy.Changed += (sender, args) =>
            {
                called = true;
                Assert.Equal($"vsls:/path/to/project1.csproj", args.ProjectFilePath.ToString());
                Assert.Equal(ProjectProxyChangeKind.ProjectChanged, args.Kind);
                Assert.Equal("vsls:/path/to/project1.csproj", args.Newer.FilePath.ToString());
            };

            // Act
            projectSnapshotManager.TriggerChanged(changedArgs);
            await proxy._processingChangedEventTestTask.JoinAsync();

            // Assert
            Assert.True(called);
        }
        public async Task CalculateUpdatedStateAsync_ReturnsStateForAllProjects()
        {
            // Arrange
            var projectSnapshotManager = new TestProjectSnapshotManager(ProjectSnapshot1, ProjectSnapshot2);

            using var proxy = new DefaultProjectSnapshotManagerProxy(
                      new TestCollaborationSession(true),
                      Dispatcher,
                      projectSnapshotManager,
                      JoinableTaskFactory);

            // Act
            var state = await JoinableTaskFactory.RunAsync(() => proxy.CalculateUpdatedStateAsync(projectSnapshotManager.Projects));

            // Assert
            Assert.Collection(
                state.ProjectHandles,
                handle =>
            {
                Assert.Equal("vsls:/path/to/project1.csproj", handle.FilePath.ToString());
                Assert.Equal(ProjectSnapshot1.TagHelpers, handle.ProjectWorkspaceState.TagHelpers);
            },
                handle =>
            {
                Assert.Equal("vsls:/path/to/project2.csproj", handle.FilePath.ToString());
                Assert.Equal(ProjectSnapshot2.TagHelpers, handle.ProjectWorkspaceState.TagHelpers);
            });
        }
Example #3
0
        public Task <ICollaborationService> CreateServiceAsync(CollaborationSession session, CancellationToken cancellationToken)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            var serializer = (JsonSerializer)session.GetService(typeof(JsonSerializer));

            serializer.Converters.RegisterRazorLiveShareConverters();

            var razorLanguageServices  = _workspace.Services.GetLanguageServices(RazorLanguage.Name);
            var projectSnapshotManager = razorLanguageServices.GetRequiredService <ProjectSnapshotManager>();

            var service = new DefaultProjectSnapshotManagerProxy(session, _foregroundDispatcher, projectSnapshotManager, _joinableTaskContext.Factory);

            return(Task.FromResult <ICollaborationService>(service));
        }
        public async Task GetStateAsync_CachesState()
        {
            // Arrange
            var projectSnapshotManager = new TestProjectSnapshotManager(ProjectSnapshot1);
            var proxy = new DefaultProjectSnapshotManagerProxy(
                new TestCollaborationSession(true),
                Dispatcher,
                projectSnapshotManager,
                JoinableTaskFactory);

            // Act
            var state1 = await JoinableTaskFactory.RunAsync(() => proxy.GetProjectManagerStateAsync(CancellationToken.None));

            var state2 = await JoinableTaskFactory.RunAsync(() => proxy.GetProjectManagerStateAsync(CancellationToken.None));

            // Assert
            Assert.Same(state1, state2);
        }
        public async Task GetLatestProjectsAsync_ReturnsSnapshotManagerProjects()
        {
            // Arrange
            var projectSnapshotManager = new TestProjectSnapshotManager(ProjectSnapshot1);
            var proxy = new DefaultProjectSnapshotManagerProxy(
                new TestCollaborationSession(true),
                Dispatcher,
                projectSnapshotManager,
                JoinableTaskFactory);

            // Act
            var projects = await proxy.GetLatestProjectsAsync();

            // Assert
            var project = Assert.Single(projects);

            Assert.Same(ProjectSnapshot1, project);
        }
        public void Changed_NoopsIfProxyDisposed()
        {
            // Arrange
            var projectSnapshotManager = new TestProjectSnapshotManager(ProjectSnapshot1);
            var proxy = new DefaultProjectSnapshotManagerProxy(
                new TestCollaborationSession(true),
                Dispatcher,
                projectSnapshotManager,
                JoinableTaskFactory);
            var changedArgs = new ProjectChangeEventArgs(ProjectSnapshot1, ProjectSnapshot1, ProjectChangeKind.ProjectChanged);

            proxy.Changed += (sender, args) => throw new InvalidOperationException("Should not have been called.");
            proxy.Dispose();

            // Act
            projectSnapshotManager.TriggerChanged(changedArgs);

            // Assert
            Assert.Null(proxy._processingChangedEventTestTask);
        }