本文整理汇总了C#中TestUtilities.UI.Python.PythonVisualStudioApp.CreateProject方法的典型用法代码示例。如果您正苦于以下问题:C# PythonVisualStudioApp.CreateProject方法的具体用法?C# PythonVisualStudioApp.CreateProject怎么用?C# PythonVisualStudioApp.CreateProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestUtilities.UI.Python.PythonVisualStudioApp
的用法示例。
在下文中一共展示了PythonVisualStudioApp.CreateProject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartNewApp
public void StartNewApp() {
using (var app = new PythonVisualStudioApp()) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.DjangoWebProjectTemplate,
TestData.GetTempPath(),
"StartNewApp"
);
app.SolutionExplorerTreeView.SelectProject(project);
using (var newAppDialog = NewAppDialog.FromDte(app)) {
newAppDialog.AppName = "Fob";
newAppDialog.OK();
}
app.SolutionExplorerTreeView.WaitForItem(
app.Dte.Solution.FullName,
app.Dte.Solution.Projects.Item(1).Name,
"Fob",
"models.py"
);
var appFolder = project.ProjectItems.Item("Fob");
Assert.IsNotNull(appFolder.Collection.Item("models.py"));
Assert.IsNotNull(appFolder.Collection.Item("tests.py"));
Assert.IsNotNull(appFolder.Collection.Item("views.py"));
Assert.IsNotNull(appFolder.Collection.Item("__init__.py"));
app.SolutionExplorerTreeView.SelectProject(project);
app.Dte.ExecuteCommand("Project.ValidateDjangoApp");
var console = app.GetInteractiveWindow("Django Management Console - " + project.Name);
Assert.IsNotNull(console);
console.WaitForTextEnd("Executing manage.py validate", "0 errors found", "The Python REPL process has exited", ">>> ");
app.SolutionExplorerTreeView.SelectProject(project);
using (var newItem = NewItemDialog.FromDte(app)) {
AutomationWrapper.Select(newItem.ProjectTypes.FindItem("HTML Page"));
newItem.FileName = "NewPage.html";
newItem.OK();
}
System.Threading.Thread.Sleep(1000);
Assert.IsNotNull(project.ProjectItems.Item("NewPage.html"));
}
}
示例2: DjangoCommandsNonDjangoApp
public void DjangoCommandsNonDjangoApp() {
using (var app = new PythonVisualStudioApp()) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.PythonApplicationTemplate,
TestData.GetTempPath(),
"DjangoCommandsNoDjangoApp"
);
app.SolutionExplorerTreeView.SelectProject(project);
try {
app.Dte.ExecuteCommand("Project.ValidateDjangoApp");
Assert.Fail("Expected COMException");
} catch (COMException e) {
// requires a Django project
Assert.IsTrue(e.Message.Contains("is not valid"), e.ToString());
}
try {
app.Dte.ExecuteCommand("Project.DjangoSyncDB");
Assert.Fail("Expected COMException");
} catch (COMException e) {
// requires a Django project
Assert.IsTrue(e.Message.Contains("is not valid"), e.ToString());
}
}
}
示例3: EndToEndTest
private void EndToEndTest(
string templateName,
string moduleName,
string textInResponse,
string pythonVersion,
string packageName = null
) {
EndToEndLog("Starting {0} {1}", templateName, pythonVersion);
using (var app = new PythonVisualStudioApp()) {
var pyProj = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
templateName,
TestData.GetTempPath(),
TestContext.TestName
).GetPythonProject();
EndToEndLog("Created project {0}", pyProj.ProjectFile);
Assert.IsInstanceOfType(pyProj.GetLauncher(), typeof(PythonWebLauncher));
IPythonInterpreterFactory factory;
// Abort analysis so we don't have too many python.exe processes
// floating around.
using (new ProcessScope("Microsoft.PythonTools.Analyzer")) {
factory = CreateVirtualEnvironment(pythonVersion, app, pyProj);
EndToEndLog("Created virtual environment {0}", factory.Configuration.Description);
InstallWebFramework(app, moduleName, packageName ?? moduleName, factory);
EndToEndLog("Installed framework {0}", moduleName);
}
EndToEndLog("Aborted analysis");
app.ServiceProvider.GetUIThread().Invoke(() => {
pyProj.SetProjectProperty("WebBrowserUrl", "");
pyProj.SetProjectProperty("WebBrowserPort", "23457");
});
EndToEndLog("Set WebBrowserPort to 23457");
LaunchAndVerifyNoDebug(app, 23457, textInResponse);
EndToEndLog("Verified without debugging");
app.ServiceProvider.GetUIThread().Invoke(() => {
pyProj.SetProjectProperty("WebBrowserUrl", "");
pyProj.SetProjectProperty("WebBrowserPort", "23456");
});
EndToEndLog("Set WebBrowserPort to 23456");
LaunchAndVerifyDebug(app, 23456, textInResponse);
EndToEndLog("Verified with debugging");
}
}
示例4: 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");
}
}
示例5: 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");
}
}
示例6: WorkerProjectAddSupportFiles
public void WorkerProjectAddSupportFiles() {
using (var app = new PythonVisualStudioApp()) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.PythonApplicationTemplate,
TestData.GetTempPath(),
"WorkerProjectAddSupportFiles"
);
// Ensure the bin directory already exists
Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(project.FullName), "bin"));
var previousItems = project.ProjectItems.Cast<ProjectItem>().Select(p => p.Name).ToSet(StringComparer.CurrentCultureIgnoreCase);
// Add the items
app.AddItem(project, PythonVisualStudioApp.TemplateLanguageName, PythonVisualStudioApp.WorkerRoleSupportTemplate, "bin");
var newItems = project.ProjectItems.Cast<ProjectItem>().Where(p => !previousItems.Contains(p.Name)).ToList();
AssertUtil.ContainsExactly(newItems.Select(i => i.Name), "bin");
var children = newItems[0].ProjectItems.Cast<ProjectItem>().Select(i => i.Name).ToSet(StringComparer.CurrentCultureIgnoreCase);
AssertUtil.ContainsExactly(children, "ConfigureCloudService.ps1", "LaunchWorker.ps1", "ps.cmd", "Readme.mht");
}
}
示例7: WebProjectAddSupportFiles
public void WebProjectAddSupportFiles() {
using (var app = new PythonVisualStudioApp()) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.EmptyWebProjectTemplate,
TestData.GetTempPath(),
"WebProjectAddSupportFiles"
);
var proj = project.GetCommonProject();
Assert.IsNotNull(proj);
var previousItems = project.ProjectItems.Cast<ProjectItem>().Select(p => p.Name).ToSet(StringComparer.CurrentCultureIgnoreCase);
// Add the items
app.AddItem(project, PythonVisualStudioApp.TemplateLanguageName, PythonVisualStudioApp.WebRoleSupportTemplate, "bin");
var newItems = project.ProjectItems.Cast<ProjectItem>().Where(p => !previousItems.Contains(p.Name)).ToList();
AssertUtil.ContainsExactly(newItems.Select(i => i.Name), "bin");
var children = newItems[0].ProjectItems.Cast<ProjectItem>().Select(i => i.Name).ToSet(StringComparer.CurrentCultureIgnoreCase);
AssertUtil.ContainsExactly(children, "ConfigureCloudService.ps1", "ps.cmd", "Readme.mht");
}
}
示例8: WebProjectBuildWarnings
public void WebProjectBuildWarnings() {
using (var app = new PythonVisualStudioApp())
using (app.SelectDefaultInterpreter(PythonPaths.Python33 ?? PythonPaths.Python33_x64)) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.EmptyWebProjectTemplate,
TestData.GetTempPath(),
"WebProjectBuildWarnings"
);
var proj = project.GetPythonProject();
Assert.IsNotNull(proj);
Assert.AreEqual(new Version(3, 3), app.ServiceProvider.GetUIThread().Invoke(() => proj.GetLaunchConfigurationOrThrow().Interpreter.Version));
for (int iteration = 0; iteration <= 2; ++iteration) {
var warnings = app.ServiceProvider.GetUIThread().Invoke(() => {
var buildPane = app.GetOutputWindow("Build");
buildPane.Clear();
project.DTE.Solution.SolutionBuild.Clean(true);
project.DTE.Solution.SolutionBuild.Build(true);
var text = app.GetOutputWindowText("Build");
Console.WriteLine(text);
return text.Split('\r', '\n')
.Select(s => Regex.Match(s, @"warning\s*:\s*(?<msg>.+)"))
.Where(m => m.Success)
.Select(m => m.Groups["msg"].Value)
.ToList();
});
Console.WriteLine("Warnings:{0}{1}", Environment.NewLine, string.Join(Environment.NewLine, warnings));
if (iteration < 2) {
Assert.IsNotNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, @"Python( 64-bit)? 3\.3 is not natively supported.+")),
"Missing \"not natively supported\" warning"
);
} else {
// Third time through, we've fixed this warning.
Assert.IsNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, @"Python( 64-bit)? 3\.3 is not natively supported.+")),
"Still recieved \"not natively supported\" warning"
);
}
if (iteration < 1) {
Assert.IsNotNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, "Using old configuration tools.+")),
"Missing \"old configuration tools\" warning"
);
} else {
// Second time through, we've fixed this warning.
Assert.IsNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, "Using old configuration tools.+")),
"Still received \"old configuration tools\" warning"
);
}
switch (iteration) {
case 0:
app.AddItem(project, PythonVisualStudioApp.TemplateLanguageName, PythonVisualStudioApp.WebRoleSupportTemplate, "bin");
break;
case 1:
var model = app.GetService<IComponentModel>(typeof(SComponentModel));
var interpreterService = model.GetService<IInterpreterRegistryService>();
var optionsService = model.GetService<IInterpreterOptionsService>();
var newInterpreter = interpreterService.FindInterpreter("Global|PythonCore|3.4|x86")
?? interpreterService.FindInterpreter("Global|PythonCore|2.7|x86");
Assert.IsNotNull(newInterpreter);
optionsService.DefaultInterpreter = newInterpreter;
break;
}
}
}
}
示例9: WebProjectStaticUri
public void WebProjectStaticUri() {
using (var app = new PythonVisualStudioApp()) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.EmptyWebProjectTemplate,
TestData.GetTempPath(),
"WebProjectStaticUri"
);
var proj = project.GetCommonProject();
Assert.IsNotNull(proj);
app.ServiceProvider.GetUIThread().Invoke(() => {
proj.SetProjectProperty("PythonWsgiHandler", "NoHandler");
proj.SetProjectProperty("StaticUriPattern", "");
proj.SetProjectProperty("StaticUriRewrite", "");
});
app.ExecuteCommand("Build.RebuildSolution");
app.WaitForOutputWindowText("Build", "1 succeeded");
var webConfig = File.ReadAllText(Path.Combine(Path.GetDirectoryName(project.FullName), "web.config"));
if (!webConfig.Contains(@"<add input=""true"" pattern=""false"" />")) {
Assert.Fail(string.Format("Did not find Static Files condition in:{0}{0}{1}",
Environment.NewLine,
webConfig
));
}
app.ServiceProvider.GetUIThread().Invoke(() => {
proj.SetProjectProperty("StaticUriPattern", "^static/.*$");
});
app.ExecuteCommand("Build.RebuildSolution");
app.WaitForOutputWindowText("Build", "1 succeeded");
webConfig = File.ReadAllText(Path.Combine(Path.GetDirectoryName(project.FullName), "web.config"));
if (!webConfig.Contains(@"<add input=""{REQUEST_URI}"" pattern=""^static/.*$"" ignoreCase=""true"" negate=""true"" />")) {
Assert.Fail(string.Format("Did not find rewrite condition in:{0}{0}{1}",
Environment.NewLine,
webConfig
));
}
if (!webConfig.Contains(@"<add input=""true"" pattern=""false"" />")) {
Assert.Fail(string.Format("Did not find Static Files condition in:{0}{0}{1}",
Environment.NewLine,
webConfig
));
}
app.ServiceProvider.GetUIThread().Invoke(() => {
proj.SetProjectProperty("StaticUriRewrite", "static_files/{R:1}");
});
app.ExecuteCommand("Build.RebuildSolution");
app.WaitForOutputWindowText("Build", "1 succeeded");
webConfig = File.ReadAllText(Path.Combine(Path.GetDirectoryName(project.FullName), "web.config"));
if (webConfig.Contains(@"<add input=""{REQUEST_URI}"" pattern=""^static/.*$"" ignoreCase=""true"" negate=""true"" />")) {
Assert.Fail(string.Format("Found old rewrite condition in:{0}{0}{1}",
Environment.NewLine,
webConfig
));
}
if (!webConfig.Contains(@"<action type=""Rewrite"" url=""static_files/{R:1}"" appendQueryString=""true"" />")) {
Assert.Fail(string.Format("Did not find rewrite action in:{0}{0}{1}",
Environment.NewLine,
webConfig
));
}
if (webConfig.Contains(@"<add input=""true"" pattern=""false"" />")) {
Assert.Fail(string.Format("Should not have found Static Files condition in:{0}{0}{1}",
Environment.NewLine,
webConfig
));
}
app.ServiceProvider.GetUIThread().Invoke(() => {
proj.SetProjectProperty("StaticUriPattern", "invalid[pattern");
});
app.ExecuteCommand("Build.RebuildSolution");
app.WaitForOutputWindowText("Build", "1 failed");
}
}