Esempio n. 1
0
        /// <summary>
        /// Sets up a limited service provider which can be used for testing.  
        /// 
        /// This will not include many of the services which are typically available in
        /// VS but is suitable for simple test cases which need just some base functionality.
        /// </summary>
        public static MockServiceProvider CreateMockServiceProvider() {
            var serviceProvider = new MockServiceProvider();

            serviceProvider.ComponentModel.AddExtension(
                typeof(IErrorProviderFactory),
                () => new MockErrorProviderFactory()
            );
            serviceProvider.ComponentModel.AddExtension(
                typeof(IContentTypeRegistryService),
                CreateContentTypeRegistryService
            );

            serviceProvider.ComponentModel.AddExtension(
                typeof(IInteractiveWindowCommandsFactory),
                () => new MockInteractiveWindowCommandsFactory()
            );

            serviceProvider.AddService(typeof(ErrorTaskProvider), CreateTaskProviderService, true);
            serviceProvider.AddService(typeof(CommentTaskProvider), CreateTaskProviderService, true);
            serviceProvider.AddService(typeof(UIThreadBase), new MockUIThread());
            var optionsService = new MockPythonToolsOptionsService();
            serviceProvider.AddService(typeof(IPythonToolsOptionsService), optionsService, true);

            var ptvsService = new PythonToolsService(serviceProvider);
            serviceProvider.AddService(typeof(PythonToolsService), ptvsService);
            return serviceProvider;
        }
Esempio n. 2
0
        public void UpgradeCheckToolsVersion() {
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            foreach (var testCase in new[] {
                new { Name = "NoToolsVersion.pyproj", Expected = 1 },
                new { Name = "OldToolsVersion.pyproj", Expected = 1 },
                new { Name = "CorrectToolsVersion.pyproj", Expected = 0 },
                new { Name = "NewerToolsVersion.pyproj", Expected = 0 }
            }) {
                int actual;
                Guid factoryGuid;
                uint flags;
                var hr = upgrade.UpgradeProject_CheckOnly(
                    TestData.GetPath(Path.Combine("TestData", "ProjectUpgrade", testCase.Name)),
                    null,
                    out actual,
                    out factoryGuid,
                    out flags
                );

                Assert.AreEqual(0, hr, string.Format("Wrong HR for {0}", testCase.Name));
                Assert.AreEqual(testCase.Expected, actual, string.Format("Wrong result for {0}", testCase.Name));
                Assert.AreEqual(Guid.Empty, factoryGuid);
            }
        }
