Esempio n. 1
0
        private IDirectory GetDiskSourceDirectory(WebHostContext context)
        {
            var descriptor = context.Deployment;

            if (string.IsNullOrEmpty(descriptor.ScopePath))
            {
                throw new InvalidOperationException("Path can't be null or empty for directory deployment");
            }

            var solutionRootPath = GetSolutionDir();

            if (string.IsNullOrEmpty(solutionRootPath))
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Configuration Setting:{0} can't be null or empty for directory deployment",
                              SolutionDirAppSettingName));
            }

            var sourceDirInfo = new DirectoryInfo(Path.Combine(solutionRootPath, descriptor.ScopePath));

            if (!sourceDirInfo.Exists)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Web app path:'{0}' doesn't exist",
                              sourceDirInfo.FullName));
            }

            var directory = new MemoryDirectory("root", null);

            directory.CopyFromDisk(sourceDirInfo);

            return(directory);
        }
Esempio n. 2
0
 private void ConfigurationInitialize(WebHostContext context)
 {
     foreach (var configuration in GetWebConfigurations(context.TestType))
     {
         configuration.Initialize(context);
     }
 }
Esempio n. 3
0
 private void ConfigurationTearDown(WebHostContext context)
 {
     foreach (var configuration in GetWebConfigurations(context.TestType).Reverse <IWebHostConfiguration>())
     {
         configuration.TearDown(context);
     }
 }
 public void TearDown(WebHostContext context)
 {
     var db = context.Properties[NuwaDBContextKey] as ITestDatabase;
     if (db != null && db.Exist())
     {
         db.Delete();
     }
 }
        protected override void InitOptions(WebHostContext context)
        {
            var target = _dirProvider.CreateDirectory();
            context.DeploymentOptions = new LocalDeploymentOptions(target);

            var hostOptions = new IISExpressHostOptions(target, target.Name);
            hostOptions.Users.Add(@".\Users");
            context.HostOptions = hostOptions;
        }
Esempio n. 6
0
        protected override void InitOptions(WebHostContext context)
        {
            DirectoryInfo target = _dirProvider.CreateDirectory();
            context.DeploymentOptions = new LocalDeploymentOptions(target);

            var hostOptions = new IISHostOptions(target, target.Name);
            hostOptions.Users.Add(@"NT AUTHORITY\Network Service");
            hostOptions.Users.Add(@"NT AUTHORITY\IUSR");
            hostOptions.Users.Add(@".\Users");
            context.HostOptions = hostOptions;
        }
        protected override void InitOptions(WebHostContext context)
        {
            var target = _dirProvider.CreateDirectory();

            context.DeploymentOptions = new LocalDeploymentOptions(target);

            var hostOptions = new IISExpressHostOptions(target, target.Name);

            hostOptions.Users.Add(@".\Users");
            context.HostOptions = hostOptions;
        }
Esempio n. 8
0
        protected override void InitOptions(WebHostContext context)
        {
            DirectoryInfo target = _dirProvider.CreateDirectory();

            context.DeploymentOptions = new LocalDeploymentOptions(target);

            var hostOptions = new IISHostOptions(target, target.Name);

            hostOptions.Users.Add(@"NT AUTHORITY\Network Service");
            hostOptions.Users.Add(@"NT AUTHORITY\IUSR");
            hostOptions.Users.Add(@".\Users");
            context.HostOptions = hostOptions;
        }
