Exemple #1
0
        public void WorkerProjectAddSupportFiles()
        {
            using (var app = new VisualStudioApp()) {
                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");
            }
        }
Exemple #2
0
        public void AddCloudProject() {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.DjangoWebProjectTemplate,
                    TestData.GetTempPath(),
                    "AddCloudProject"
                );
                app.SolutionExplorerTreeView.SelectProject(project);

                try {
                    app.ExecuteCommand("Project.ConverttoMicrosoftAzureCloudServiceProject");
                } catch (Exception ex1) {
                    try {
                        app.ExecuteCommand("Project.ConverttoWindowsAzureCloudServiceProject");
                    } catch (Exception ex2) {
                        Console.WriteLine("Unable to execute Project.ConverttoWindowsAzureCloudServiceProject.\r\n{0}", ex2);
                        try {
                            app.ExecuteCommand("Project.AddWindowsAzureCloudServiceProject");
                        } catch (Exception ex3) {
                            Console.WriteLine("Unable to execute Project.AddWindowsAzureCloudServiceProject.\r\n{0}", ex3);
                            throw ex1;
                        }
                    }
                }

                var res = app.SolutionExplorerTreeView.WaitForItem(
                    "Solution '" + app.Dte.Solution.Projects.Item(1).Name + "' (2 projects)",
                    app.Dte.Solution.Projects.Item(1).Name + ".Azure"
                );
                Assert.IsNotNull(res);
            }
        }
        public void DebugProjectProperties(VisualStudioApp app, DjangoInterpreterSetter interpreterSetter)
        {
            var project = app.CreateProject(
                PythonVisualStudioApp.TemplateLanguageName,
                PythonVisualStudioApp.DjangoWebProjectTemplate,
                TestData.GetTempPath(),
                "DebugProjectProperties"
                );

            app.SolutionExplorerTreeView.SelectProject(project);

            app.Dte.ExecuteCommand("Project.Properties");
            var window = app.Dte.Windows.OfType <EnvDTE.Window>().FirstOrDefault(w => w.Caption == project.Name);

            Assert.IsNotNull(window);

            window.Activate();
            var hwnd      = window.HWnd;
            var projProps = new ProjectPropertiesWindow(new IntPtr(hwnd));

            // FYI This is broken on Dev15 (15.0 up to latest build as of now 15.3 build 26507)
            // Active page can't be changed via UI automation.
            // Bug 433488 has been filed.
            // - InvokePattern is not available
            // - SelectionItemPattern is available (according to Inspect) but does not work
            // - Default action does nothing
            var debugPage = projProps[new Guid(PythonConstants.DebugPropertyPageGuid)];

            Assert.IsNotNull(debugPage);

            var dbgProps = new PythonProjectDebugProperties(debugPage);

            Assert.AreEqual("Django Web launcher", dbgProps.LaunchMode);
            dbgProps.AssertMatchesProject(project.GetPythonProject());
        }
Exemple #4
0
        private void TestPublishToWebSite(
            string templateName,
            string projectName,
            string moduleName,
            string textInResponse,
            string pythonVersion,
            int publishTimeout,
            string packageName = null
        ) {
            using (var app = new VisualStudioApp()) {
                var pyProj = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    templateName,
                    TestData.GetTempPath(),
                    projectName
                ).GetPythonProject();

                var factory = WebProjectTests.CreateVirtualEnvironment(pythonVersion, app, pyProj);

                WebProjectTests.InstallWebFramework(app, moduleName, packageName ?? moduleName, factory);

                _webSiteToDelete = Guid.NewGuid().ToString("N");
                var siteUri = app.PublishToAzureWebSite(_webSiteToDelete, publishSettingsFilePath);
                app.WaitForBuildComplete(publishTimeout);

                string text = WebDownloadUtility.GetString(siteUri);

                Console.WriteLine("Response from {0}", siteUri);
                Console.WriteLine(text);
                Assert.IsTrue(text.Contains(textInResponse), text);
            }
        }