Esempio n. 3
0
        public void UpgradeToolsVersion() {
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            foreach (var testCase in new[] {
                new { Name = "NoToolsVersion.pyproj", Expected = 1 },
                new { Name = "OldToolsVersion.pyproj", Expected = 1 },
                new { Name = "CorrectToolsVersion.pyproj", Expected = 0 },
                new { Name = "NewerToolsVersion.pyproj", Expected = 0 }
            }) {
                int actual;
                Guid factoryGuid;
                string newLocation;

                // Use a copy of the project so we don't interfere with other
                // tests using them.
                var origProject = Path.Combine("TestData", "ProjectUpgrade", testCase.Name);
                var tempProject = Path.Combine(TestData.GetTempPath("ProjectUpgrade"), testCase.Name);
                File.Copy(origProject, tempProject);

                var hr = upgrade.UpgradeProject(
                    tempProject,
                    0u,  // no backups
                    null,
                    out newLocation,
                    null,
                    out actual,
                    out factoryGuid
                );

                Assert.AreEqual(0, hr, string.Format("Wrong HR for {0}", testCase.Name));
                Assert.AreEqual(testCase.Expected, actual, string.Format("Wrong result for {0}", testCase.Name));
                Assert.AreEqual(tempProject, newLocation, string.Format("Wrong location for {0}", testCase.Name));
                if (testCase.Expected != 0) {
                    Assert.IsTrue(
                        File.ReadAllText(tempProject).Contains("ToolsVersion=\"4.0\""),
                        string.Format("Upgraded {0} did not contain ToolsVersion=\"4.0\"", testCase.Name)
                    );
                } else {
                    Assert.IsTrue(
                        File.ReadAllText(tempProject) == File.ReadAllText(origProject),
                        string.Format("Non-upgraded {0} has different content to original", testCase.Name)
                    );
                }
                Assert.AreEqual(Guid.Empty, factoryGuid);
            }
        }
        public void UpgradeEnvironmentVariables() {
            var factory = new BaseNodeProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;

            // Use a copy of the project so we don't interfere with other
            // tests using them.
            var origProject = TestData.GetPath(Path.Combine("TestData", "ProjectUpgrade", "EnvironmentVariables.njsproj"));
            var tempProject = Path.Combine(TestData.GetTempPath("ProjectUpgrade"), "EnvironmentVariables.njsproj");
            File.Copy(origProject, tempProject);

            int actual;
            Guid factoryGuid;
            uint flags;
            var hr = upgrade.UpgradeProject_CheckOnly(
                tempProject,
                null,
                out actual,
                out factoryGuid,
                out flags
            );

            Assert.AreEqual(0, hr);
            Assert.AreEqual(1, actual);
            Assert.AreEqual(typeof(BaseNodeProjectFactory).GUID, factoryGuid);

            string newLocation;
            hr = upgrade.UpgradeProject(
                tempProject,
                0u,
                null,
                out newLocation,
                null,
                out actual,
                out factoryGuid);

            Assert.AreEqual(0, hr);
            Assert.AreEqual(1, actual);
            Assert.AreEqual(typeof(BaseNodeProjectFactory).GUID, factoryGuid);

            Assert.IsTrue(File.ReadAllText(tempProject).Contains("<Environment>fob=1\r\nbar=2</Environment>"));
            Assert.IsFalse(File.ReadAllText(tempProject).Contains("<EnvironmentVariables>"));
        }
Esempio n. 5
0
        /// <summary>
        /// Sets up a limited service provider which can be used for testing.  
        /// 
        /// This will not include many of the services which are typically available in
        /// VS but is suitable for simple test cases which need just some base functionality.
        /// </summary>
        public static MockServiceProvider CreateMockServiceProvider(
            bool suppressTaskProvider = false
        ) {
            var serviceProvider = new MockServiceProvider();

            serviceProvider.ComponentModel.AddExtension(
                typeof(IErrorProviderFactory),
                () => new MockErrorProviderFactory()
            );
            serviceProvider.ComponentModel.AddExtension(
                typeof(IContentTypeRegistryService),
                CreateContentTypeRegistryService
            );

            serviceProvider.ComponentModel.AddExtension(
                typeof(IInteractiveWindowCommandsFactory),
                () => new MockInteractiveWindowCommandsFactory()
            );

            var optService = new Lazy<MockInterpreterOptionsService>(() => new MockInterpreterOptionsService());
            serviceProvider.ComponentModel.AddExtension<IInterpreterRegistryService>(() => optService.Value);
            serviceProvider.ComponentModel.AddExtension<IInterpreterOptionsService>(() => optService.Value);

            if (suppressTaskProvider) {
                serviceProvider.AddService(typeof(ErrorTaskProvider), null, true);
                serviceProvider.AddService(typeof(CommentTaskProvider), null, true);
            } else {
                serviceProvider.AddService(typeof(ErrorTaskProvider), CreateTaskProviderService, true);
                serviceProvider.AddService(typeof(CommentTaskProvider), CreateTaskProviderService, true);
            }
            serviceProvider.AddService(typeof(UIThreadBase), new MockUIThread());
            var optionsService = new MockPythonToolsOptionsService();
            serviceProvider.AddService(typeof(IPythonToolsOptionsService), optionsService, true);

            var ptvsService = new PythonToolsService(serviceProvider);
            serviceProvider.AddService(typeof(PythonToolsService), ptvsService);
            return serviceProvider;
        }
