Exemple #1
0
        public void GivenIHaveCreatedASiteInIISWithTheAlias(string appPool, string portalAlias)
        {
            string physicalPath = Directory.GetCurrentDirectory();

            physicalPath = physicalPath.Replace("\\Tests\\Fixtures", "\\Website");
            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["DefaultPhysicalAppPath"]))
            {
                physicalPath = ConfigurationManager.AppSettings["DefaultPhysicalAppPath"];
            }
            IISManager.CreateIISApplication(portalAlias, physicalPath);
            IISManager.SetApplicationPool(portalAlias, appPool);
        }
Exemple #2
0
        /// <summary>
        /// The Web site Set up.
        /// </summary>
        public void SetUp()
        {
            if (TestConfig.UseExistingInstallation)
            {
                return;
            }

            var applicationPath = Path.Combine(TestConfig.InstallPhysicalPath, TestConfig.TestApplicationName);

            // Delete folder
            if (Directory.Exists(applicationPath))
            {
                Directory.Delete(applicationPath, true);
            }

            var currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            // Create folder
            Directory.CreateDirectory(TestConfig.InstallPhysicalPath);

            var installZip = string.Empty;

            switch (TestConfig.PackageLocation)
            {
            case "Local":
            {
                installZip = Path.Combine(currentPath, TestConfig.LocalReleasePackageFile);
            }

            break;

            case "GitHub":
            {
                installZip = Path.Combine(TestConfig.InstallPhysicalPath, "YAF-BIN.zip");

                // download latest release
                var webClient = new WebClient();
                webClient.DownloadFile(TestConfig.ReleaseDownloadUrl, installZip);
                webClient.Dispose();
            }

            break;
            }

            // Extract Install Package
            var fastZip = new FastZip();

            fastZip.ExtractZip(
                installZip, applicationPath, FastZip.Overwrite.Always, null, null, null, false);

            // Rename Web.config
            File.Copy(
                Path.Combine(applicationPath, "recommended.web.config"), Path.Combine(applicationPath, "web.config"));

            // Create Website in IIS
            IISManager.CreateIISApplication(TestConfig.TestApplicationName, applicationPath);

            // Add Config Password
            var xmlAppConfig = new XmlDocument();

            xmlAppConfig.Load(Path.Combine(applicationPath, "app.config"));

            var xNode  = xmlAppConfig.CreateNode(XmlNodeType.Element, "add", string.Empty);
            var xKey   = xmlAppConfig.CreateAttribute("key");
            var xValue = xmlAppConfig.CreateAttribute("value");

            xKey.Value   = "YAF.ConfigPassword";
            xValue.Value = TestConfig.ConfigPassword;
            xNode.Attributes.Append(xKey);
            xNode.Attributes.Append(xValue);
            xmlAppConfig.GetElementsByTagName("appSettings")[0].InsertAfter(
                xNode, xmlAppConfig.GetElementsByTagName("appSettings")[0].LastChild);

            xmlAppConfig.Save(Path.Combine(applicationPath, "app.config"));

            // Setup Mail Config
            var xmlMailConfig = new XmlDocument();

            xmlMailConfig.Load(Path.Combine(applicationPath, "mail.config"));

            var xNetworkNode = xmlMailConfig.CreateNode(XmlNodeType.Element, "network", string.Empty);
            var xhost        = xmlMailConfig.CreateAttribute("host");
            var xport        = xmlMailConfig.CreateAttribute("port");
            var xpassword    = xmlMailConfig.CreateAttribute("password");
            var xuserName    = xmlMailConfig.CreateAttribute("userName");

            xhost.Value     = TestConfig.TestMailHost;
            xport.Value     = TestConfig.TestMailPort;
            xpassword.Value = TestConfig.TestMailPassword;
            xuserName.Value = TestConfig.TestMailUserName;

            xNetworkNode.Attributes.Append(xhost);
            xNetworkNode.Attributes.Append(xport);
            xNetworkNode.Attributes.Append(xpassword);
            xNetworkNode.Attributes.Append(xuserName);

            xmlMailConfig.GetElementsByTagName("smtp")[0].InsertAfter(
                xNetworkNode, xmlMailConfig.GetElementsByTagName("smtp")[0].LastChild);

            xmlMailConfig.GetElementsByTagName("smtp")[0].Attributes["from"].Value = TestConfig.TestForumMail;

            xmlMailConfig.Save(Path.Combine(applicationPath, "mail.config"));

            // Copy db.config
            File.Copy(Path.Combine(currentPath, @"..\..\..\testfiles\db.config"), Path.Combine(applicationPath, "db.config"), true);

            // Inject Custom.sql file
            File.Copy(Path.Combine(currentPath, @"..\..\..\testfiles\custom.sql"), Path.Combine(applicationPath, "install\\custom.sql"));

            Directory.CreateDirectory(Path.Combine(applicationPath, "App_Data"));

            // Setup DB
            DBManager.AttachDatabase(TestConfig.TestDatabase);

            if (TestConfig.UseTestMailServer)
            {
                // Launch Mail Server
                this.SmtpServer = SimpleSmtpServer.Start(TestConfig.TestMailPort.ToType <int>());
            }

            this.SetupWebsite();
        }