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>
        ///     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;
        }
        /// <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();
        }
Beispiel #4
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 #5
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)
        {

        }