Esempio n. 6
0
        public void ProviderLoadLog_SuccessAndFailure() {
            var sp = new MockServiceProvider();
            var log = new MockActivityLog();
            sp.Services[typeof(SVsActivityLog).GUID] = log;
            var sm = new MockSettingsManager();
            sp.Services[typeof(SVsSettingsManager).GUID] = sm;

            var path1 = FactoryProviderTypeLoadErrorPath;
            var path2 = FactoryProviderSuccessPath;

            sm.Store.AddSetting(@"PythonTools\InterpreterFactories\Test1", "CodeBase", path1);
            sm.Store.AddSetting(@"PythonTools\InterpreterFactories\Test2", "CodeBase", path2);

            var service = new InterpreterOptionsService(sp);

            foreach (var msg in log.AllItems) {
                Console.WriteLine(msg);
            }

            AssertUtil.AreEqual(
                new Regex(@"Error//Python Tools//Failed to import factory providers.*System\.ComponentModel\.Composition\.CompositionException"),
                log.ErrorsAndWarnings.Single()
            );

            Assert.AreEqual(1, service.KnownProviders.Count());
        }
Esempio n. 7
0
        public void ProviderLoadLog_CorruptImage() {
            var sp = new MockServiceProvider();
            var log = new MockActivityLog();
            sp.Services[typeof(SVsActivityLog).GUID] = log;
            var sm = new MockSettingsManager();
            sp.Services[typeof(SVsSettingsManager).GUID] = sm;

            var path = FactoryProviderCorruptPath;

            sm.Store.AddSetting(@"PythonTools\InterpreterFactories\Test", "CodeBase", path);

            var service = new InterpreterOptionsService(sp);

            foreach (var msg in log.AllItems) {
                Console.WriteLine(msg);
            }

            AssertUtil.AreEqual(
                new Regex(@"Error//Python Tools//Failed to load interpreter provider assembly.+System\.BadImageFormatException.+//" + Regex.Escape(path)),
                log.ErrorsAndWarnings.Single()
            );
        }
Esempio n. 8
0
        public void ProviderLoadLog_FileNotFound() {
            var sp = new MockServiceProvider();
            var log = new MockActivityLog();
            sp.Services[typeof(SVsActivityLog).GUID] = log;
            var sm = new MockSettingsManager();
            sp.Services[typeof(SVsSettingsManager).GUID] = sm;

            var path = Path.ChangeExtension(Path.GetTempFileName(), "dll");
            File.Delete(path);
            Assert.IsFalse(File.Exists(path));

            sm.Store.AddSetting(@"PythonTools\InterpreterFactories\Test", "CodeBase", path);

            var service = new InterpreterOptionsService(sp);

            foreach (var msg in log.AllItems) {
                Console.WriteLine(msg);
            }

            AssertUtil.AreEqual(
                new Regex(@"Error//Python Tools//Failed to load interpreter provider assembly.+System\.IO\.FileNotFoundException.+//" + Regex.Escape(path)),
                log.ErrorsAndWarnings.Single()
            );
        }
Esempio n. 9
0
        public void ProviderLoadLog_Success() {
            var sp = new MockServiceProvider();
            var log = new MockActivityLog();
            sp.Services[typeof(SVsActivityLog).GUID] = log;
            var sm = new MockSettingsManager();
            sp.Services[typeof(SVsSettingsManager).GUID] = sm;

            var path = FactoryProviderSuccessPath;

            sm.Store.AddSetting(@"PythonTools\InterpreterFactories\Test", "CodeBase", path);

            var service = new InterpreterOptionsService(sp);

            foreach (var msg in log.AllItems) {
                Console.WriteLine(msg);
            }

            AssertUtil.AreEqual(
                new Regex(@"Information//Python Tools//Loading interpreter provider assembly.*//" + Regex.Escape(path)),
                log.AllItems.Single()
            );

            Assert.AreEqual(1, service.KnownProviders.Count());
        }
