Esempio n. 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);
                        }
        }
Esempio n. 2
0
        private (TestSetupData, IList <string>) GenerateWorkspace()
        {
            var virtualEnvName = "virtualEnv";

            var mockWorkspace              = WorkspaceTestHelper.CreateMockWorkspace(WorkspaceTestHelper.CreateWorkspaceFolder(), WorkspaceTestHelper.Python37Id);
            var optionsService             = new WorkspaceTestHelper.MockOptionsService(WorkspaceTestHelper.DefaultFactory);
            var includedWorkspaceFilePaths = GenerateWorkspaceFiles(mockWorkspace.Location, virtualEnvName, out string virtualEnvPath);

            includedWorkspaceFilePaths.Add(Path.Combine(mockWorkspace.Location, "app.py")); //Created by WorkspaceTestHelper.CreateWorkspaceFolder()

            var workspaceInterpreterFactories = new List <IPythonInterpreterFactory>()
            {
                new MockPythonInterpreterFactory(
                    new VisualStudioInterpreterConfiguration("Python|3.7", "Fake interpreter 3.7", Path.Combine(mockWorkspace.Location, virtualEnvName), virtualEnvPath)
                    )
            };
            var registryService = new WorkspaceTestHelper.MockRegistryService(workspaceInterpreterFactories);

            var testDataSetup = new TestSetupData {
                OptionsService  = optionsService,
                RegistryService = registryService,
                Workspace       = mockWorkspace,
            };

            return(testDataSetup, includedWorkspaceFilePaths);
        }
Esempio n. 3
0
 private static TestSetupData PrepareWorkspace(string interpreterSetting)
 {
     return(new TestSetupData {
         OptionsService = new WorkspaceTestHelper.MockOptionsService(WorkspaceTestHelper.DefaultFactory),
         RegistryService = new WorkspaceTestHelper.MockRegistryService(WorkspaceTestHelper.AllFactories),
         Workspace = WorkspaceTestHelper.CreateMockWorkspace(WorkspaceTestHelper.CreateWorkspaceFolder(), interpreterSetting),
     });
 }
Esempio n. 4
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);
        }