Example #1
0
        public void CloseWorkspace()
        {
            var workspaceFolder  = WorkspaceTestHelper.CreateWorkspaceFolder();
            var workspace        = WorkspaceTestHelper.CreateMockWorkspace(workspaceFolder, WorkspaceTestHelper.PythonNoId);
            var workspaceService = new WorkspaceTestHelper.MockWorkspaceService(workspace);
            var optionsService   = new WorkspaceTestHelper.MockOptionsService(WorkspaceTestHelper.DefaultFactory);
            var registryService  = new WorkspaceTestHelper.MockRegistryService(WorkspaceTestHelper.AllFactories);
            var provider         = new PythonWorkspaceContextProvider(
                workspaceService,
                new Lazy <IInterpreterOptionsService>(() => optionsService),
                new Lazy <IInterpreterRegistryService>(() => registryService)
                );

            Assert.AreEqual(workspaceFolder, provider.Workspace.Location);
            Assert.AreEqual(WorkspaceTestHelper.DefaultFactory, provider.Workspace.CurrentFactory);

            using (var openEvent = new AutoResetEvent(false))
                using (var initEvent = new AutoResetEvent(false))
                    using (var closingEvent = new AutoResetEvent(false))
                        using (var closedEvent = new AutoResetEvent(false)) {
                            provider.WorkspaceOpening     += (sender, e) => { openEvent.Set(); };
                            provider.WorkspaceInitialized += (sender, e) => { initEvent.Set(); };
                            provider.WorkspaceClosed      += (sender, e) => { closedEvent.Set(); };
                            provider.WorkspaceClosing     += (sender, e) => { closingEvent.Set(); };

                            workspaceService.SimulateChangeWorkspace(null);

                            Assert.IsFalse(openEvent.WaitOne(1000), $"Unexpected {nameof(provider.WorkspaceOpening)}.");
                            Assert.IsFalse(initEvent.WaitOne(1000), $"Unexpected {nameof(provider.WorkspaceInitialized)}.");
                            Assert.IsTrue(closingEvent.WaitOne(1000), $"Expected {nameof(provider.WorkspaceClosing)}.");
                            Assert.IsTrue(closedEvent.WaitOne(1000), $"Expected {nameof(provider.WorkspaceClosed)}.");

                            Assert.AreEqual(null, provider.Workspace);
                        }
        }
Example #2
0
        public void AlreadyOpenedWorkspace()
        {
            var workspaceFolder  = WorkspaceTestHelper.CreateWorkspaceFolder();
            var workspace        = WorkspaceTestHelper.CreateMockWorkspace(workspaceFolder, WorkspaceTestHelper.PythonNoId);
            var workspaceService = new WorkspaceTestHelper.MockWorkspaceService(workspace);
            var optionsService   = new WorkspaceTestHelper.MockOptionsService(WorkspaceTestHelper.DefaultFactory);
            var registryService  = new WorkspaceTestHelper.MockRegistryService(WorkspaceTestHelper.AllFactories);
            var provider         = new PythonWorkspaceContextProvider(
                workspaceService,
                new Lazy <IInterpreterOptionsService>(() => optionsService),
                new Lazy <IInterpreterRegistryService>(() => registryService)
                );

            Assert.AreEqual(workspaceFolder, provider.Workspace.Location);
            Assert.AreEqual(WorkspaceTestHelper.DefaultFactory, provider.Workspace.CurrentFactory);
        }