Esempio n. 10
0
        public void WebProjectCompatibility() {
            const int ExpressSkuValue = 500;
            const int ShellSkuValue = 1000;
            const int ProSkuValue = 2000;
            const int PremiumUltimateSkuValue = 3000;
            
            const int VWDExpressSkuValue = 0x0040;
            const int WDExpressSkuValue = 0x8000;
            const int PremiumSubSkuValue = 0x0080;
            const int UltimateSubSkuValue = 0x0188;

            const uint Compatible = (uint)0;
            const uint Incompatible = (uint)__VSPPROJECTUPGRADEVIAFACTORYREPAIRFLAGS.VSPUVF_PROJECT_INCOMPATIBLE;

            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            var shell = new MockVsShell();

            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            sp.Services[typeof(SVsShell).GUID] = shell;
            factory.Site = sp;

            var projectFile = TestData.GetPath(Path.Combine("TestData", "ProjectUpgrade", "WebProjectType.pyproj"));

            var upgrade = (IVsProjectUpgradeViaFactory4)factory;

            foreach (var testCase in new[] {
                new { Name = "Ultimate", Sku1 = PremiumUltimateSkuValue, Sku2 = UltimateSubSkuValue, Expected = Compatible },
                new { Name = "Premium", Sku1 = PremiumUltimateSkuValue, Sku2 = PremiumSubSkuValue, Expected = Compatible },
                new { Name = "Professional", Sku1 = ProSkuValue, Sku2 = 0, Expected = Compatible },
                new { Name = "VWDExpress", Sku1 = ExpressSkuValue, Sku2 = VWDExpressSkuValue, Expected = Compatible },
                new { Name = "WDExpress", Sku1 = ExpressSkuValue, Sku2 = WDExpressSkuValue, Expected = Incompatible },
                new { Name = "Shell", Sku1 = ShellSkuValue, Sku2 = 0, Expected = Incompatible }
            }) {
                uint actual;
                Guid factoryGuid;
                uint flags;

                // Change the SKU for each test case.
                shell.Properties[(int)__VSSPROPID2.VSSPROPID_SKUEdition] = testCase.Sku1;
                shell.Properties[(int)__VSSPROPID2.VSSPROPID_SubSKUEdition] = testCase.Sku2;

                upgrade.UpgradeProject_CheckOnly(
                    projectFile,
                    null,
                    out actual,
                    out factoryGuid,
                    out flags
                );

                Assert.AreEqual(testCase.Expected, actual, string.Format("Wrong result for {0}", testCase.Name));
            }
        }
Esempio n. 11
0
        public void CommonTargetsProjectUpgrade() {
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            var origProject = TestData.GetPath("TestData\\ProjectUpgrade\\OldCommonTargets.pyproj");
            var tempProject = Path.Combine(TestData.GetTempPath("ProjectUpgrade"), "OldCommonTargets.pyproj");
            File.Copy(origProject, tempProject);

            int actual;
            Guid factoryGuid;
            string newLocation;

            var hr = upgrade.UpgradeProject(
                tempProject,
                0u,  // no backups
                null,
                out newLocation,
                null,
                out actual,
                out factoryGuid
            );

            Assert.AreEqual(0, hr, string.Format("Wrong HR for OldCommonTargets.pyproj"));
            Assert.AreEqual(1, actual, string.Format("Wrong result for OldCommonTargets.pyproj"));
            Assert.AreEqual(tempProject, newLocation, string.Format("Wrong location for OldCommonTargets.pyproj"));

            Assert.IsTrue(
                File.ReadAllText(tempProject).Contains("<Import Project=\"" + PythonProjectFactory.CommonTargets + "\" Condition=\"!Exists($(PtvsTargetsFile)"),
                string.Format("Upgraded OldCommonTargets.pyproj should conditionally import from $(VSToolsPath)")
            );
            Assert.IsTrue(
                File.ReadAllText(tempProject).Contains("<VisualStudioVersion"),
                string.Format("Upgraded OldCommonTargets.pyproj should define $(VisualStudioVersion)")
            );
            Assert.IsTrue(
                File.ReadAllText(tempProject).Contains("<PtvsTargetsFile>" + PythonProjectFactory.PtvsTargets),
                string.Format("Upgraded OldCommonTargets.pyproj should define $(PtvsTargetsFile)")
            );
            Assert.IsTrue(
                File.ReadAllText(tempProject).Contains("<Import Project=\"$(PtvsTargetsFile)\" Condition=\"Exists($(PtvsTargetsFile))\""),
                string.Format("Upgraded OldCommonTargets.pyproj should import $(PtvsTargetsFile)")
            );
            Assert.AreEqual(Guid.Empty, factoryGuid);
        }
