Beispiel #1
0
        public void ReadAppSettings()
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                var applicationUrl = deployer.Deploy(HostType.IIS, Configuration);
                var vDirPath = Path.GetDirectoryName(deployer.GetWebConfigPath());
                var options = new MyStartOptions(true) { DontPassStartupClassInCommandLine = true, TargetApplicationDirectory = vDirPath };
                string webConfigPath = deployer.GetWebConfigPath();

                XmlDocument configuration = new XmlDocument() { InnerXml = File.ReadAllText(webConfigPath) };
                var appSettingsNode = configuration.SelectSingleNode("/configuration/appSettings");
                appSettingsNode.InnerXml += "<add key=\"traceoutput\" value=\"MyLogTextThroughAppSetting.txt\" />";
                File.WriteAllText(webConfigPath, configuration.InnerXml);

                using (new HostServer(options))
                {
                    var httpClient = new HttpClient();
                    httpClient.DefaultRequestHeaders.Add("outputFile", "Test logging");
                    string response = httpClient.GetAsync("http://localhost:5000/").Result.Content.ReadAsStringAsync().Result;

                    Assert.Equal("SUCCESS", response);
                    Assert.True(File.Exists("MyLogTextThroughAppSetting.txt"), "Log file MyLogTextThroughAppSetting.txt is not created on specifying through appSetting");
                }
            }
        }
Beispiel #2
0
        public void ReadAppSettings()
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                var applicationUrl = deployer.Deploy(HostType.IIS, Configuration);
                var vDirPath       = Path.GetDirectoryName(deployer.GetWebConfigPath());
                var options        = new MyStartOptions(true)
                {
                    DontPassStartupClassInCommandLine = true, TargetApplicationDirectory = vDirPath
                };
                string webConfigPath = deployer.GetWebConfigPath();

                XmlDocument configuration = new XmlDocument()
                {
                    InnerXml = File.ReadAllText(webConfigPath)
                };
                var appSettingsNode = configuration.SelectSingleNode("/configuration/appSettings");
                appSettingsNode.InnerXml += "<add key=\"traceoutput\" value=\"MyLogTextThroughAppSetting.txt\" />";
                File.WriteAllText(webConfigPath, configuration.InnerXml);

                using (new HostServer(options))
                {
                    var httpClient = new HttpClient();
                    httpClient.DefaultRequestHeaders.Add("outputFile", "Test logging");
                    string response = httpClient.GetAsync("http://localhost:5000/").Result.Content.ReadAsStringAsync().Result;

                    Assert.Equal("SUCCESS", response);
                    Assert.True(File.Exists("MyLogTextThroughAppSetting.txt"), "Log file MyLogTextThroughAppSetting.txt is not created on specifying through appSetting");
                }
            }
        }
        public void ApplicationPoolStop(HostType hostType)
        {
            var serverInstance = new NotificationServer();
            serverInstance.StartNotificationService();
            try
            {
                using (ApplicationDeployer deployer = new ApplicationDeployer())
                {
                    string applicationUrl = deployer.Deploy(hostType, Configuration);
                    Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl) == "SUCCESS");

                    if (hostType == HostType.IIS)
                    {
                        string webConfig = deployer.GetWebConfigPath();
                        string webConfigContent = File.ReadAllText(webConfig);
                        File.WriteAllText(webConfig, webConfigContent);
                    }
                }

                bool receivedNotification = serverInstance.NotificationReceived.WaitOne(20 * 1000);
                Assert.True(receivedNotification, "Cancellation token was not issued on closing host");
            }
            finally
            {
                serverInstance.Dispose();
            }
        }
        public void ExplicitlyRegisterOwinHttpHandler()
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                deployer.AutomaticAppStartupInWebHost = false;
                string url = deployer.Deploy(HostType.IIS);
                var webConfigPath = deployer.GetWebConfigPath();

                var addHandler = "<system.webServer>" +
                                            "<handlers>" +
                                                "<add name=\"Owin\" verb=\"*\" type=\"Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb\" path=\"*\" />" +
                                            "</handlers>" +
                                        "</system.webServer>";

                var configuration = new XmlDocument() { InnerXml = File.ReadAllText(webConfigPath) };
                var configurationNode = configuration.SelectSingleNode("/configuration");
                configurationNode.InnerXml += addHandler;
                File.WriteAllText(webConfigPath, configuration.InnerXml);

                ((WebDeployer)deployer.Application).Application.Deploy("Default.aspx", File.ReadAllText("RequirementFiles\\Default.aspx"));

                Assert.Equal(Startup.RESULT, HttpClientUtility.GetResponseTextFromUrl(url + "/Default.aspx"));
                Assert.Equal(Startup.RESULT, HttpClientUtility.GetResponseTextFromUrl(url));
            }
        }