Esempio n. 9
0
        protected override void InitOptions(WebHostContext context)
        {
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureWebsiteUrl, NuwaGlobalConfiguration.AzureWebsiteUrlKey);
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureFtpUrl, NuwaGlobalConfiguration.AzureFtpUrlKey);
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureFtpUserName, NuwaGlobalConfiguration.AzureFtpUserNameKey);
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureFtpPassword, NuwaGlobalConfiguration.AzureFtpPasswordKey);

            context.DeploymentOptions = new FtpDeploymentOptions(
                NuwaGlobalConfiguration.AzureFtpUrl,
                NuwaGlobalConfiguration.AzureFtpUserName,
                NuwaGlobalConfiguration.AzureFtpPassword);
            context.DeploymentOptions.WebConfigTransformers.Add(new WebConfigTransformer(
                                                                    config => {
                config.ConfigureCustomError("Off");
            }));
            context.HostOptions = new AzureWebsiteHostOptions(NuwaGlobalConfiguration.AzureWebsiteUrl);
        }
        protected override void InitOptions(WebHostContext context)
        {
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureWebsiteUrl, NuwaGlobalConfiguration.AzureWebsiteUrlKey);
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureFtpUrl, NuwaGlobalConfiguration.AzureFtpUrlKey);
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureFtpUserName, NuwaGlobalConfiguration.AzureFtpUserNameKey);
            AppSettingNotEmptyOrNull(NuwaGlobalConfiguration.AzureFtpPassword, NuwaGlobalConfiguration.AzureFtpPasswordKey);

            context.DeploymentOptions = new FtpDeploymentOptions(
                NuwaGlobalConfiguration.AzureFtpUrl,
                NuwaGlobalConfiguration.AzureFtpUserName,
                NuwaGlobalConfiguration.AzureFtpPassword);
            context.DeploymentOptions.WebConfigTransformers.Add(new WebConfigTransformer(
                config => {
                    config.ConfigureCustomError("Off");
                }));
            context.HostOptions = new AzureWebsiteHostOptions(NuwaGlobalConfiguration.AzureWebsiteUrl);

        }
Esempio n. 11
0
        protected override void InitOptions(WebHostContext context)
        {
            DirectoryInfo target = _dirProvider.CreateDirectory();
            context.DeploymentOptions = new LocalDeploymentOptions(target);

            var hostOptions = new IISHostOptions(target, target.Name);
            hostOptions.Users.Add(@"NT AUTHORITY\Network Service");
            hostOptions.Users.Add(@"NT AUTHORITY\IUSR");
            hostOptions.Users.Add(@".\Users");
            context.HostOptions = hostOptions;

            // For DEU OS
            //var hostOptions = new IISHostOptions(target, target.Name);
            //hostOptions.Users.Add(@"NT-AUTORITÄT\Netzwerkdienst");

            //hostOptions.Users.Add(@"NT-AUTORITÄT\IUSR");
            //hostOptions.Users.Add(@".\Benutzer");
            //context.HostOptions = hostOptions;
        }
Esempio n. 12
0
        protected virtual void RetrieveSource(WebHostContext context)
        {
            IDirectory source;

            switch (context.Deployment.DeploymentType)
            {
            case DeploymentType.Directory:
                source = GetDiskSourceDirectory(context);
                break;

            case DeploymentType.Assembly:
            case DeploymentType.Resource:
                source = GetAssemblyAndResourceDirectory(context);
                break;

            default:
                throw new NotSupportedException(context.Deployment.DeploymentType.ToString());
            }

            context.Source = source;
        }
Esempio n. 13
0
        protected override void InitOptions(WebHostContext context)
        {
            DirectoryInfo target = _dirProvider.CreateDirectory();

            context.DeploymentOptions = new LocalDeploymentOptions(target);

            var hostOptions = new IISHostOptions(target, target.Name);

            hostOptions.Users.Add(@"NT AUTHORITY\Network Service");
            hostOptions.Users.Add(@"NT AUTHORITY\IUSR");
            hostOptions.Users.Add(@".\Users");
            context.HostOptions = hostOptions;

            // For DEU OS
            //var hostOptions = new IISHostOptions(target, target.Name);
            //hostOptions.Users.Add(@"NT-AUTORITÄT\Netzwerkdienst");

            //hostOptions.Users.Add(@"NT-AUTORITÄT\IUSR");
            //hostOptions.Users.Add(@".\Benutzer");
            //context.HostOptions = hostOptions;
        }
        public void Initialize(WebHostContext context)
        {
            ITestDatabase db;
            string connectionString;
            string prefix = context.TestType.TestTypeInfo.Type.Name;
            if (context.HostOptions is IISExpressHostOptions)
            {
                connectionString = new ConnectionStringBuilder().UseLocalDB().UseRandomDBName(prefix).ToString();
                db = new SqlTestDatabase(connectionString);
            }
            else if (context.HostOptions is IISHostOptions)
            {
                connectionString = new ConnectionStringBuilder().UseLocalSqlExpress().UseRandomDBName(prefix).ToString();
                db = new SqlTestDatabase(connectionString);
            }
            else if (context.HostOptions is AzureWebsiteHostOptions)
            {
                connectionString = NuwaGlobalConfiguration.SqlAzureConnectionString;
                db = new SqlTestDatabase(connectionString);
            }
            else
            {
                throw new NotSupportedException(context.HostOptions.GetType().Name);
            }

            if (db.Exist())
            {
                db.Delete();
            }

            context.Properties.Add(NuwaDBContextKey, db);

            context.DeploymentOptions.WebConfigTransformers.Add(new WebConfigTransformer(
                config =>
                {
                    config.ClearConnectionStrings();
                    config.AddConnectionString(ConnectionStringName, connectionString, "System.Data.SqlClient");
                }));
        }