Esempio n. 12
0
        public void OldWebProjectUpgrade() {
            // PTVS 2.1 Beta 1 shipped with separate .targets files for Bottle
            // and Flask. In PTVS 2.1 Beta 2 these were removed. This test
            // ensures that we upgrade projects created in 2.1 Beta 1.
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            foreach (var testCase in new[] {
                new { Name = "OldBottleProject.pyproj", Expected = 1 },
                new { Name = "OldFlaskProject.pyproj", Expected = 1 }
            }) {
                int actual;
                Guid factoryGuid;
                string newLocation;

                // Use a copy of the project so we don't interfere with other
                // tests using them.
                var origProject = Path.Combine("TestData", "ProjectUpgrade", testCase.Name);
                var tempProject = Path.Combine(TestData.GetTempPath("ProjectUpgrade"), testCase.Name);
                File.Copy(origProject, tempProject);

                var hr = upgrade.UpgradeProject(
                    tempProject,
                    0u,  // no backups
                    null,
                    out newLocation,
                    null,
                    out actual,
                    out factoryGuid
                );

                Assert.AreEqual(0, hr, string.Format("Wrong HR for {0}", testCase.Name));
                Assert.AreEqual(testCase.Expected, actual, string.Format("Wrong result for {0}", testCase.Name));
                Assert.AreEqual(tempProject, newLocation, string.Format("Wrong location for {0}", testCase.Name));
                if (testCase.Expected != 0) {
                    Assert.IsFalse(
                        File.ReadAllText(tempProject).Contains("<Import Project=\"$(VSToolsPath)"),
                        string.Format("Upgraded {0} should not import from $(VSToolsPath)", testCase.Name)
                    );
                    Assert.IsTrue(
                        File.ReadAllText(tempProject).Contains("Microsoft.PythonTools.Web.targets"),
                        string.Format("Upgraded {0} should import Web.targets", testCase.Name)
                    );
                    Assert.IsTrue(
                        File.ReadAllText(tempProject).Contains("<PythonWsgiHandler>"),
                        string.Format("Upgraded {0} should contain <PythonWsgiHandler>", testCase.Name)
                    );
                } else {
                    Assert.IsTrue(
                        File.ReadAllText(tempProject) == File.ReadAllText(origProject),
                        string.Format("Non-upgraded {0} has different content to original", testCase.Name)
                    );
                }
                Assert.AreEqual(Guid.Empty, factoryGuid);
            }
        }
Esempio n. 13
0
        public void UpgradeCheckUserToolsVersion() {
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var projectFile = TestData.GetPath(Path.Combine("TestData", "ProjectUpgrade", "CorrectToolsVersion.pyproj"));

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            
            foreach (var testCase in new[] {
                new { Name = "12.0", Expected = 0 },
                new { Name = "4.0", Expected = 0 }
            }) {
                int actual;
                int hr;
                Guid factoryGuid;
                uint flags;

                var xml = Microsoft.Build.Construction.ProjectRootElement.Create();
                xml.ToolsVersion = testCase.Name;
                xml.Save(projectFile + ".user");

                try {
                    hr = upgrade.UpgradeProject_CheckOnly(
                        projectFile,
                        null,
                        out actual,
                        out factoryGuid,
                        out flags
                    );
                } finally {
                    File.Delete(projectFile + ".user");
                }

                Assert.AreEqual(0, hr, string.Format("Wrong HR for ToolsVersion={0}", testCase.Name));
                Assert.AreEqual(testCase.Expected, actual, string.Format("Wrong result for ToolsVersion={0}", testCase.Name));
                Assert.AreEqual(Guid.Empty, factoryGuid);
            }
        }