Exemple #5
0
        public void AddCloudProject()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.DjangoWebProjectTemplate,
                    TestData.GetTempPath(),
                    "AddCloudProject"
                    );
                app.SolutionExplorerTreeView.SelectProject(project);

                try {
                    app.ExecuteCommand("Project.ConverttoMicrosoftAzureCloudServiceProject");
                } catch (Exception ex1) {
                    try {
                        app.ExecuteCommand("Project.ConverttoWindowsAzureCloudServiceProject");
                    } catch (Exception ex2) {
                        Console.WriteLine("Unable to execute Project.ConverttoWindowsAzureCloudServiceProject.\r\n{0}", ex2);
                        try {
                            app.ExecuteCommand("Project.AddWindowsAzureCloudServiceProject");
                        } catch (Exception ex3) {
                            Console.WriteLine("Unable to execute Project.AddWindowsAzureCloudServiceProject.\r\n{0}", ex3);
                            throw ex1;
                        }
                    }
                }

                var res = app.SolutionExplorerTreeView.WaitForItem(
                    "Solution '" + app.Dte.Solution.Projects.Item(1).Name + "' (2 projects)",
                    app.Dte.Solution.Projects.Item(1).Name + ".Azure"
                    );
                Assert.IsNotNull(res);
            }
        }
Exemple #6
0
        public void WebProjectAddSupportFiles()
        {
            using (var app = new VisualStudioApp()) {
                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");
            }
        }
Exemple #7
0
        public void StartNewAppDuplicateName()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.DjangoWebProjectTemplate,
                    TestData.GetTempPath(),
                    "StartNewAppDuplicateName"
                    );
                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"
                    );

                app.Dte.Documents.CloseAll(EnvDTE.vsSaveChanges.vsSaveChangesNo);

                app.SolutionExplorerTreeView.SelectProject(project);
                using (var newAppDialog = NewAppDialog.FromDte(app)) {
                    newAppDialog.AppName = "Fob";
                    newAppDialog.OK();
                }

                using (var dlg = AutomationDialog.WaitForDialog(app)) { }
            }
        }
        private void TestPublishToWebSite(
            string templateName,
            string projectName,
            string moduleName,
            string textInResponse,
            string pythonVersion,
            int publishTimeout,
            string packageName = null
            )
        {
            using (var app = new VisualStudioApp()) {
                var pyProj = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    templateName,
                    TestData.GetTempPath(),
                    projectName
                    ).GetPythonProject();

                var factory = WebProjectTests.CreateVirtualEnvironment(pythonVersion, app, pyProj);

                WebProjectTests.InstallWebFramework(app, moduleName, packageName ?? moduleName, factory);

                _webSiteToDelete = Guid.NewGuid().ToString("N");
                var siteUri = app.PublishToAzureWebSite(_webSiteToDelete, publishSettingsFilePath);
                app.WaitForBuildComplete(publishTimeout);

                string text = WebDownloadUtility.GetString(siteUri);

                Console.WriteLine("Response from {0}", siteUri);
                Console.WriteLine(text);
                Assert.IsTrue(text.Contains(textInResponse), text);
            }
        }
        public void DjangoCommandsNonDjangoApp(VisualStudioApp app, DjangoInterpreterSetter interpreterSetter)
        {
            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());
            }
        }
Exemple #10
0
 static EnvDTE.Project CreateTemporaryProject(VisualStudioApp app, [CallerMemberName] string projectName = null) {
     var project = app.CreateProject(
         PythonVisualStudioApp.TemplateLanguageName,
         PythonVisualStudioApp.PythonApplicationTemplate,
         TestData.GetTempPath(),
         projectName ?? Path.GetFileNameWithoutExtension(Path.GetRandomFileName())
     );
     Assert.IsNotNull(project, "Project was not created");
     return project;
 }
