Beispiel #1
0
        /// <summary>
        ///     ctor
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="dependencies"></param>
        /// <param name="remote"></param>
        public WebServerIis(WebServerSettings settings, Dependencies dependencies, bool remote)
        {
            _environmentSystem = dependencies.EnvironmentSystem;
            _fileSystem = dependencies.FileSystem;
            _serverManagerProvider = dependencies.ServerManagerProvider;

            _type = "IIS";
            _hostName = remote
                ? settings.HostName.Replace("localhost", _environmentSystem.MachineName)
                : settings.HostName;
            _rootPhysicalPath = string.IsNullOrEmpty(settings.RootPhysicalPath)
                ? _environmentSystem.ExpandEnvironmentVariables(@"%SystemDrive%\inetpub\wwwroot")
                : settings.RootPhysicalPath;

            _version = GetIisVersion();
            _configs = new Dictionary<string, string>
            {
                {
                    "applicationhost.config",
                    _environmentSystem.ExpandEnvironmentVariables(
                        @"%SystemDrive%\Windows\System32\inetsrv\config\applicationHost.config")
                }
            };

            _serverManager = _serverManagerProvider.GetServerManager("");
        }
Beispiel #2
0
        /// <summary>
        ///     ctor
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="dependencies"></param>
        /// <param name="remote"></param>
        public WebServerIis(WebServerSettings settings, Dependencies dependencies, bool remote)
        {
            _environmentSystem     = dependencies.EnvironmentSystem;
            _fileSystem            = dependencies.FileSystem;
            _serverManagerProvider = dependencies.ServerManagerProvider;

            _type     = "IIS";
            _hostName = remote
                ? settings.HostName.Replace("localhost", _environmentSystem.MachineName)
                : settings.HostName;
            _rootPhysicalPath = string.IsNullOrEmpty(settings.RootPhysicalPath)
                ? _environmentSystem.ExpandEnvironmentVariables(@"%SystemDrive%\inetpub\wwwroot")
                : settings.RootPhysicalPath;

            _version = GetIisVersion();
            _configs = new Dictionary <string, string>
            {
                {
                    "applicationhost.config",
                    _environmentSystem.ExpandEnvironmentVariables(
                        @"%SystemDrive%\Windows\System32\inetsrv\config\applicationHost.config")
                }
            };

            _serverManager = _serverManagerProvider.GetServerManager("");
        }
Beispiel #3
0
        /// <summary>
        ///     Create a web server given web server's type
        /// </summary>
        /// <param name="webServerType"></param>
        /// <param name="websiteName"></param>
        /// <param name="settings"></param>
        /// <param name="dependencies"></param>
        /// <returns></returns>
        internal static WebServer Create(
            string webServerType,
            string websiteName,
            WebServerSettings settings,
            Dependencies dependencies)
        {
            var type = string.IsNullOrEmpty(webServerType) ? TestEasyConfig.Instance.WebServer.Type : webServerType;

            if (settings == null)
            {
                settings = new WebServerSettings();
            }

            if (!string.IsNullOrEmpty(websiteName))
            {
                settings.HostName       = TestEasyConfig.Instance.Client.Remote ? dependencies.EnvironmentSystem.MachineName : "localhost";
                settings.WebAppName     = websiteName;
                settings.StartupTimeout = TestEasyConfig.Instance.WebServer.StartupTimeout;
            }

            var typeInfo = (TestEasyConfig.Instance.WebServer.Types[type.ToLowerInvariant()] == null)
                ? ""
                : TestEasyConfig.Instance.WebServer.Types[type.ToLowerInvariant()].Type;

            if (string.IsNullOrEmpty(typeInfo))
            {
                if (type.Equals("IIS", StringComparison.InvariantCultureIgnoreCase))
                {
                    typeInfo = "TestEasy.WebServer.WebServerIis";
                }
                else if (type.Equals("IISExpress", StringComparison.InvariantCultureIgnoreCase))
                {
                    typeInfo = "TestEasy.WebServer.WebServerIisExpress";
                }
            }

            WebServer server = null;

            if (!string.IsNullOrEmpty(typeInfo))
            {
                server = Instantiate(typeInfo, settings, dependencies);
            }

            if (server == null)
            {
                throw new NotSupportedException(string.Format("WebServer type is unsupported '{0}', type info: '{1}'. Make sure your web server type is registered in webServerTypes collection in default.config or testsuite.config.",
                                                              type, typeInfo));
            }

            return(server);
        }
