internal async Task OnProjectChangedAsync_WhenProjectUnloaded_TriggersCancellation()
        {
            var unloadSource = new CancellationTokenSource();

            var instance = await CreateInitializedInstanceAsync(
                tasksService : IUnconfiguredProjectTasksServiceFactory.ImplementUnloadCancellationToken(unloadSource.Token));

            var registration            = IDataProgressTrackerServiceRegistrationFactory.Create();
            var activeConfiguredProject = ConfiguredProjectFactory.Create();
            var update = IProjectVersionedValueFactory.CreateEmpty();

            await Assert.ThrowsAsync <OperationCanceledException>(() =>
            {
                return(instance.OnProjectChangedAsync(
                           registration,
                           activeConfiguredProject,
                           update,
                           hasChange: _ => true,
                           applyFunc: (_, _, _, token) =>
                {
                    // Simulate project unload during callback
                    unloadSource.Cancel();

                    token.ThrowIfCancellationRequested();
                }));
            });
        }
        internal async Task OnProjectChangedAsync_WhenProjectUnloaded_TriggersCancellation(WorkspaceContextHandlerType handlerType)
        {
            var unloadSource = new CancellationTokenSource();
            var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementUnloadCancellationToken(unloadSource.Token);

            void ApplyProjectBuild(IProjectVersionedValue <IProjectSubscriptionUpdate> _, IProjectBuildSnapshot projectBuildSnapshot, ContextState __, CancellationToken cancellationToken)
            {
                // Unload project
                unloadSource.Cancel();

                cancellationToken.ThrowIfCancellationRequested();
            }

            void ApplyProjectEvaluation(IProjectVersionedValue <IProjectSubscriptionUpdate> _, ContextState __, CancellationToken cancellationToken)
            {
                // Unload project
                unloadSource.Cancel();

                cancellationToken.ThrowIfCancellationRequested();
            }

            var applyChangesToWorkspaceContext = handlerType switch
            {
                WorkspaceContextHandlerType.Evaluation => IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectEvaluationAsync(ApplyProjectEvaluation),
                WorkspaceContextHandlerType.ProjectBuild => IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectBuildAsync(ApplyProjectBuild),
                WorkspaceContextHandlerType.SourceItems => IApplyChangesToWorkspaceContextFactory.ImplementApplySourceItemsAsync(ApplyProjectEvaluation), // ApplyProjectEvaluation works for source items as they share a signature
                _ => throw new NotImplementedException()
            };

            var instance = await CreateInitializedInstanceAsync(tasksService : tasksService, applyChangesToWorkspaceContext : applyChangesToWorkspaceContext);

            var update = IProjectVersionedValueFactory.Create <(ConfiguredProject, IProjectSubscriptionUpdate, IProjectBuildSnapshot)>((default !, default !, Mock.Of <IProjectBuildSnapshot>()));
        [InlineData(false)]     // Project Build
        public async Task OnProjectChangedAsync_WhenProjectUnloaded_TriggersCancellation(bool evaluation)
        {
            var unloadSource = new CancellationTokenSource();
            var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementUnloadCancellationToken(unloadSource.Token);

            void ApplyProjectBuild(IProjectVersionedValue <IProjectSubscriptionUpdate> _, IProjectBuildSnapshot projectBuildSnapshot, ContextState __, CancellationToken cancellationToken)
            {
                // Unload project
                unloadSource.Cancel();

                cancellationToken.ThrowIfCancellationRequested();
            }

            void ApplyProjectEvaluation(IProjectVersionedValue <IProjectSubscriptionUpdate> _, ContextState __, CancellationToken cancellationToken)
            {
                // Unload project
                unloadSource.Cancel();

                cancellationToken.ThrowIfCancellationRequested();
            }

            var applyChangesToWorkspaceContext = evaluation ? IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectEvaluationAsync(ApplyProjectEvaluation) : IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectBuildAsync(ApplyProjectBuild);

            var instance = await CreateInitializedInstanceAsync(tasksService : tasksService, applyChangesToWorkspaceContext : applyChangesToWorkspaceContext);

            var update = IProjectVersionedValueFactory.Create <(ConfiguredProject, IProjectSubscriptionUpdate, IProjectBuildSnapshot)>(default);
Ejemplo n.º 4
0
        public async Task OpenContextForWriteAsync_WhenProjectUnloaded_ThrowsOperationCanceled()
        {
            var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementUnloadCancellationToken(new CancellationToken(canceled: true));
            var accessor     = IWorkspaceProjectContextAccessorFactory.Create();
            var workspaceProjectContextProvider = IWorkspaceProjectContextProviderFactory.ImplementCreateProjectContextAsync(accessor);

            var instance = await CreateInitializedInstanceAsync(workspaceProjectContextProvider : workspaceProjectContextProvider, tasksService : tasksService);

            int callCount = 0;

            await Assert.ThrowsAnyAsync <OperationCanceledException>(() =>
            {
                return(instance.OpenContextForWriteAsync(c => { callCount++; return Task.CompletedTask; }));
            });

            Assert.Equal(0, callCount);
        }
Ejemplo n.º 5
0
        [InlineData(false)]     // Project Build
        public async Task OnProjectChangedAsync_WhenProjectUnloaded_TriggersCancellation(bool evaluation)
        {
            var unloadSource = new CancellationTokenSource();
            var tasksService = IUnconfiguredProjectTasksServiceFactory.ImplementUnloadCancellationToken(unloadSource.Token);

            void applyChanges(IProjectVersionedValue <IProjectSubscriptionUpdate> _, bool __, CancellationToken cancellationToken)
            {
                // Unload project
                unloadSource.Cancel();

                cancellationToken.ThrowIfCancellationRequested();
            }

            var applyChangesToWorkspaceContext = evaluation ? IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectEvaluationAsync(applyChanges) : IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectBuildAsync(applyChanges);

            var instance = await CreateInitializedInstanceAsync(tasksService : tasksService, applyChangesToWorkspaceContext : applyChangesToWorkspaceContext);

            var update = IProjectVersionedValueFactory.CreateEmpty();
            await Assert.ThrowsAsync <OperationCanceledException>(() =>
            {
                return(instance.OnProjectChangedAsync(update, evaluation));
            });
        }