Exemple #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");
                }
            }
        }
        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 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);
                }
            }
        }
Exemple #4
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 StartupOptionsAndOwinHostFacts(bool useOwinHostExe, string traceOutputFile,
                                                   int?port, bool portInEnvironmentVar,
                                                   bool passSettings, string[] urls)
        {
            try
            {
                MyStartOptions options = new MyStartOptions(useOwinHostExe);
                string         defaultApplicationUrl = "http://localhost:5000/";

                if (!string.IsNullOrWhiteSpace(traceOutputFile))
                {
                    DeleteFile(traceOutputFile);
                    options.TraceOutput = traceOutputFile;
                }

                #region Port
                if (port.HasValue)
                {
                    options.Port          = port.Value;
                    defaultApplicationUrl = string.Format("http://localhost:{0}/", port.Value);
                }

                if (portInEnvironmentVar)
                {
                    //Set environment Variable
                    Environment.SetEnvironmentVariable("PORT", "10001", EnvironmentVariableTarget.Process);
                    defaultApplicationUrl = string.Format("http://localhost:{0}/", 10001);
                }
                #endregion Port

                var traceFileName = System.Guid.NewGuid().ToString() + ".txt";
                if (passSettings)
                {
                    options.Settings.Add("traceoutput", traceFileName);
                }

                if (urls != null)
                {
                    for (int i = 0; i < urls.Length; i++)
                    {
                        options.Urls.Add(urls[i]);
                    }
                }

                string expectedLogText = null;

                using (new HostServer(options))
                {
                    List <string> allUrls = new List <string>(options.Urls);
                    if (allUrls.Count == 0)
                    {
                        allUrls.Add(defaultApplicationUrl);
                    }

                    for (int i = 0; i < allUrls.Count; i++)
                    {
                        var httpClient = new HttpClient();
                        var headers    = new List <KeyValuePair <string, string> >();

                        if (!string.IsNullOrWhiteSpace(traceOutputFile) || passSettings)
                        {
                            expectedLogText = System.Guid.NewGuid().ToString();
                            httpClient.DefaultRequestHeaders.Add("outputFile", expectedLogText);
                        }

                        var response = httpClient.GetAsync(allUrls[i]).Result.Content.ReadAsStringAsync().Result;
                        Assert.Equal("SUCCESS", response);
                    }
                }

                #region Verify logoutput
                if (!string.IsNullOrWhiteSpace(traceOutputFile))
                {
                    ValidateLog(traceOutputFile, expectedLogText);
                }
                else if (passSettings)
                {
                    ValidateLog(traceFileName, expectedLogText);
                }
                #endregion Verify logoutput
            }
            finally
            {
                Environment.SetEnvironmentVariable("PORT", null, EnvironmentVariableTarget.Process);
            }
        }
        public void StartupOptionsAndOwinHostFacts(bool useOwinHostExe, string traceOutputFile,
            int? port, bool portInEnvironmentVar,
            bool passSettings, string[] urls)
        {
            try
            {
                MyStartOptions options = new MyStartOptions(useOwinHostExe);
                string defaultApplicationUrl = "http://localhost:5000/";

                if (!string.IsNullOrWhiteSpace(traceOutputFile))
                {
                    DeleteFile(traceOutputFile);
                    options.TraceOutput = traceOutputFile;
                }

                #region Port
                if (port.HasValue)
                {
                    options.Port = port.Value;
                    defaultApplicationUrl = string.Format("http://localhost:{0}/", port.Value);
                }

                if (portInEnvironmentVar)
                {
                    //Set environment Variable
                    Environment.SetEnvironmentVariable("PORT", "10001", EnvironmentVariableTarget.Process);
                    defaultApplicationUrl = string.Format("http://localhost:{0}/", 10001);
                }
                #endregion Port

                var traceFileName = System.Guid.NewGuid().ToString() + ".txt";
                if (passSettings)
                {
                    options.Settings.Add("traceoutput", traceFileName);
                }

                if (urls != null)
                {
                    for (int i = 0; i < urls.Length; i++)
                    {
                        options.Urls.Add(urls[i]);
                    }
                }

                string expectedLogText = null;

                using (new HostServer(options))
                {
                    List<string> allUrls = new List<string>(options.Urls);
                    if (allUrls.Count == 0)
                    {
                        allUrls.Add(defaultApplicationUrl);
                    }

                    for (int i = 0; i < allUrls.Count; i++)
                    {
                        var httpClient = new HttpClient();
                        var headers = new List<KeyValuePair<string, string>>();

                        if (!string.IsNullOrWhiteSpace(traceOutputFile) || passSettings)
                        {
                            expectedLogText = System.Guid.NewGuid().ToString();
                            httpClient.DefaultRequestHeaders.Add("outputFile", expectedLogText);
                        }

                        var response = httpClient.GetAsync(allUrls[i]).Result.Content.ReadAsStringAsync().Result;
                        Assert.Equal("SUCCESS", response);
                    }
                }

                #region Verify logoutput
                if (!string.IsNullOrWhiteSpace(traceOutputFile))
                {
                    ValidateLog(traceOutputFile, expectedLogText);
                }
                else if (passSettings)
                {
                    ValidateLog(traceFileName, expectedLogText);
                }
                #endregion Verify logoutput
            }
            finally
            {
                Environment.SetEnvironmentVariable("PORT", null, EnvironmentVariableTarget.Process);
            }
        }
Exemple #7
0
 public HostServer(MyStartOptions startOptions)
 {
     this.startOptions = startOptions;
     this.Start();
 }
Exemple #8
0
 public HostServer(MyStartOptions startOptions)
 {
     this.startOptions = startOptions;
     this.Start();
 }