本文整理匯總了C#中TestUtilities.UI.Python.PythonVisualStudioApp.WaitForDialog方法的典型用法代碼示例。如果您正苦於以下問題:C# PythonVisualStudioApp.WaitForDialog方法的具體用法?C# PythonVisualStudioApp.WaitForDialog怎麽用?C# PythonVisualStudioApp.WaitForDialog使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TestUtilities.UI.Python.PythonVisualStudioApp
的用法示例。
在下文中一共展示了PythonVisualStudioApp.WaitForDialog方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CustomCommandsRequiredPackages
public void CustomCommandsRequiredPackages() {
using (var app = new PythonVisualStudioApp())
using (var dis = app.SelectDefaultInterpreter(PythonVersion, "virtualenv")) {
PythonProjectNode node;
EnvDTE.Project proj;
OpenProject(app, "CommandRequirePackages.sln", out node, out proj);
string envName;
var env = app.CreateVirtualEnvironment(proj, out envName);
env.Select();
app.Dte.ExecuteCommand("Python.ActivateEnvironment");
// Ensure that no error dialog appears
app.WaitForNoDialog(TimeSpan.FromSeconds(5.0));
// First, execute the command and cancel it.
var task = ExecuteAsync(node, "Require Packages");
try {
var dialogHandle = app.WaitForDialog(task);
if (dialogHandle == IntPtr.Zero) {
if (task.IsFaulted && task.Exception != null) {
Assert.Fail("Unexpected exception in package install confirmation dialog:\n{0}", task.Exception);
} else {
Assert.AreNotEqual(IntPtr.Zero, dialogHandle);
}
}
using (var dialog = new AutomationDialog(app, AutomationElement.FromHandle(dialogHandle))) {
var label = dialog.FindByAutomationId("CommandLink_1000");
Assert.IsNotNull(label);
string expectedLabel =
"The following packages will be installed using pip:\r\n" +
"\r\n" +
"ptvsd\r\n" +
"azure==0.1"; ;
Assert.AreEqual(expectedLabel, label.Current.HelpText);
dialog.Cancel();
try {
task.Wait(1000);
Assert.Fail("Command was not canceled after dismissing the package install confirmation dialog");
} catch (AggregateException ex) {
if (!(ex.InnerException is TaskCanceledException)) {
throw;
}
}
}
} finally {
if (!task.IsCanceled && !task.IsCompleted && !task.IsFaulted) {
if (task.Wait(10000)) {
task.Dispose();
}
} else {
task.Dispose();
}
}
// Then, execute command and allow it to proceed.
task = ExecuteAsync(node, "Require Packages");
try {
var dialogHandle = app.WaitForDialog(task);
if (dialogHandle == IntPtr.Zero) {
if (task.IsFaulted && task.Exception != null) {
Assert.Fail("Unexpected exception in package install confirmation dialog:\n{0}", task.Exception);
} else {
Assert.AreNotEqual(IntPtr.Zero, dialogHandle);
}
}
using (var dialog = new AutomationDialog(app, AutomationElement.FromHandle(dialogHandle))) {
dialog.ClickButtonAndClose("CommandLink_1000", nameIsAutomationId: true);
}
task.Wait();
var ver = PythonVersion.Version.ToVersion();
ExpectOutputWindowText(app, string.Format("pass {0}.{1}", ver.Major, ver.Minor));
} finally {
if (!task.IsCanceled && !task.IsCompleted && !task.IsFaulted) {
if (task.Wait(10000)) {
task.Dispose();
}
} else {
task.Dispose();
}
}
}
}
示例2: RenameProjectToExisting
public void RenameProjectToExisting() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\RenameProjectTestUI.sln");
app.OpenSolutionExplorer();
var window = app.SolutionExplorerTreeView;
// find Program.py, send copy & paste, verify copy of file is there
var projectNode = window.FindItem("Solution 'RenameProjectTestUI' (1 project)", "HelloWorld");
// rename once, cancel renaming to existing file....
AutomationWrapper.Select(projectNode);
Keyboard.PressAndRelease(Key.F2);
System.Threading.Thread.Sleep(100);
Keyboard.Type("HelloWorldExisting");
System.Threading.Thread.Sleep(100);
Keyboard.PressAndRelease(Key.Enter);
IntPtr dialog = app.WaitForDialog();
VisualStudioApp.CheckMessageBox("HelloWorldExisting.pyproj", "overwrite");
// rename again, don't cancel...
AutomationWrapper.Select(projectNode);
Keyboard.PressAndRelease(Key.F2);
System.Threading.Thread.Sleep(100);
Keyboard.Type("HelloWorldExisting");
System.Threading.Thread.Sleep(100);
Keyboard.PressAndRelease(Key.Enter);
dialog = app.WaitForDialog();
VisualStudioApp.CheckMessageBox(MessageBoxButton.Yes, "HelloWorldExisting.pyproj", "overwrite");
Assert.IsNotNull(window.WaitForItem("Solution 'RenameProjectTestUI' (1 project)", "HelloWorldExisting"));
}
}
示例3: RenameItemsTest
public void RenameItemsTest() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\RenameItemsTestUI.sln");
var window = app.OpenSolutionExplorer();
// find Program.py, send copy & paste, verify copy of file is there
var node = window.FindChildOfProject(project, "Program.py");
// rename once, cancel renaming to existing file....
node.Select();
Keyboard.PressAndRelease(Key.F2);
System.Threading.Thread.Sleep(100);
Keyboard.PressAndRelease(Key.A, Key.LeftCtrl);
Keyboard.Type("NewName.txt");
System.Threading.Thread.Sleep(100);
Keyboard.PressAndRelease(Key.Enter);
IntPtr dialog = app.WaitForDialog();
VisualStudioApp.CheckMessageBox(MessageBoxButton.Cancel, "file name extension");
// rename again, don't cancel...
node.Select();
Keyboard.PressAndRelease(Key.F2);
System.Threading.Thread.Sleep(100);
Keyboard.PressAndRelease(Key.A, Key.LeftCtrl);
Keyboard.Type("NewName.txt");
System.Threading.Thread.Sleep(100);
Keyboard.PressAndRelease(Key.Enter);
dialog = app.WaitForDialog();
VisualStudioApp.CheckMessageBox(MessageBoxButton.Yes, "file name extension");
Assert.IsNotNull(window.WaitForChildOfProject(project, "NewName.txt"));
}
}
示例4: TestLaunchWithErrorsRun
public void TestLaunchWithErrorsRun() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\ErrorProject.sln");
GetOptions().PromptBeforeRunningWithBuildErrorSetting = true;
var debug3 = (Debugger3)app.Dte.Debugger;
ThreadPool.QueueUserWorkItem(x => debug3.Go(true));
var dialog = new PythonLaunchWithErrorsDialog(app.WaitForDialog());
dialog.No();
// make sure we don't go into debug mode
for (int i = 0; i < 10; i++) {
Assert.AreEqual(dbgDebugMode.dbgDesignMode, app.Dte.Debugger.CurrentMode);
System.Threading.Thread.Sleep(100);
}
WaitForMode(app, dbgDebugMode.dbgDesignMode);
}
}
示例5: NewProfilingSession
public void NewProfilingSession() {
PythonPaths.Python27.AssertInstalled();
var testFile = TestData.GetPath(@"TestData\ProfileTest\Program.py");
Assert.IsTrue(File.Exists(testFile), "ProfileTest\\Program.py does not exist");
using (var app = new PythonVisualStudioApp()) {
app.OpenPythonPerformance();
app.PythonPerformanceExplorerToolBar.NewPerfSession();
var profiling = (IPythonProfiling)app.Dte.GetObject("PythonProfiling");
app.OpenPythonPerformance();
var perf = app.PythonPerformanceExplorerTreeView.WaitForItem("Performance *");
Assert.IsNotNull(perf);
var session = profiling.GetSession(1);
Assert.IsNotNull(session);
Mouse.MoveTo(perf.GetClickablePoint());
Mouse.DoubleClick(System.Windows.Input.MouseButton.Left);
// wait for the dialog, set some settings, save them.
using (var perfTarget = new PythonPerfTarget(app.WaitForDialog())) {
perfTarget.SelectProfileScript();
perfTarget.InterpreterComboBox.SelectItem("Python 2.7");
perfTarget.ScriptName = testFile;
perfTarget.WorkingDir = Path.GetDirectoryName(testFile);
try {
perfTarget.Ok();
} catch (ElementNotEnabledException) {
Assert.Fail("Settings were invalid:\n ScriptName = {0}\n Interpreter = {1}",
perfTarget.ScriptName, perfTarget.SelectedInterpreter);
}
}
app.WaitForDialogDismissed();
Mouse.MoveTo(perf.GetClickablePoint());
Mouse.DoubleClick(System.Windows.Input.MouseButton.Left);
// re-open the dialog, verify the settings
using (var perfTarget = new PythonPerfTarget(app.WaitForDialog())) {
Assert.AreEqual("Python 2.7", perfTarget.SelectedInterpreter);
Assert.AreEqual(TestData.GetPath(@"TestData\ProfileTest\Program.py"), perfTarget.ScriptName);
}
}
}
示例6: LaunchSession
private IPythonProfileSession LaunchSession(
PythonVisualStudioApp app,
Func<IPythonProfileSession> creator
) {
// Ensure the performance window has been opened, which will make
// the app clean up all sessions when it is disposed.
app.OpenPythonPerformance();
IPythonProfileSession session = null;
var task = Task.Factory.StartNew(() => {
session = creator();
// Must fault the task to abort the wait
throw new Exception();
});
var dialog = app.WaitForDialog(task);
if (dialog != IntPtr.Zero) {
using (var saveDialog = new SaveDialog(app, AutomationElement.FromHandle(dialog))) {
var originalDestName = Path.Combine(SaveDirectory, Path.GetFileName(saveDialog.FileName));
var destName = originalDestName;
while (File.Exists(destName)) {
destName = string.Format("{0} {1}{2}",
Path.GetFileNameWithoutExtension(originalDestName),
Guid.NewGuid(),
Path.GetExtension(originalDestName)
);
}
saveDialog.FileName = destName;
saveDialog.Save();
try {
task.Wait(TimeSpan.FromSeconds(5.0));
Assert.Fail("Task did not fault");
} catch (AggregateException) {
}
}
} else {
// Ensure the exception is observed
var ex = task.Exception;
}
Assert.IsNotNull(session, "Session was not correctly initialized");
return session;
}
示例7: WebProjectInstallOnNew
public void WebProjectInstallOnNew() {
using (var app = new PythonVisualStudioApp()) {
app.OptionsService.DefaultInterpreter.PipUninstall("bottle");
var t = Task.Run(() => app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.BottleWebProjectTemplate,
TestData.GetTempPath(),
"WebProjectInstallOnNew",
suppressUI: false
));
using (var dlg = new AutomationDialog(app, AutomationElement.FromHandle(app.WaitForDialog(t)))) {
// Install to active environment
dlg.ClickButtonAndClose("CommandLink_1001", nameIsAutomationId: true);
}
var project = t.WaitAndUnwrapExceptions();
Assert.AreSame(app.OptionsService.DefaultInterpreter, project.GetPythonProject().ActiveInterpreter);
for (int retries = 60; retries > 0; --retries) {
if (project.GetPythonProject().ActiveInterpreter.FindModules("bottle").Any()) {
break;
}
Thread.Sleep(1000);
}
AssertUtil.ContainsExactly(project.GetPythonProject().ActiveInterpreter.FindModules("bottle"), "bottle");
app.OptionsService.DefaultInterpreter.PipUninstall("bottle");
}
}
示例8: WebProjectCreateVirtualEnvOnNew
public void WebProjectCreateVirtualEnvOnNew() {
using (var app = new PythonVisualStudioApp()) {
var t = Task.Run(() => app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.FlaskWebProjectTemplate,
TestData.GetTempPath(),
"WebProjectCreateVirtualEnvOnNew",
suppressUI: false
));
using (var dlg = new AutomationDialog(app, AutomationElement.FromHandle(app.WaitForDialog(t)))) {
// Create a virtual environment
dlg.ClickButtonAndClose("CommandLink_1000", nameIsAutomationId: true);
}
using (var dlg = new AutomationDialog(app, AutomationElement.FromHandle(app.WaitForDialog(t)))) {
dlg.ClickButtonByAutomationId("Create");
dlg.ClickButtonAndClose("Close", nameIsAutomationId: true);
}
var project = t.WaitAndUnwrapExceptions();
var contextProvider = app.ComponentModel.GetService<VsProjectContextProvider>();
for (int retries = 20; retries > 0; --retries) {
if (contextProvider.IsProjectSpecific(project.GetPythonProject().ActiveInterpreter.Configuration)) {
break;
}
Thread.Sleep(1000);
}
Assert.IsTrue(contextProvider.IsProjectSpecific(project.GetPythonProject().ActiveInterpreter.Configuration), "Did not have virtualenv");
for (int retries = 60; retries > 0; --retries) {
if (project.GetPythonProject().ActiveInterpreter.FindModules("flask").Any()) {
break;
}
Thread.Sleep(1000);
}
AssertUtil.ContainsExactly(project.GetPythonProject().ActiveInterpreter.FindModules("flask"), "flask");
}
}