public async Task ReleaseProjectContextAsync_UnregistersContextWithTracker()
        {
            IWorkspaceProjectContext result          = null;
            var activeWorkspaceProjectContextTracker = IActiveWorkspaceProjectContextTrackerFactory.ImplementReleaseContext(c => { result = c; });

            var provider = CreateInstance(activeWorkspaceProjectContextTracker: activeWorkspaceProjectContextTracker);

            var projectContext = IWorkspaceProjectContextMockFactory.Create();

            await provider.ReleaseProjectContextAsync(projectContext);

            Assert.Same(projectContext, result);
        }
        public async Task CreateProjectContextAsync_RegistersContextWithTracker()
        {
            IWorkspaceProjectContext result          = null;
            var activeWorkspaceProjectContextTracker = IActiveWorkspaceProjectContextTrackerFactory.ImplementRegisterContext((c, id) => { result = c; });

            var context = IWorkspaceProjectContextMockFactory.Create();
            var workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, __, ___, ____, ______, _______) => context);
            var provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory, activeWorkspaceProjectContextTracker: activeWorkspaceProjectContextTracker);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            await provider.CreateProjectContextAsync(project);

            Assert.NotNull(result);
        }
예제 #3
0
        public async Task OnProjectChangedAsync_RespectsIsActiveContext(bool evaluation, bool isActiveContext)
        {
            bool?isActiveContextResult = null;

            void applyChanges(IProjectVersionedValue <IProjectSubscriptionUpdate> u, bool iac, CancellationToken _)
            {
                isActiveContextResult = iac;
            }

            var activeWorkspaceProjectContextTracker = IActiveWorkspaceProjectContextTrackerFactory.ImplementIsActiveContext(context => isActiveContext);
            var applyChangesToWorkspaceContext       = evaluation ? IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectEvaluation(applyChanges) : IApplyChangesToWorkspaceContextFactory.ImplementApplyProjectBuild(applyChanges);


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

            var update = IProjectVersionedValueFactory.CreateEmpty();
            await instance.OnProjectChangedAsync(update, evaluation);

            Assert.Equal(isActiveContext, isActiveContextResult);
        }
예제 #4
0
        private WorkspaceContextHostInstance CreateInstance(ConfiguredProject project = null, IProjectThreadingService threadingService = null, IUnconfiguredProjectTasksService tasksService = null, IProjectSubscriptionService projectSubscriptionService = null, IActiveWorkspaceProjectContextTracker activeWorkspaceProjectContextTracker = null, IWorkspaceProjectContextProvider workspaceProjectContextProvider = null, IApplyChangesToWorkspaceContext applyChangesToWorkspaceContext = null)
        {
            project                              = project ?? ConfiguredProjectFactory.Create();
            threadingService                     = threadingService ?? IProjectThreadingServiceFactory.Create();
            tasksService                         = tasksService ?? IUnconfiguredProjectTasksServiceFactory.Create();
            projectSubscriptionService           = projectSubscriptionService ?? IProjectSubscriptionServiceFactory.Create();
            activeWorkspaceProjectContextTracker = activeWorkspaceProjectContextTracker ?? IActiveWorkspaceProjectContextTrackerFactory.Create();
            workspaceProjectContextProvider      = workspaceProjectContextProvider ?? IWorkspaceProjectContextProviderFactory.ImplementCreateProjectContextAsync(IWorkspaceProjectContextMockFactory.Create());
            applyChangesToWorkspaceContext       = applyChangesToWorkspaceContext ?? IApplyChangesToWorkspaceContextFactory.Create();

            return(new WorkspaceContextHostInstance(project,
                                                    threadingService,
                                                    tasksService,
                                                    projectSubscriptionService,
                                                    workspaceProjectContextProvider,
                                                    activeWorkspaceProjectContextTracker,
                                                    ExportFactoryFactory.ImplementCreateValueWithAutoDispose(() => applyChangesToWorkspaceContext)));
        }
        private static WorkspaceProjectContextProvider CreateInstance(UnconfiguredProject project = null, IProjectThreadingService threadingService = null, IWorkspaceProjectContextFactory workspaceProjectContextFactory = null, IActiveWorkspaceProjectContextTracker activeWorkspaceProjectContextTracker = null, ISafeProjectGuidService projectGuidService = null, IProjectRuleSnapshot projectRuleSnapshot = null)
        {
            projectRuleSnapshot = projectRuleSnapshot ?? IProjectRuleSnapshotFactory.FromJson(
                @"{
    ""Properties"": {
        ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj"",
        ""LanguageServiceName"": ""CSharp"",
        ""TargetPath"": ""C:\\Target.dll""
    }
}");

            var telemetryService = ITelemetryServiceFactory.Create();

            project          = project ?? UnconfiguredProjectFactory.Create();
            threadingService = threadingService ?? IProjectThreadingServiceFactory.Create();
            workspaceProjectContextFactory       = workspaceProjectContextFactory ?? IWorkspaceProjectContextFactoryFactory.Create();
            activeWorkspaceProjectContextTracker = activeWorkspaceProjectContextTracker ?? IActiveWorkspaceProjectContextTrackerFactory.Create();
            projectGuidService = projectGuidService ?? ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(Guid.NewGuid());

            var mock = new Mock <WorkspaceProjectContextProvider>(project, threadingService, projectGuidService, telemetryService, workspaceProjectContextFactory.AsLazy(), activeWorkspaceProjectContextTracker);

            mock.Protected().Setup <Task <IProjectRuleSnapshot> >("GetLatestSnapshotAsync", ItExpr.IsAny <ConfiguredProject>())
            .ReturnsAsync(projectRuleSnapshot);

            return(mock.Object);
        }