Esempio n. 14
0
        public void BaseInterpreterUpgrade() {
            // PTVS 3.0 changed interpreter ID format.
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            foreach (var testCase in new[] {
                new { Name = "CPythonBaseInterpreter.pyproj", Expected = 1, Id = "Global|PythonCore|3.4|x86" },
            }) {
                int actual;
                Guid factoryGuid;
                string newLocation;

                var project = TestData.GetPath("TestData\\ProjectUpgrade\\" + testCase.Name);
                using (FileUtils.Backup(project)) {

                    var hr = upgrade.UpgradeProject(
                        project,
                        0u,  // no backups
                        null,
                        out newLocation,
                        null,
                        out actual,
                        out factoryGuid
                    );

                    Assert.AreEqual(0, hr, string.Format("Wrong HR for {0}", testCase.Name));
                    Assert.AreEqual(testCase.Expected, actual, string.Format("Wrong result for {0}", testCase.Name));
                    Assert.AreEqual(project, newLocation, string.Format("Wrong location for {0}", testCase.Name));

                    AssertUtil.Contains(
                        File.ReadAllText(project),
                        "<BaseInterpreter>{0}</BaseInterpreter>".FormatInvariant(testCase.Id)
                    );
                    Assert.AreEqual(Guid.Empty, factoryGuid);
                }
            }
        }
Esempio n. 15
0
        public void PythonTargetsProjectUpgrade() {
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            var project = TestData.GetPath("TestData\\ProjectUpgrade\\OldPythonTargets.pyproj");
            using (FileUtils.Backup(project)) {
                int actual;
                Guid factoryGuid;
                string newLocation;

                var hr = upgrade.UpgradeProject(
                    project,
                    0u,  // no backups
                    null,
                    out newLocation,
                    null,
                    out actual,
                    out factoryGuid
                );

                Assert.AreEqual(0, hr, string.Format("Wrong HR for OldPythonTargets.pyproj"));
                Assert.AreEqual(1, actual, string.Format("Wrong result for OldPythonTargets.pyproj"));
                Assert.AreEqual(project, newLocation, string.Format("Wrong location for OldPythonTargets.pyproj"));

                var text = File.ReadAllText(project);
                Assert.IsFalse(
                    text.Contains("<PtvsTargetsFile>"),
                    string.Format("Upgraded OldPythonTargets.pyproj should not define $(PtvsTargetsFile)")
                );
                Assert.IsTrue(
                    text.Contains("<Import Project=\"" + PythonProjectFactory.PtvsTargets + "\""),
                    string.Format("Upgraded OldPythonTargets.pyproj should import the Python targets directly")
                );
                Assert.AreEqual(Guid.Empty, factoryGuid);
            }
        }
Esempio n. 16
0
        public void WebBrowserUrlUpgrade() {
            // PTVS 3.0 changed interpreter ID format.
            var factory = new PythonProjectFactory(null);
            var sp = new MockServiceProvider();
            sp.Services[typeof(SVsQueryEditQuerySave).GUID] = null;
            sp.Services[typeof(SVsActivityLog).GUID] = new MockActivityLog();
            factory.Site = sp;

            var upgrade = (IVsProjectUpgradeViaFactory)factory;
            foreach (var testCase in new[] {
                new { Name = "NoWebBrowserUrl.pyproj", Expected = 1 },
                new { Name = "HasWebBrowserUrl.pyproj", Expected = 0 },
            }) {
                int actual;
                Guid factoryGuid;
                string newLocation;

                var project = TestData.GetPath("TestData\\ProjectUpgrade\\" + testCase.Name);
                using (FileUtils.Backup(project)) {

                    var hr = upgrade.UpgradeProject(
                        project,
                        0u,  // no backups
                        null,
                        out newLocation,
                        null,
                        out actual,
                        out factoryGuid
                    );

                    Assert.AreEqual(0, hr, string.Format("Wrong HR for {0}", testCase.Name));
                    Assert.AreEqual(testCase.Expected, actual, string.Format("Wrong result for {0}", testCase.Name));
                    Assert.AreEqual(project, newLocation, string.Format("Wrong location for {0}", testCase.Name));
                    Console.WriteLine(File.ReadAllText(project));

                    if (testCase.Expected != 0) {
                        AssertUtil.Contains(
                            File.ReadAllText(project),
                            "<WebBrowserUrl>http://localhost</WebBrowserUrl>"
                        );
                    }
                    Assert.AreEqual(Guid.Empty, factoryGuid);
                }
            }
        }