Exemple #11
0
        private EnvDTE.Project CreateTemporaryProject(VisualStudioApp app)
        {
            var project = app.CreateProject(
                PythonVisualStudioApp.TemplateLanguageName,
                PythonVisualStudioApp.PythonApplicationTemplate,
                TestData.GetTempPath(),
                TestContext.TestName
                );

            Assert.IsNotNull(project, "Project was not created");
            return(project);
        }
Exemple #12
0
        private void EndToEndTest(
            string templateName,
            string moduleName,
            string textInResponse,
            string pythonVersion,
            string packageName = null
            )
        {
            EndToEndLog("Starting {0} {1}", templateName, pythonVersion);
            using (var app = new VisualStudioApp()) {
                var pyProj = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    templateName,
                    TestData.GetTempPath(),
                    TestContext.TestName
                    ).GetPythonProject();

                EndToEndLog("Created project {0}", pyProj.ProjectFile);

                Assert.IsInstanceOfType(pyProj.GetLauncher(), typeof(PythonWebLauncher));

                var factory = CreateVirtualEnvironment(pythonVersion, app, pyProj);

                EndToEndLog("Created virtual environment {0}", factory.Description);

                InstallWebFramework(app, moduleName, packageName ?? moduleName, factory);

                EndToEndLog("Installed framework {0}", moduleName);

                // Abort analysis so we don't have too many python.exe processes
                // floating around.
                foreach (var p in Process.GetProcessesByName("Microsoft.PythonTools.Analyzer"))
                {
                    p.Kill();
                }

                EndToEndLog("Aborted analysis");

                app.ServiceProvider.GetUIThread().Invoke(() => {
                    pyProj.SetProjectProperty("WebBrowserPort", "23457");
                });
                EndToEndLog("Set WebBrowserPort to 23457");
                LaunchAndVerifyNoDebug(app, 23457, textInResponse);
                EndToEndLog("Verified without debugging");

                app.ServiceProvider.GetUIThread().Invoke(() => {
                    pyProj.SetProjectProperty("WebBrowserPort", "23456");
                });
                EndToEndLog("Set WebBrowserPort to 23456");
                LaunchAndVerifyDebug(app, 23456, textInResponse);
                EndToEndLog("Verified with debugging");
            }
        }
Exemple #13
0
        public void WebProjectLauncherNoStartupFile(VisualStudioApp app, DotNotWaitOnNormalExit optionSetter)
        {
            var project = app.CreateProject(
                PythonVisualStudioApp.TemplateLanguageName,
                PythonVisualStudioApp.EmptyWebProjectTemplate,
                TestData.GetTempPath(),
                "NewWebProject"
                );

            foreach (var cmd in new[] { "Debug.Start", "Debug.StartWithoutDebugging" })
            {
                app.Dte.ExecuteCommand(cmd);
                app.CheckMessageBox("The project cannot be launched because the startup file is not specified.");
            }
        }
