public static void CloseAll(VisualStudioApp app = null) { IComponentModel compModel; if (app != null) { compModel = app.GetService<IComponentModel>(typeof(SComponentModel)); } else { compModel = (IComponentModel)VSTestContext.ServiceProvider.GetService(typeof(SComponentModel)); } var replWindowProvider = compModel.GetService<IReplWindowProvider>(); foreach (var frame in replWindowProvider.GetReplWindows() .OfType<ReplWindow>() .Select(r => r.Frame) .OfType<IVsWindowFrame>()) { frame.Hide(); } }
public InteractiveWindow(string title, AutomationElement element, VisualStudioApp app) : base(null, element) { _app = app; _title = title; var compModel = _app.GetService<IComponentModel>(typeof(SComponentModel)); var replWindowProvider = compModel.GetService<IReplWindowProvider>(); _replWindow = replWindowProvider.GetReplWindows() .OfType<ReplWindow>() .FirstOrDefault(p => p.Title.Equals(title, StringComparison.CurrentCulture)); _replWindowInfo = _replWindows.GetValue(_replWindow, window => { var info = new ReplWindowInfo(); window.ReadyForInput += new Action(info.OnReadyForInput); return info; }); }
public void TestPublishFilesImpersonateCancelCredentials() { WNetCancelConnection2(TestSharePrivate, 0, true); using (var app = new VisualStudioApp()) { try { var project = app.OpenProject(@"TestData\HelloWorld.sln"); string subDir = Guid.NewGuid().ToString(); project.Properties.Item("PublishUrl").Value = Path.Combine(TestSharePrivate, subDir); app.OnDispose(() => project.Properties.Item("PublishUrl").Value = ""); string dir = Path.Combine(TestSharePrivate, subDir); app.OpenSolutionExplorer().SelectProject(project); using (var creds = CredentialsDialog.PublishSelection(app)) { creds.UserName = PrivateShareUser; creds.Password = PrivateSharePasswordIncorrect; creds.Cancel(); } var statusBar = app.GetService<IVsStatusbar>(typeof(SVsStatusbar)); string text = null; const string expected = "Publish failed: Access to the path"; for (int i = 0; i < 10; i++) { ErrorHandler.ThrowOnFailure(statusBar.GetText(out text)); if (text.StartsWith(expected)) { break; } System.Threading.Thread.Sleep(1000); } Assert.IsTrue(text.StartsWith(expected), "Expected '{0}', got '{1}'", expected, text); } finally { WNetCancelConnection2(TestSharePrivate, 0, true); } } }
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 )); } } }
private static void LaunchAndVerifyNoDebug( VisualStudioApp app, int port, string textInResponse ) { bool prevNormal = true, prevAbnormal = true; string text; int retries; try { using (var processes = new ProcessScope("python")) { EndToEndLog("Transitioning to UI thread to build"); app.ServiceProvider.GetUIThread().Invoke(() => { EndToEndLog("Building"); app.Dte.Solution.SolutionBuild.Build(true); EndToEndLog("Updating settings"); prevNormal = app.GetService <PythonToolsService>().DebuggerOptions.WaitOnNormalExit; prevAbnormal = app.GetService <PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit; app.GetService <PythonToolsService>().DebuggerOptions.WaitOnNormalExit = false; app.GetService <PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit = false; EndToEndLog("Starting running"); app.Dte.Solution.SolutionBuild.Run(); EndToEndLog("Running"); }); var newProcesses = processes.WaitForNewProcess(TimeSpan.FromSeconds(30)).ToList(); Assert.IsTrue(newProcesses.Any(), "Did not find new Python process"); EndToEndLog("Found new processes with IDs {0}", string.Join(", ", newProcesses.Select(p => p.Id.ToString()))); for (retries = 100; retries > 0 && !IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(p => p.Port == port); --retries) { Thread.Sleep(300); } EndToEndLog("Active at http://localhost:{0}/", port); text = WebDownloadUtility.GetString(new Uri(string.Format("http://localhost:{0}/", port))); } } finally { app.ServiceProvider.GetUIThread().Invoke(() => { app.GetService <PythonToolsService>().DebuggerOptions.WaitOnNormalExit = prevNormal; app.GetService <PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit = prevAbnormal; }); } EndToEndLog("Response from http://localhost:{0}/", port); EndToEndLog(text); Assert.IsTrue(text.Contains(textInResponse), text); for (retries = 20; retries > 0 && !IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().All(p => p.Port != port); --retries) { Thread.Sleep(500); } if (retries > 0) { EndToEndLog("Process ended"); } else { EndToEndLog("Timed out waiting for process to exit"); } }
private static void CloudProjectTest(string roleType, bool openServiceDefinition) { Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType); var asm = Assembly.Load("Microsoft.VisualStudio.CloudService.Wizard,Version=1.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"); 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 (var app = new VisualStudioApp()) 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)); app.ServiceProvider.GetUIThread().InvokeAsync(() => PythonProjectNode.UpdateServiceDefinition(hier, roleType, roleType + "Role1", app.ServiceProvider) ).GetAwaiter().GetResult(); 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']", ns )); } } }
public InteractiveWindow(string title, AutomationElement element, VisualStudioApp app) : base(null, element) { _app = app; _title = title; var compModel = _app.GetService<IComponentModel>(typeof(SComponentModel)); var replWindowProvider = compModel.GetService<InteractiveWindowProvider>(); _replWindow = replWindowProvider #if DEV14_OR_LATER .GetReplToolWindows() #else .GetReplWindows() #endif .OfType<ToolWindowPane>() .FirstOrDefault(p => p.Caption.Equals(title, StringComparison.CurrentCulture)); #if DEV14_OR_LATER _interactive = ((IVsInteractiveWindow)_replWindow).InteractiveWindow; #else _interactive = (IReplWindow)_replWindow; #endif _replWindowInfo = _replWindows.GetValue(_replWindow, window => { var info = new InteractiveWindowInfo(); _interactive.ReadyForInput += new Action(info.OnReadyForInput); return info; }); }