Beispiel #4
0
        /// <summary>
        ///     Create a web server given web server's type
        /// </summary>
        /// <param name="webServerType"></param>
        /// <param name="websiteName"></param>
        /// <param name="settings"></param>
        /// <param name="dependencies"></param>
        /// <returns></returns>
        internal static WebServer Create(
            string webServerType, 
            string websiteName,
            WebServerSettings settings, 
            Dependencies dependencies)
        {
            var type = string.IsNullOrEmpty(webServerType) ? TestEasyConfig.Instance.WebServer.Type : webServerType;

            if (settings == null)
            {
                settings = new WebServerSettings();
            }

            if (!string.IsNullOrEmpty(websiteName))
            {
                settings.HostName = TestEasyConfig.Instance.Client.Remote ? dependencies.EnvironmentSystem.MachineName : "localhost";
                settings.WebAppName = websiteName;
                settings.StartupTimeout = TestEasyConfig.Instance.WebServer.StartupTimeout;             
            }

            var typeInfo = (TestEasyConfig.Instance.WebServer.Types[type.ToLowerInvariant()] == null)
                ? ""
                : TestEasyConfig.Instance.WebServer.Types[type.ToLowerInvariant()].Type;
            if (string.IsNullOrEmpty(typeInfo))
            {
                if (type.Equals("IIS", StringComparison.InvariantCultureIgnoreCase))
                {
                    typeInfo = "TestEasy.WebServer.WebServerIis";
                }
                else if (type.Equals("IISExpress", StringComparison.InvariantCultureIgnoreCase))
                {
                    typeInfo = "TestEasy.WebServer.WebServerIisExpress";
                }
            }

            WebServer server = null;
            if (!string.IsNullOrEmpty(typeInfo))
            {
                server = Instantiate(typeInfo, settings, dependencies);
            }

            if (server == null)
            {
                throw new NotSupportedException(string.Format("WebServer type is unsupported '{0}', type info: '{1}'. Make sure your web server type is registered in webServerTypes collection in default.config or testsuite.config.",
                    type, typeInfo));
            }

            return server;
        }
Beispiel #5
0
        private static WebServer Instantiate(string typeInfo, WebServerSettings settings, Dependencies dependencies)
        {
            var assembly = dependencies.FileSystem.GetCallingAssembly();
            var typeName = "";

            if (!string.IsNullOrEmpty(typeInfo))
            {
                string[] typeTokens = typeInfo.Split(',');

                // if assembly name is specified and is not not current assembly
                if (typeTokens.Length == 2 &&
                    (assembly == null || string.Compare(typeTokens[1].Trim(), assembly.GetName().Name, StringComparison.InvariantCultureIgnoreCase) != 0))
                {
                    var assemblyName = typeTokens[1].Trim();
                    var assemblyPath = dependencies.FileSystem.GetExecutingAssemblyDirectory();
                    var dllPath      = Path.Combine(assemblyPath, assemblyName + ".dll");
                    var exePath      = Path.Combine(assemblyPath, assemblyName + ".dll");
                    if (dependencies.FileSystem.FileExists(dllPath))
                    {
                        assemblyName = dllPath;
                    }
                    else if (dependencies.FileSystem.FileExists(exePath))
                    {
                        assemblyName = exePath;
                    }

                    assembly = dependencies.FileSystem.LoadAssemblyFromFile(assemblyName);
                }

                typeName = typeTokens[0].Trim();
            }

            if (assembly == null)
            {
                return(null);
            }

            var type = assembly.GetType(typeName);

            if (type == null)
            {
                return(null);
            }

            return((WebServer)Activator.CreateInstance(type, settings, dependencies));
        }