Beispiel #5
0
        public void ExplicitlyRegisterOwinHttpHandler()
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                deployer.AutomaticAppStartupInWebHost = false;
                string url           = deployer.Deploy(HostType.IIS);
                var    webConfigPath = deployer.GetWebConfigPath();

                var addHandler = "<system.webServer>" +
                                 "<handlers>" +
                                 "<add name=\"Owin\" verb=\"*\" type=\"Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb\" path=\"*\" />" +
                                 "</handlers>" +
                                 "</system.webServer>";

                var configuration = new XmlDocument()
                {
                    InnerXml = File.ReadAllText(webConfigPath)
                };
                var configurationNode = configuration.SelectSingleNode("/configuration");
                configurationNode.InnerXml += addHandler;
                File.WriteAllText(webConfigPath, configuration.InnerXml);

                ((WebDeployer)deployer.Application).Application.Deploy("Default.aspx", File.ReadAllText("RequirementFiles\\Default.aspx"));

                Assert.Equal(Startup.RESULT, HttpClientUtility.GetResponseTextFromUrl(url + "/Default.aspx"));
                Assert.Equal(Startup.RESULT, HttpClientUtility.GetResponseTextFromUrl(url));
            }
        }
        public void ApplicationPoolStop(HostType hostType)
        {
            var serverInstance = new NotificationServer();

            serverInstance.StartNotificationService();
            try
            {
                using (ApplicationDeployer deployer = new ApplicationDeployer())
                {
                    string applicationUrl = deployer.Deploy(hostType, Configuration);
                    Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl) == "SUCCESS");

                    if (hostType == HostType.IIS)
                    {
                        string webConfig        = deployer.GetWebConfigPath();
                        string webConfigContent = File.ReadAllText(webConfig);
                        File.WriteAllText(webConfig, webConfigContent);
                    }
                }

                bool receivedNotification = serverInstance.NotificationReceived.WaitOne(20 * 1000);
                Assert.True(receivedNotification, "Cancellation token was not issued on closing host");
            }
            finally
            {
                serverInstance.Dispose();
            }
        }
Beispiel #7
0
 public void InvalidAppStartupInConfiguration(HostType hostType)
 {
     using (ApplicationDeployer deployer = new ApplicationDeployer())
     {
         string applicationUrl = deployer.Deploy(hostType, ValidConfiguration);
         string webConfig = deployer.GetWebConfigPath();
         string webConfigContent = File.ReadAllText(webConfig).Replace(typeof(NegativeScenarios).Name, "NotExistingStartupClass");
         File.WriteAllText(webConfig, webConfigContent);
         Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown with invalid owin:AppStartup");
     }
 }
 public void InvalidAppStartupInConfiguration(HostType hostType)
 {
     using (ApplicationDeployer deployer = new ApplicationDeployer())
     {
         string applicationUrl   = deployer.Deploy(hostType, ValidConfiguration);
         string webConfig        = deployer.GetWebConfigPath();
         string webConfigContent = File.ReadAllText(webConfig).Replace(typeof(NegativeScenarios).Name, "NotExistingStartupClass");
         File.WriteAllText(webConfig, webConfigContent);
         Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown with invalid owin:AppStartup");
     }
 }