Esempio n. 15
0
        protected override bool InitializeServer(RunFrame frame)
        {
            var context = new WebHostContext()
            {
                TestType   = TypeDescriptor,
                Deployment = new DeploymentDescriptor(TypeDescriptor.TestTypeInfo),
                Frame      = frame
            };

            RetrieveSource(context);
            InitOptions(context);
            ConfigurationInitialize(context);

            if (context.DeploymentOptions != null)
            {
                context.DeploymentOptions.Deploy(context.Source);
            }

            if (context.HostOptions == null)
            {
                throw new NuwaHostSetupException("Host options is not specified.");
            }

            try
            {
                var baseAddress = context.HostOptions.Start().Replace("localhost", Environment.MachineName);
                frame.SetState(KeyBaseAddresss, baseAddress);
                frame.SetState(KeyWebHostContext, context);
            }
            catch (Exception e)
            {
                throw new NuwaHostSetupException("Failed to setup Host.", e);
            }

            return(true);
        }
Esempio n. 16
0
        private IDirectory GetDiskSourceDirectory(WebHostContext context)
        {
            var descriptor = context.Deployment;
            if (string.IsNullOrEmpty(descriptor.ScopePath))
            {
                throw new InvalidOperationException("Path can't be null or empty for directory deployment");
            }

            var solutionRootPath = GetSolutionDir();
            if (string.IsNullOrEmpty(solutionRootPath))
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Configuration Setting:{0} can't be null or empty for directory deployment",
                        SolutionDirAppSettingName));
            }

            var sourceDirInfo = new DirectoryInfo(Path.Combine(solutionRootPath, descriptor.ScopePath));
            if (!sourceDirInfo.Exists)
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Web app path:'{0}' doesn't exist",
                        sourceDirInfo.FullName));
            }

            var directory = new MemoryDirectory("root", null);
            directory.CopyFromDisk(sourceDirInfo);

            return directory;
        }
