예제 #1
0
        public void Can_Create_Site()
        {
            Cleanup();
            var browser = new BrowserBuilder().WithDefaultConfiguration().Build();

            var response = browser.Post("/sites/create/", with =>
                {
                    with.Authenticated();
                    with.HttpRequest();
                    with.FormValue("name", _testSite.Name);
                    with.FormValue("sitepath", @"c:\inetpub\wwwroot");
                    with.FormValue("bindingsuserinput", "http://unit-test-site.com");
                    with.FormValue("bindingsipaddress", "*");
                    with.FormValue("bindingscertificatename", "Servant");
                    with.FormValue("applicationpool", "");
                });

            var body = response.Body.AsString();

            var urlRegex = new Regex(@"/sites/(\d+)/settings", RegexOptions.IgnoreCase);
            string headerLocation;
            response.Headers.TryGetValue("Location", out headerLocation);
            
            Assert.IsTrue(urlRegex.IsMatch(headerLocation ?? ""));
        }
예제 #2
0
        public void Can_Save_Configuration()
        {
            var browser = new BrowserBuilder().WithoutConfiguration().Build();
            const string servantUrl = "http://localhost:54444/";
            var response = browser.Post("/setup/1/", with =>
                {
                    with.FormValue("servanturl", servantUrl);
                    with.FormValue("username", "admin");
                    with.FormValue("password", "servant");
                    with.FormValue("autosendcrashreport", "true");
                    with.FormValue("acceptterms", "true");
                });

            response.ShouldHaveRedirectedTo("/setup/confirm/?url=" + HttpUtility.UrlEncode(servantUrl));
        }
예제 #3
0
        public void Can_Save_Settings()
        {
            var browser = new BrowserBuilder().WithDefaultConfiguration().Build();
            var configuration = Nancy.TinyIoc.TinyIoCContainer.Current.Resolve<ServantConfiguration>();

            BrowserResponse response = browser.Post("/settings/", with =>
                {
                    with.Authenticated();
                    with.HttpRequest();
                    with.FormValue("servanturl", configuration.ServantUrl);
                    with.FormValue("debug", true.ToString());
                    with.FormValue("autosendcrashreport", true.ToString());
                    with.FormValue("username", configuration.Username);
                    with.FormValue("password", "servant");
                });

            configuration = ConfigurationHelper.GetConfigurationFromDisk();

            Assert.AreEqual(true, configuration.Debug);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
예제 #4
0
        public void Can_Save_Site_Settings()
        {
            var browser = new BrowserBuilder().WithDefaultConfiguration().Build();
            var originalSite = GetTestSiteFromIis();

            var response = browser.Post("/sites/" + originalSite.IisId + "/settings/", with =>
                {
                    with.Authenticated();
                    with.HttpRequest();
                    with.FormValue("name", originalSite.Name);
                    with.FormValue("sitepath", originalSite.SitePath);
                    with.FormValue("bindingsuserinput", "http://unit-test-site-edited.com");
                    with.FormValue("bindingsipaddress", "*");
                    with.FormValue("bindingscertificatename", "Servant");
                    with.FormValue("applicationpool", originalSite.ApplicationPool);
                });

            var body = response.Body.AsString();

            StringAssert.Contains("var message = \"Settings have been saved.\"", body);
        }
예제 #5
0
        public void Cannot_Create_Application_With_Invalid_Path()
        {
            var browser = new BrowserBuilder().WithDefaultConfiguration().Build();
            var site = GetTestSiteFromIis();

            var response = browser.Post("/sites/" + site.IisId + "/applications/", with =>
            {
                with.Authenticated();
                with.HttpRequest();
                with.FormValue("path", "virtual%¤#<*>apptest");
                with.FormValue("applicationpool", site.ApplicationPool);
                with.FormValue("diskpath", "C:");
            });

            var body = response.Body.AsString();
            StringAssert.Contains("Path cannot contain the following characters", body);
        }
예제 #6
0
        public void Can_Create_Application()
        {
            var browser = new BrowserBuilder().WithDefaultConfiguration().Build();
            var site = GetTestSiteFromIis();

            var response = browser.Post("/sites/" + site.IisId + "/applications/", with =>
            {
                with.Authenticated();
                with.HttpRequest();
                with.FormValue("path", "virtualapptest");
                with.FormValue("applicationpool", site.ApplicationPool);
                with.FormValue("diskpath", "C:");
            });

            var body = response.Body.AsString();
            StringAssert.Contains("var message = \"Applications have been saved.\";", body);
        }
예제 #7
0
        public void Can_Delete_Site()
        {
            var browser = new BrowserBuilder().WithDefaultConfiguration().Build();
            var originalSite = GetTestSiteFromIis();

            var response = browser.Post("/sites/" + originalSite.IisId + "/delete/", with =>
                {
                    with.Authenticated();
                    with.HttpRequest();
                });

            response.ShouldHaveRedirectedTo("/");
        }
예제 #8
0
        public void Cannot_Save_Site_Settings_With_Errors()
        {
            var browser = new BrowserBuilder().WithDefaultConfiguration().Build();
            var originalSite = GetTestSiteFromIis();

            var response = browser.Post("/sites/" + originalSite.IisId + "/settings/", with =>
            {
                with.Authenticated();
                with.HttpRequest();
                with.FormValue("name", originalSite.Name);
                with.FormValue("sitepath", originalSite.SitePath);
                with.FormValue("bindingsuserinput", "http://unit-test-site-edite%%d.com");
                with.FormValue("bindingsipaddress", "*");
                with.FormValue("bindingscertificatename", "Servant");
                with.FormValue("applicationpool", originalSite.ApplicationPool);
            });

            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
            
            var body = response.Body.AsString();

            StringAssert.Contains("\"Message\":\"The binding is invalid.\",\"PropertyName\":\"bindingsuserinput[0]\"", body);
        }