Exemplo n.º 1
0
        public void Update_SoftCancelsIncompleteTaskForSameProject()
        {
            // Arrange
            using (var stateGenerator = new DefaultProjectWorkspaceStateGenerator(Dispatcher))
            {
                stateGenerator.BlockBackgroundWorkStart = new ManualResetEventSlim(initialState: false);
                stateGenerator.Update(WorkspaceProject, ProjectSnapshot, CancellationToken.None);
                var initialUpdate = stateGenerator._updates.Single().Value;

                // Act
                stateGenerator.Update(WorkspaceProject, ProjectSnapshot, CancellationToken.None);

                // Assert
                Assert.True(initialUpdate.Cts.IsCancellationRequested);
            }
        }
Exemplo n.º 2
0
        public void Update_StartsUpdateTask()
        {
            // Arrange
            using (var stateGenerator = new DefaultProjectWorkspaceStateGenerator(Dispatcher))
            {
                stateGenerator.BlockBackgroundWorkStart = new ManualResetEventSlim(initialState: false);

                // Act
                stateGenerator.Update(WorkspaceProject, ProjectSnapshot, CancellationToken.None);

                // Assert
                var update = Assert.Single(stateGenerator._updates);
                Assert.False(update.Value.Task.IsCompleted);
            }
        }
Exemplo n.º 3
0
        public void Dispose_MakesUpdateNoop()
        {
            // Arrange
            using (var stateGenerator = new DefaultProjectWorkspaceStateGenerator(Dispatcher))
            {
                stateGenerator.BlockBackgroundWorkStart = new ManualResetEventSlim(initialState: false);

                // Act
                stateGenerator.Dispose();
                stateGenerator.Update(WorkspaceProject, ProjectSnapshot, CancellationToken.None);

                // Assert
                Assert.Empty(stateGenerator._updates);
            }
        }
Exemplo n.º 4
0
        public async Task Update_ResolvesTagHelpersAndUpdatesWorkspaceState()
        {
            // Arrange
            using (var stateGenerator = new DefaultProjectWorkspaceStateGenerator(Dispatcher))
            {
                stateGenerator.NotifyBackgroundWorkCompleted = new ManualResetEventSlim(initialState: false);
                var projectManager = new TestProjectSnapshotManager(Dispatcher, Workspace);
                stateGenerator.Initialize(projectManager);
                projectManager.ProjectAdded(ProjectSnapshot.HostProject);

                // Act
                stateGenerator.Update(WorkspaceProject, ProjectSnapshot, CancellationToken.None);

                // Jump off the foreground thread so the background work can complete.
                await Task.Run(() => stateGenerator.NotifyBackgroundWorkCompleted.Wait(TimeSpan.FromSeconds(3)));

                // Assert
                var newProjectSnapshot = projectManager.GetLoadedProject(ProjectSnapshot.FilePath);
                Assert.Equal(ResolvableTagHelpers, newProjectSnapshot.TagHelpers);
            }
        }
        public async Task Update_NullWorkspaceProject_ClearsProjectWorkspaceState()
        {
            // Arrange
            using (var stateGenerator = new DefaultProjectWorkspaceStateGenerator(Dispatcher))
            {
                stateGenerator.NotifyBackgroundWorkCompleted = new ManualResetEventSlim(initialState: false);
                var projectManager = new TestProjectSnapshotManager(Dispatcher, Workspace);
                stateGenerator.Initialize(projectManager);
                projectManager.ProjectAdded(ProjectSnapshot.HostProject);
                projectManager.ProjectWorkspaceStateChanged(ProjectSnapshot.FilePath, ProjectWorkspaceStateWithTagHelpers);

                // Act
                stateGenerator.Update(workspaceProject: null, ProjectSnapshot);

                // Jump off the foreground thread so the background work can complete.
                await Task.Run(() => stateGenerator.NotifyBackgroundWorkCompleted.Wait(TimeSpan.FromSeconds(3)));

                // Assert
                var newProjectSnapshot = projectManager.GetLoadedProject(ProjectSnapshot.FilePath);
                Assert.Empty(newProjectSnapshot.TagHelpers);
            }
        }