Esempio n. 17
0
        private IDirectory GetAssemblyAndResourceDirectory(WebHostContext context)
        {
            var descriptor = context.TestType;
            var frame      = context.Frame;
            var options    = WebAppSetupOptions.GenerateDefaultOptions();

            options.AddWebApiAssemblies();
            options.AddRoute(
                new WebAPIRouteSetup(
                    "api default",
                    "api/{controller}/{action}",
                    "new { action = " + typeof(RouteParameter).FullName + ".Optional }"));

            var deploymentDescriptor = context.Deployment;

            if (deploymentDescriptor.ScopePath != null)
            {
                var resourceAssembly = deploymentDescriptor.ScopeResourceType != null ? deploymentDescriptor.ScopeResourceType.Assembly : descriptor.TestAssembly;
                options.AddAssemblyAndReferences(resourceAssembly);
                options.AddTextFilesFromResources(resourceAssembly, deploymentDescriptor.ScopePath);
            }

            if (options.TextFiles.ContainsKey("web.config"))
            {
                options.UpdateWebConfig(WebConfigHelper.Load(options.TextFiles["web.config"]));
            }

            if (!descriptor.TestControllerTypes.Any())
            {
                if (descriptor.TestAssembly == null)
                {
                    throw new InvalidOperationException(
                              "Neither Controller Types or test assembly is given to web-host strategy. " +
                              "That will cause issue in runtime, because the assemblies contain the controller " +
                              "will not be copied to IIS website bin folder. Please given Controller Type by " +
                              "NuwaControllerAttribute.");
                }

                options.AddAssemblyAndReferences(descriptor.TestAssembly);
            }
            else
            {
                foreach (var ct in descriptor.TestControllerTypes)
                {
                    options.AddAssemblyAndReferences(ct.Assembly);
                }
            }

            // set trace writer
            TraceElement traceElem = frame.GetFirstElement <TraceElement>();

            if (traceElem != null)
            {
                options.TraceWriterType = traceElem.TracerType;
            }

            // set configure action
            if (descriptor.ConfigureMethod != null)
            {
                options.ConfigureMethod = descriptor.ConfigureMethod;
                options.AddAssemblyAndReferences(options.ConfigureMethod.Module.Assembly);
            }

            // TODO: are they used in all situation?
            // setup katana integration pipeline
            if (descriptor.GetDesignatedMethod <NuwaKatanaConfigurationAttribute>() != null)
            {
                options.AddAssemblyAndReferences(Assembly.Load("Microsoft.Owin.Host.SystemWeb"));
                options.UpdateWebConfig(config =>
                {
                    var method = descriptor.GetDesignatedMethod <NuwaKatanaConfigurationAttribute>();
                    config.AddAppSection(
                        "owin:AppStartup",
                        string.Format("{0}.{1}, {2}",
                                      method.DeclaringType.FullName,
                                      method.Name,
                                      method.DeclaringType.Assembly.GetName().Name));
                });
            }
            else if (EnableDefaultOwinWebApiConfiguration)
            {
                options.AddAssemblyAndReferences(Assembly.Load("Microsoft.Owin.Host.SystemWeb"));
                options.UpdateWebConfig(config =>
                {
                    config.AddAppSection(
                        "owin:AppStartup",
                        string.Format("{0}.{1}, {2}",
                                      typeof(WebBaseHostElement).FullName,
                                      "DefaultOwinWebApiConfiguration",
                                      typeof(WebBaseHostElement).Assembly.GetName().Name));
                    if (options.TraceWriterType != null)
                    {
                        config.AddAppSection(
                            NuwaGlobalConfiguration.TraceWriterTypeKey,
                            string.Format("{0}, {1}",
                                          options.TraceWriterType.FullName,
                                          options.TraceWriterType.Assembly.GetName().Name));
                    }

                    if (options.ConfigureMethod != null)
                    {
                        config.AddAppSection(
                            NuwaGlobalConfiguration.HttpConfigureKey,
                            string.Format("{0}.{1}, {2}",
                                          options.ConfigureMethod.DeclaringType.FullName,
                                          options.ConfigureMethod.Name,
                                          options.ConfigureMethod.DeclaringType.Assembly.GetName().Name));
                    }
                });
            }
            else
            {
                options.UpdateWebConfig(config =>
                {
                    config.AddAppSection(
                        "owin:AutomaticAppStartup",
                        "false");
                });
            }

            // update web.config
            if (descriptor.WebConfigMethod != null)
            {
                Action <WebConfigHelper> action = Delegate.CreateDelegate(
                    typeof(Action <WebConfigHelper>),
                    descriptor.WebConfigMethod)
                                                  as Action <WebConfigHelper>;

                if (action != null)
                {
                    options.UpdateWebConfig(action);
                }
            }

            // retrieve partial trust element
            options.UpdateWebConfig(webConfig => webConfig.ConfigureTrustLevel("Full"));

            var ramfarSetting = ConfigurationManager.AppSettings["runAllManagedModulesForAllRequests"];

            if (ramfarSetting != null && string.Equals(ramfarSetting, "true", StringComparison.InvariantCultureIgnoreCase))
            {
                options.UpdateWebConfig(webConfig => webConfig.AddRAMFAR(true));
            }

            // Update deployment options
            if (descriptor.WebDeployConfigMethod != null)
            {
                descriptor.WebDeployConfigMethod.Invoke(null, new object[] { options });
            }

            if (EnableGlobalAsax)
            {
                options.GenerateGlobalAsaxForCS();
            }

            doAdditionalAssemblyAndREferences();
            doAdditionalUpdateWebConfig();

            return(options.ToDirectory());
        }