Beispiel #9
0
        public void InvalidAssemblyNameInConfiguration(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                string applicationUrl = deployer.Deploy(hostType, ValidConfiguration);

                string webConfig = deployer.GetWebConfigPath();
                string fullyQualifiedConfigurationMethodName = ((Action<IAppBuilder>)ValidConfiguration).GetFullyQualifiedConfigurationMethodName();
                string webConfigContent = File.ReadAllText(webConfig).
                    Replace(fullyQualifiedConfigurationMethodName, fullyQualifiedConfigurationMethodName + ", NotExistingAssembly");
                File.WriteAllText(webConfig, webConfigContent);

                Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown with invalid assembly name");
            }
        }
Beispiel #10
0
        public void FriendlyStartupNames(string friendlyAppStartupName, string expectedResponse)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                var applicationUrl = deployer.Deploy(HostType.IIS, Configuration);
                var vDirPath = Path.GetDirectoryName(deployer.GetWebConfigPath());
                var options = new MyStartOptions(true) { TargetApplicationDirectory = vDirPath, FriendlyAppStartupName = friendlyAppStartupName };

                using (new HostServer(options))
                {
                    string response = HttpClientUtility.GetResponseTextFromUrl("http://localhost:5000/");
                    Assert.Equal(expectedResponse, response);
                }
            }
        }
        public void InvalidAssemblyNameInConfiguration(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                string applicationUrl = deployer.Deploy(hostType, ValidConfiguration);

                string webConfig = deployer.GetWebConfigPath();
                string fullyQualifiedConfigurationMethodName = ((Action <IAppBuilder>)ValidConfiguration).GetFullyQualifiedConfigurationMethodName();
                string webConfigContent = File.ReadAllText(webConfig).
                                          Replace(fullyQualifiedConfigurationMethodName, fullyQualifiedConfigurationMethodName + ", NotExistingAssembly");
                File.WriteAllText(webConfig, webConfigContent);

                Assert.True(HttpClientUtility.GetResponseTextFromUrl(applicationUrl).Contains(expectedExceptionType.Name), "Fatal error not thrown with invalid assembly name");
            }
        }
Beispiel #12
0
        public void FriendlyStartupNames(string friendlyAppStartupName, string expectedResponse)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                var applicationUrl = deployer.Deploy(HostType.IIS, Configuration);
                var vDirPath       = Path.GetDirectoryName(deployer.GetWebConfigPath());
                var options        = new MyStartOptions(true)
                {
                    TargetApplicationDirectory = vDirPath, FriendlyAppStartupName = friendlyAppStartupName
                };

                using (new HostServer(options))
                {
                    string response = HttpClientUtility.GetResponseTextFromUrl("http://localhost:5000/");
                    Assert.Equal(expectedResponse, response);
                }
            }
        }
Beispiel #13
0
        public void FriendlyStartupNameInAppSetting(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                string applicationUrl = deployer.Deploy(hostType);

                //Tweek the web.config appSettings to say owin:AppStartup = FriendlyName
                var webConfigPath = deployer.GetWebConfigPath();

                XmlDocument configuration = new XmlDocument() { InnerXml = File.ReadAllText(webConfigPath) };
                var appSettingsNode = configuration.SelectSingleNode("/configuration/appSettings");
                appSettingsNode.InnerXml += "<add key=\"owin:AppStartup\" value=\"FriendlyClassNameWithMethodNameOverride\" />";
                File.WriteAllText(webConfigPath, configuration.InnerXml);

                string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl);
                Assert.Equal("CopyOfConfiguration", responseText);
            }
        }
Beispiel #14
0
        public void FriendlyStartupNameInAppSetting(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                string applicationUrl = deployer.Deploy(hostType);

                //Tweek the web.config appSettings to say owin:AppStartup = FriendlyName
                var webConfigPath = deployer.GetWebConfigPath();

                XmlDocument configuration = new XmlDocument()
                {
                    InnerXml = File.ReadAllText(webConfigPath)
                };
                var appSettingsNode = configuration.SelectSingleNode("/configuration/appSettings");
                appSettingsNode.InnerXml += "<add key=\"owin:AppStartup\" value=\"FriendlyClassNameWithMethodNameOverride\" />";
                File.WriteAllText(webConfigPath, configuration.InnerXml);

                string responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl);
                Assert.Equal("CopyOfConfiguration", responseText);
            }
        }