Ejemplo n.º 1
0
        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");
            }
        }