Esempio n. 18
0
 protected abstract void InitOptions(WebHostContext context);
Esempio n. 19
0
 private void ConfigurationTearDown(WebHostContext context)
 {
     foreach (var configuration in GetWebConfigurations(context.TestType).Reverse<IWebHostConfiguration>())
     {
         configuration.TearDown(context);
     }
 }
Esempio n. 20
0
 private void ConfigurationInitialize(WebHostContext context)
 {
     foreach (var configuration in GetWebConfigurations(context.TestType))
     {
         configuration.Initialize(context);
     }
 }
Esempio n. 21
0
        private IDirectory GetAssemblyAndResourceDirectory(WebHostContext context)
        {
            var descriptor = context.TestType;
            var frame = context.Frame;
            var options = WebAppSetupOptions.GenerateDefaultOptions();

            options.AddWebApiAssemblies();
            options.AddRoute(
                new WebAPIRouteSetup(
                    "api default",
                    "api/{controller}/{action}",
                    "new { action = " + typeof(RouteParameter).FullName + ".Optional }"));

            var deploymentDescriptor = context.Deployment;
            if (deploymentDescriptor.ScopePath != null)
            {
                var resourceAssembly = deploymentDescriptor.ScopeResourceType != null ? deploymentDescriptor.ScopeResourceType.Assembly : descriptor.TestAssembly;
                options.AddAssemblyAndReferences(resourceAssembly);
                options.AddTextFilesFromResources(resourceAssembly, deploymentDescriptor.ScopePath);
            }

            if (options.TextFiles.ContainsKey("web.config"))
            {
                options.UpdateWebConfig(WebConfigHelper.Load(options.TextFiles["web.config"]));
            }

            if (!descriptor.TestControllerTypes.Any())
            {
                if (descriptor.TestAssembly == null)
                {
                    throw new InvalidOperationException(
                        "Neither Controller Types or test assembly is given to web-host strategy. " +
                        "That will cause issue in runtime, because the assemblies contain the controller " +
                        "will not be copied to IIS website bin folder. Please given Controller Type by " +
                        "NuwaControllerAttribute.");
                }

                options.AddAssemblyAndReferences(descriptor.TestAssembly);
            }
            else
            {
                foreach (var ct in descriptor.TestControllerTypes)
                {
                    options.AddAssemblyAndReferences(ct.Assembly);
                }
            }

            // set trace writer
            TraceElement traceElem = frame.GetFirstElement<TraceElement>();
            if (traceElem != null)
            {
                options.TraceWriterType = traceElem.TracerType;
            }

            // set configure action
            if (descriptor.ConfigureMethod != null)
            {
                options.ConfigureMethod = descriptor.ConfigureMethod;
                options.AddAssemblyAndReferences(options.ConfigureMethod.Module.Assembly);
            }

            // TODO: are they used in all situation?
            // setup katana integration pipeline
            if (descriptor.GetDesignatedMethod<NuwaKatanaConfigurationAttribute>() != null)
            {
                options.AddAssemblyAndReferences(Assembly.Load("Microsoft.Owin.Host.SystemWeb"));
                options.UpdateWebConfig(config =>
                {
                    var method = descriptor.GetDesignatedMethod<NuwaKatanaConfigurationAttribute>();
                    config.AddAppSection(
                        "owin:AppStartup",
                        string.Format("{0}.{1}, {2}",
                            method.DeclaringType.FullName,
                            method.Name,
                            method.DeclaringType.Assembly.GetName().Name));
                });
            }
            else if (EnableDefaultOwinWebApiConfiguration)
            {
                options.AddAssemblyAndReferences(Assembly.Load("Microsoft.Owin.Host.SystemWeb"));
                options.UpdateWebConfig(config =>
                {
                    config.AddAppSection(
                        "owin:AppStartup",
                        string.Format("{0}.{1}, {2}",
                            typeof(WebBaseHostElement).FullName,
                            "DefaultOwinWebApiConfiguration",
                            typeof(WebBaseHostElement).Assembly.GetName().Name));
                    if (options.TraceWriterType != null)
                    {
                        config.AddAppSection(
                            NuwaGlobalConfiguration.TraceWriterTypeKey,
                            string.Format("{0}, {1}",
                                options.TraceWriterType.FullName,
                                options.TraceWriterType.Assembly.GetName().Name));
                    }

                    if (options.ConfigureMethod != null)
                    {
                        config.AddAppSection(
                            NuwaGlobalConfiguration.HttpConfigureKey,
                            string.Format("{0}.{1}, {2}",
                                options.ConfigureMethod.DeclaringType.FullName,
                                options.ConfigureMethod.Name,
                                options.ConfigureMethod.DeclaringType.Assembly.GetName().Name));
                    }

                });
            }
            else
            {
                options.UpdateWebConfig(config =>
                {
                    config.AddAppSection(
                        "owin:AutomaticAppStartup",
                        "false");
                });
            }

            // update web.config
            if (descriptor.WebConfigMethod != null)
            {
                Action<WebConfigHelper> action = Delegate.CreateDelegate(
                    typeof(Action<WebConfigHelper>),
                    descriptor.WebConfigMethod)
                    as Action<WebConfigHelper>;

                if (action != null)
                {
                    options.UpdateWebConfig(action);
                }
            }

            // retrieve partial trust element
            options.UpdateWebConfig(webConfig => webConfig.ConfigureTrustLevel("Full"));

            var ramfarSetting = ConfigurationManager.AppSettings["runAllManagedModulesForAllRequests"];
            if (ramfarSetting != null && string.Equals(ramfarSetting, "true", StringComparison.InvariantCultureIgnoreCase))
            {
                options.UpdateWebConfig(webConfig => webConfig.AddRAMFAR(true));
            }

            // Update deployment options
            if (descriptor.WebDeployConfigMethod != null)
            {
                descriptor.WebDeployConfigMethod.Invoke(null, new object[] { options });
            }

            if (EnableGlobalAsax)
            {
                options.GenerateGlobalAsaxForCS();
            }

            doAdditionalAssemblyAndREferences();
            doAdditionalUpdateWebConfig();

            return options.ToDirectory();
        }