Beispiel #6
0
        /// <summary>
        ///     ctor
        /// </summary>
        public WebServerIisExpress(WebServerSettings settings, Dependencies dependencies)
        {
            if (TestEasyConfig.Instance.Client.Remote)
            {
                throw new NotSupportedException("For tests using remote browsers, IISExpress web server type is not supported, please use IIS.");
            }

            if (string.IsNullOrEmpty(settings.RootPhysicalPath) && !string.IsNullOrEmpty(settings.WebAppName))
            {
                settings.RootPhysicalPath = TestEasyHelpers.Tools.GetUniqueTempPath(settings.WebAppName);
            }

            _architecture          = settings.Architecture;
            _fileSystem            = dependencies.FileSystem;
            _environmentSystem     = dependencies.EnvironmentSystem;
            _processRunner         = dependencies.ProcessRunner;
            _serverManagerProvider = dependencies.ServerManagerProvider;

            _type             = "IISExpress";
            _hostName         = settings.HostName;
            _startupTimeout   = settings.StartupTimeout;
            _rootPhysicalPath = string.IsNullOrEmpty(settings.RootPhysicalPath)
                ? Path.GetDirectoryName(_fileSystem.GetExecutingAssemblyDirectory())
                : settings.RootPhysicalPath;
            _httpPort                  = _environmentSystem.GetNextAvailablePort(0);
            _serverExecutablePath      = LocateIisExpress(); // _version is initialized here
            _applicationHostConfigPath = CreateApplicationHostConfigFromTemplate();

            _configs = new Dictionary <string, string>
            {
                {
                    "applicationhost.config", _applicationHostConfigPath
                }
            };

            _iisExpressConfig = new IisExpressConfig(_applicationHostConfigPath, dependencies.FileSystem);

            InitializeApplicationHostConfig();

            Start();
        }
        /// <summary>
        ///     ctor
        /// </summary>
        public WebServerIisExpress(WebServerSettings settings, Dependencies dependencies)
        {
            if (TestEasyConfig.Instance.Client.Remote)
            {
                throw new NotSupportedException("For tests using remote browsers, IISExpress web server type is not supported, please use IIS.");
            }

            if (string.IsNullOrEmpty(settings.RootPhysicalPath) && !string.IsNullOrEmpty(settings.WebAppName))
            {
                settings.RootPhysicalPath = TestEasyHelpers.Tools.GetUniqueTempPath(settings.WebAppName);
            }

            _architecture = settings.Architecture;
            _fileSystem = dependencies.FileSystem;
            _environmentSystem = dependencies.EnvironmentSystem;
            _processRunner = dependencies.ProcessRunner;
            _serverManagerProvider = dependencies.ServerManagerProvider;

            _type = "IISExpress";
            _hostName = settings.HostName;
            _startupTimeout = settings.StartupTimeout;
            _rootPhysicalPath = string.IsNullOrEmpty(settings.RootPhysicalPath)
                ? Path.GetDirectoryName(_fileSystem.GetExecutingAssemblyDirectory())
                : settings.RootPhysicalPath;
            _httpPort = _environmentSystem.GetNextAvailablePort(0);
            _serverExecutablePath = LocateIisExpress(); // _version is initialized here
            _applicationHostConfigPath = CreateApplicationHostConfigFromTemplate();

            _configs = new Dictionary<string, string>
            {
                {
                    "applicationhost.config", _applicationHostConfigPath
                }
            };

            _iisExpressConfig = new IisExpressConfig(_applicationHostConfigPath, dependencies.FileSystem);
            
            InitializeApplicationHostConfig();

            Start();
        }
        public void CustomServerAndBrowserUsingConfigTest()
        {
            // Arrange
            const string webSiteName = "TestEasyWAP";

            // Create server using Config settings
            WebServerSettings settings = new WebServerSettings
            {
                HostName = TestEasyConfig.Instance.Client.Remote ? Environment.MachineName : "",
                RootPhysicalPath = (TestEasyConfig.Instance.WebServer.Type.Equals("IISExpress", StringComparison.InvariantCultureIgnoreCase))
                    ? TestEasyHelpers.Tools.GetUniqueTempPath(webSiteName)
                    : ""
            };

            WebServer server = WebServer.Create(TestEasyConfig.Instance.WebServer.Type, settings);
            WebApplicationInfo appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });
            server.BuildWebApplication(webSiteName);
            
            // create browser object using config settings
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser();

                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx");

                browser.FindElement(By.XPath("//input[@name='Button1']")).Click();
                browser.WaitForPageLoaded();

                // Assert
                Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value"));
            }
        }