Exemple #14
0
        public void WebProjectCreateVirtualEnvOnNew()
        {
            using (var app = new VisualStudioApp()) {
                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 = TaskExt.WaitAndUnwrapExceptions(t);

                var provider = project.Properties.Item("InterpreterFactoryProvider").Value as MSBuildProjectInterpreterFactoryProvider;
                for (int retries = 20; retries > 0; --retries)
                {
                    if (provider.IsProjectSpecific(provider.ActiveInterpreter))
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                Assert.IsTrue(provider.IsProjectSpecific(provider.ActiveInterpreter), "Did not have virtualenv");

                for (int retries = 60; retries > 0; --retries)
                {
                    if (InterpreterExt.FindModules(provider.ActiveInterpreter, "flask").Any())
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                AssertUtil.ContainsExactly(
                    InterpreterExt.FindModules(provider.ActiveInterpreter, "flask"),
                    "flask"
                    );
            }
        }
Exemple #15
0
        public void NewDjangoProject(VisualStudioApp app, DjangoInterpreterSetter interpreterSetter)
        {
            var project = app.CreateProject(
                PythonVisualStudioApp.TemplateLanguageName,
                PythonVisualStudioApp.DjangoWebProjectTemplate,
                TestData.GetTempPath(),
                "NewDjangoProject"
                );
            var folder = project.ProjectItems.Item(project.Name);

            Assert.IsNotNull(project.ProjectItems.Item("manage.py"));
            Assert.IsNotNull(folder.ProjectItems.Item("settings.py"));
            Assert.IsNotNull(folder.ProjectItems.Item("urls.py"));
            Assert.IsNotNull(folder.ProjectItems.Item("__init__.py"));
            Assert.IsNotNull(folder.ProjectItems.Item("wsgi.py"));
        }
Exemple #16
0
        public void StartNewAppSameAsProjectName(VisualStudioApp app, DjangoInterpreterSetter interpreterSetter)
        {
            var project = app.CreateProject(
                PythonVisualStudioApp.TemplateLanguageName,
                PythonVisualStudioApp.DjangoWebProjectTemplate,
                TestData.GetTempPath(),
                "StartNewAppSameAsProjectName"
                );

            app.SolutionExplorerTreeView.SelectProject(project);

            using (var newAppDialog = NewAppDialog.FromDte(app)) {
                newAppDialog.AppName = app.Dte.Solution.Projects.Item(1).Name;
                newAppDialog.OK();
            }

            using (var dlg = AutomationDialog.WaitForDialog(app)) { }
        }
Exemple #17
0
		public void CreateNewScript() {
			using (var app = new VisualStudioApp()) {
				var project = app.CreateProject(
					RConstants.TemplateLanguageName, RConstants.ProjectTemplate_EmptyProject,
					System.IO.Path.GetTempPath(), "RTestProject");
				app.OpenSolutionExplorer().SelectProject(project);
				using (var newItem = NewItemDialog.FromDte(app)) {
					AutomationWrapper.Select(newItem.ProjectTypes.FindItem("R Script"));
					newItem.FileName = "my-script.r";
					newItem.OK();
				}

				var document = app.GetDocument("my-script.r");
				document.SetFocus();
				document.Type("2 -> a");
				document.Text.Should().Be("2 -> a# R Script");
			}
		}
Exemple #18
0
        public void CreateNewScript()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    RConstants.TemplateLanguageName, RConstants.ProjectTemplate_EmptyProject,
                    System.IO.Path.GetTempPath(), "RTestProject");
                app.OpenSolutionExplorer().SelectProject(project);
                using (var newItem = NewItemDialog.FromDte(app)) {
                    AutomationWrapper.Select(newItem.ProjectTypes.FindItem("R Script"));
                    newItem.FileName = "my-script.r";
                    newItem.OK();
                }

                var document = app.GetDocument("my-script.r");
                document.SetFocus();
                document.Type("2 -> a");
                document.Text.Should().Be("2 -> a# R Script");
            }
        }
Exemple #19
0
        public void NewDjangoProjectSafeProjectName()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.DjangoWebProjectTemplate,
                    TestData.GetTempPath(),
                    "Django Project $100"
                    );

                var folder = project.ProjectItems.Item("Django_Project__100");
                Assert.IsNotNull(project.ProjectItems.Item("manage.py"));
                Assert.IsNotNull(folder.ProjectItems.Item("settings.py"));
                Assert.IsNotNull(folder.ProjectItems.Item("urls.py"));
                Assert.IsNotNull(folder.ProjectItems.Item("__init__.py"));
                Assert.IsNotNull(folder.ProjectItems.Item("wsgi.py"));
                var settings = app.ServiceProvider.GetUIThread().Invoke(() => project.GetPythonProject().GetProperty("DjangoSettingsModule"));
                Assert.AreEqual("Django_Project__100.settings", settings);
            }
        }
Exemple #20
0
        public void WebProjectStaticUri()
        {
            using (var app = new VisualStudioApp()) {
                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");
            }
        }