public void MscorlibReferenceUpgrade() { // IronPython projects typically require mscorlib reference. // We'll add it if there are any other .NET references 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 = "NoNetReferences.pyproj", Expected = 0 }, new { Name = "HasMscorlib.pyproj", Expected = 0 }, new { Name = "NoMscorlib.pyproj", Expected = 1 }, }) { 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), "<Reference Include=\"mscorlib" ); } Assert.AreEqual(Guid.Empty, factoryGuid); } } }
public void InterpreterReferenceUpgrade() { // 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 = "CPythonInterpreterReference.pyproj", Expected = 1, Id = "Global|PythonCore|3.5-32" }, new { Name = "IronPythonInterpreterReference.pyproj", Expected = 1, Id = "IronPython|2.7-32" }, new { Name = "UnknownInterpreterReference.pyproj", Expected = 1, Id = (string)null }, }) { 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)); var content = File.ReadAllText(project); if (testCase.Id == null) { Assert.IsFalse(content.Contains("<InterpreterReference "), "Found <InterpreterReference> in " + content); } else { AssertUtil.Contains(content, "<InterpreterReference Include=\"{0}\" />".FormatInvariant(testCase.Id)); } Assert.AreEqual(Guid.Empty, factoryGuid); } } }
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 project = TestData.GetPath("TestData\\ProjectUpgrade\\OldCommonTargets.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 OldCommonTargets.pyproj")); Assert.AreEqual(1, actual, string.Format("Wrong result for OldCommonTargets.pyproj")); Assert.AreEqual(project, newLocation, string.Format("Wrong location for OldCommonTargets.pyproj")); var text = File.ReadAllText(project); Assert.IsTrue( text.Contains("<Import Project=\"" + PythonProjectFactory.CommonTargets + "\" Condition=\"!Exists($(PtvsTargetsFile)"), string.Format("Upgraded OldCommonTargets.pyproj should conditionally import from $(VSToolsPath)") ); Assert.IsTrue( text.Contains("<VisualStudioVersion"), string.Format("Upgraded OldCommonTargets.pyproj should define $(VisualStudioVersion)") ); Assert.IsTrue( text.Contains("<PtvsTargetsFile>" + PythonProjectFactory.PtvsTargets), string.Format("Upgraded OldCommonTargets.pyproj should define $(PtvsTargetsFile)") ); Assert.IsTrue( text.Contains("<Import Project=\"$(PtvsTargetsFile)\" Condition=\"Exists($(PtvsTargetsFile))\""), string.Format("Upgraded OldCommonTargets.pyproj should import $(PtvsTargetsFile)") ); Assert.AreEqual(Guid.Empty, factoryGuid); } }
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); } } }
private void Backup() { if (File.Exists(_studyStorageLocation.GetStudyXmlPath())) { try { _backupPath = FileUtils.Backup(_studyStorageLocation.GetStudyXmlPath(), ProcessorContext.BackupDirectory); } catch (IOException) { _backupPath = null; throw; } } }
public void InterpreterIdUpgrade() { // 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 = "CPythonInterpreterId.pyproj", Expected = 1, Id = "Global|PythonCore|2.7|x86" }, new { Name = "CPython35InterpreterId.pyproj", Expected = 1, Id = "Global|PythonCore|3.5-32|x86" }, new { Name = "CPythonx64InterpreterId.pyproj", Expected = 1, Id = "Global|PythonCore|3.5|x64" }, new { Name = "MSBuildInterpreterId.pyproj", Expected = 1, Id = "MSBuild|env|$(MSBuildProjectFullPath)" }, new { Name = "IronPythonInterpreterId.pyproj", Expected = 1, Id = "IronPython|2.7-32" }, }) { 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), "<InterpreterId>{0}</InterpreterId>".FormatInvariant(testCase.Id) ); Assert.AreEqual(Guid.Empty, factoryGuid); } } }
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( 1, text.FindIndexesOf(PythonProjectFactory.PtvsTargets).Count(), "Expected only one import of Python targets file" ); Assert.AreEqual(Guid.Empty, factoryGuid); } }
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-32" }, }) { 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)); Assert.IsFalse( File.ReadAllText(project).Contains("<BaseInterpreter>"), "Project should not contain <BaseInterpreter> element" ); Assert.AreEqual(Guid.Empty, factoryGuid); } } }
private void Backup() { if (File.Exists(_path)) { if (_failOnExists) { throw new AccessViolationException(String.Format("DICOM File unexpectedly already exists: {0}", _path)); } try { _backupPath = FileUtils.Backup(_path, ProcessorContext.BackupDirectory); } catch (IOException) { _backupPath = null; throw; } } }
public void CommonPropsProjectUpgrade() { 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\\OldCommonProps.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 OldCommonProps.pyproj")); Assert.AreEqual(1, actual, string.Format("Wrong result for OldCommonProps.pyproj")); Assert.AreEqual(project, newLocation, string.Format("Wrong location for OldCommonProps.pyproj")); Assert.IsFalse( File.ReadAllText(project).Contains("<Import Project=\"" + PythonProjectFactory.CommonProps), string.Format("Upgraded OldCommonProps.pyproj should not import from $(VSToolsPath)") ); Assert.AreEqual(Guid.Empty, factoryGuid); } }
private void Backup() { if (File.Exists(_path)) { if (_failOnExists) { throw new InstanceAlreadyExistsException(String.Format("DICOM File unexpectedly already exists: {0}", _path)); } try { _backupSpeed.Start(); var fi = new FileInfo(_path); _backupPath = FileUtils.Backup(_path, ProcessorContext.BackupDirectory); _backupSpeed.SetData(fi.Length); _backupSpeed.End(); } catch (IOException) { _backupPath = null; throw; } } }
private static void CloudProjectTest(PythonVisualStudioApp app, string roleType, bool openServiceDefinition) { Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType); Assembly asm = null; try { asm = Assembly.Load("Microsoft.VisualStudio.CloudService.Wizard,Version=1.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"); } catch { // Failed to load - we'll skip the test below } if (asm != null && asm.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false) .OfType <AssemblyFileVersionAttribute>() .Any(a => { Version ver; return(Version.TryParse(a.Version, out ver) && ver < new Version(2, 5)); }) ) { Assert.Inconclusive("Test requires Microsoft Azure Tools 2.5 or later"); } using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"))) { app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3); var ccproj = app.Dte.Solution.Projects.Cast <Project>().FirstOrDefault(p => p.Name == "CloudProject"); Assert.IsNotNull(ccproj); if (openServiceDefinition) { var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open(); wnd.Activate(); app.OnDispose(() => wnd.Close()); } IVsHierarchy hier; var sln = app.GetService <IVsSolution>(typeof(SVsSolution)); ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier)); var pyproj = app.Dte.Solution.Projects.Cast <Project>().FirstOrDefault(p => p.Name == roleType + "Role1"); Assert.IsNotNull(pyproj); app.ServiceProvider.GetUIThread().InvokeAsync(() => { Assert.IsNotNull(pyproj.GetPythonProject()); ((IAzureRoleProject)pyproj.GetPythonProject()).AddedAsRole(hier, roleType); }).GetAwaiter().GetResult(); // AddedAsRole runs in the background, so wait a second for it to // do its thing. Thread.Sleep(1000); var doc = new XmlDocument(); for (int retries = 5; retries > 0; --retries) { try { doc.Load(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef")); break; } catch (IOException ex) { Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex); } catch (XmlException) { var copyTo = TestData.GetPath(@"TestData\CloudProject\" + Path.GetRandomFileName()); File.Copy(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"), copyTo); Console.WriteLine("Copied file to " + copyTo); throw; } Thread.Sleep(100); } var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"); doc.Save(Console.Out); var nav = doc.CreateNavigator(); if (roleType == "Web") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='ps.cmd ConfigureCloudService.ps1']", ns )); } else if (roleType == "Worker") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='bin\\ps.cmd ConfigureCloudService.ps1']", ns )); Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='bin\\ps.cmd LaunchWorker.ps1 worker.py']", ns )); } } }
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 } }) { // Use a copy of the project so we don't interfere with other // tests using them. var project = TestData.GetPath("TestData", "ProjectUpgrade", testCase.Name); using (FileUtils.Backup(project)) { var origText = File.ReadAllText(project); var hr = upgrade.UpgradeProject( project, 0u, // no backups null, out global::System.String newLocation, null, out global::System.Int32 actual, out Guid 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)); var text = File.ReadAllText(project); if (testCase.Expected != 0) { Assert.IsFalse( text.Contains("<Import Project=\"$(VSToolsPath)"), string.Format("Upgraded {0} should not import from $(VSToolsPath)", testCase.Name) ); Assert.IsTrue( text.Contains("Microsoft.PythonTools.Web.targets"), string.Format("Upgraded {0} should import Web.targets", testCase.Name) ); Assert.IsTrue( text.Contains("<PythonWsgiHandler>"), string.Format("Upgraded {0} should contain <PythonWsgiHandler>", testCase.Name) ); } else { Assert.IsTrue( text == origText, string.Format("Non-upgraded {0} has different content to original", testCase.Name) ); } Assert.AreEqual(Guid.Empty, factoryGuid); } } }
private void Backup() { _backupPath = FileUtils.Backup(_path, ProcessorContext.BackupDirectory); }
private static void CloudProjectTest(string roleType, bool openServiceDefinition) { Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType); using (var app = new VisualStudioApp()) using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"))) { app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3); var ccproj = app.Dte.Solution.Projects.Cast <EnvDTE.Project>().FirstOrDefault(p => p.Name == "CloudProject"); Assert.IsNotNull(ccproj); if (openServiceDefinition) { var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open(); wnd.Activate(); app.OnDispose(() => wnd.Close()); } IVsHierarchy hier; var sln = app.GetService <IVsSolution>(typeof(SVsSolution)); ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier)); app.ServiceProvider.GetUIThread().Invoke(() => NodejsProject.UpdateServiceDefinition( hier, roleType, roleType + "Role1", new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)app.Dte) ) ); var doc = new XmlDocument(); for (int retries = 5; retries > 0; --retries) { try { doc.Load(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef")); break; } catch (IOException ex) { Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex); } catch (XmlException) { var copyTo = TestData.GetPath(@"TestData\CloudProject\CloudProject\" + Path.GetRandomFileName()); File.Copy(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"), copyTo); Console.WriteLine("Copied file to " + copyTo); throw; } Thread.Sleep(100); } var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"); doc.Save(Console.Out); var nav = doc.CreateNavigator(); if (roleType == "Web") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='setup_web.cmd > log.txt']", ns )); } else if (roleType == "Worker") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='setup_worker.cmd > log.txt']", ns )); Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='node.cmd .\\server.js']", ns )); } } }