Beispiel #9
0
 /// <summary>
 ///     Create a web server given web server's type
 /// </summary>
 /// <param name="webServerType"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static WebServer Create(string webServerType, WebServerSettings settings)
 {
     return(Create(webServerType, "", settings, Dependencies.Instance));
 }
Beispiel #10
0
 /// <summary>
 ///     ctor
 /// </summary>
 public WebServerIisExpress(WebServerSettings settings)
     : this(settings, Dependencies.Instance)
 {
 }
Beispiel #11
0
 /// <summary>
 ///     ctor
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="dependencies"></param>
 public WebServerIis(WebServerSettings settings, Dependencies dependencies)
     : this(settings, dependencies, TestEasyConfig.Instance.Client.Remote)
 {
 }
Beispiel #12
0
        private static WebServer Instantiate(string typeInfo, WebServerSettings settings, Dependencies dependencies)
        {
            var assembly = dependencies.FileSystem.GetCallingAssembly();
            var typeName = "";

            if (!string.IsNullOrEmpty(typeInfo))
            {
                string[] typeTokens = typeInfo.Split(',');

                // if assembly name is specified and is not not current assembly
                if (typeTokens.Length == 2
                    && (assembly == null || string.Compare(typeTokens[1].Trim(), assembly.GetName().Name, StringComparison.InvariantCultureIgnoreCase) != 0))
                {
                    var assemblyName = typeTokens[1].Trim();                    
                    var assemblyPath = dependencies.FileSystem.GetExecutingAssemblyDirectory();
                    var dllPath = Path.Combine(assemblyPath, assemblyName + ".dll");
                    var exePath = Path.Combine(assemblyPath, assemblyName + ".dll");
                    if (dependencies.FileSystem.FileExists(dllPath))
                    {
                        assemblyName = dllPath;
                    }
                    else if (dependencies.FileSystem.FileExists(exePath))
                    {
                        assemblyName = exePath;
                    }

                    assembly = dependencies.FileSystem.LoadAssemblyFromFile(assemblyName);
                }

                typeName = typeTokens[0].Trim();
            }

            if (assembly == null)
            {
                return null;
            }

            var type = assembly.GetType(typeName);

            if (type == null)
            {
                return null;
            }

            return (WebServer)Activator.CreateInstance(type, settings, dependencies);            
        }
Beispiel #13
0
 /// <summary>
 ///     Create a web server given web server's type
 /// </summary>
 /// <param name="webServerType"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static WebServer Create(string webServerType, WebServerSettings settings)
 {
     return Create(webServerType, "", settings, Dependencies.Instance);
 }
        public void CustomServerAndBrowserTest()
        {
            // Arrange
            const string webSiteName = "TestEasyWAP";

            // Create server object
            WebServerSettings settings = new WebServerSettings
            {
                HostName = Environment.MachineName, // machine anme or empty (in this case localhost will be used)
                RootPhysicalPath = TestEasyHelpers.Tools.GetUniqueTempPath(webSiteName) // needed only when web server type is IISExpress
            };

            WebServer server = WebServer.Create("IISExpress", settings);
            WebApplicationInfo appInfo = server.CreateWebApplication(webSiteName);
            server.DeployWebApplication(appInfo.Name, new List<DeploymentItem>
                {
                    new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName }
                });
            server.BuildWebApplication(webSiteName);

            // create browser object
            using (var browserManager = new BrowserManager())
            {
                var browser = browserManager.CreateBrowser(BrowserType.Ie, false/*, remote=true/false */);

                // Act
                browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx");

                browser.FindElement(By.XPath("//input[@name='Button1']")).Click();
                browser.WaitForPageLoaded();

                // Assert
                Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value"));
            }
        }
Beispiel #15
0
        /// <summary>
        ///     ctor
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="dependencies"></param>
        public WebServerIis(WebServerSettings settings, Dependencies dependencies)
            : this(settings, dependencies, TestEasyConfig.Instance.Client.Remote)
        {

        }
Beispiel #16
0
 /// <summary>
 ///     ctor
 /// </summary>
 /// <param name="settings"></param>
 public WebServerIis(WebServerSettings settings)
     : this(settings, Dependencies.Instance)
 {
 }