Esempio n. 22
0
 protected abstract void InitOptions(WebHostContext context);
Esempio n. 23
0
        protected virtual void RetrieveSource(WebHostContext context)
        {
            IDirectory source;
            switch (context.Deployment.DeploymentType)
            {
                case DeploymentType.Directory:
                    source = GetDiskSourceDirectory(context);
                    break;
                case DeploymentType.Assembly:
                case DeploymentType.Resource:
                    source = GetAssemblyAndResourceDirectory(context);
                    break;
                default:
                    throw new NotSupportedException(context.Deployment.DeploymentType.ToString());
            }

            context.Source = source;
        }
Esempio n. 24
0
        protected override bool InitializeServer(RunFrame frame)
        {
            var context = new WebHostContext()
            {
                TestType = TypeDescriptor,
                Deployment = new DeploymentDescriptor(TypeDescriptor.TestTypeInfo),
                Frame = frame
            };

            RetrieveSource(context);
            InitOptions(context);
            ConfigurationInitialize(context);

            if (context.DeploymentOptions != null)
            {
                context.DeploymentOptions.Deploy(context.Source);
            }

            if (context.HostOptions == null)
            {
                throw new NuwaHostSetupException("Host options is not specified.");
            }

            try
            {
                var baseAddress = context.HostOptions.Start().Replace("localhost", Environment.MachineName);
                frame.SetState(KeyBaseAddresss, baseAddress);
                frame.SetState(KeyWebHostContext, context);
            }
            catch (Exception e)
            {
                throw new NuwaHostSetupException("Failed to setup Host.", e);
            }

            return true;
        }