Inheritance: Spring.Web.UI.Page
Exemplo n.º 1
0
        public void ValidateSetsDefaultVariables()
        {
            TestPage page = new TestPage(HttpContext.Current);
            TestUserControl c1 = new TestUserControl();
            page.Controls.Add(c1);

            ConditionValidator v1 = new ConditionValidator("#page == #this.Page", null);
            ConditionValidator v2 = new ConditionValidator("#usercontrol == #this", null);

            Assert.IsTrue(c1.Validate(c1, v1, v2));
        }
Exemplo n.º 2
0
        public void StyleBlockRendersTypeAttribute()
        {
            TestPage page = new TestPage();
            Head head = new Head();
            page.Controls.Add(head);

            page.Styles.Add("stylename", "stylevalue");

            string result = page.Render(string.Empty);
            string expect = @"<head><style type=""text/css"">stylename { stylevalue }</style></head>";
            Assert.AreEqual(expect, result);
        }
Exemplo n.º 3
0
        public void StyleFileRendersTypeAttributeAndUsesCssRootPath()
        {
            const string STYLESHEETPATH = "filepath";

            using (new TestWebContext("/", "testpage.aspx"))
            {
                TestPage page = new TestPage(HttpContext.Current);
                Head head = new Head();
                page.Controls.Add(head);

                page.CssRoot = "testcssroot";
                page.StyleFiles.Add("filename", STYLESHEETPATH);

                string result = page.Render(string.Empty);
                string expect = string.Format(@"<head><link rel=""stylesheet"" type=""text/css"" href=""/testcssroot/{0}"" /></head>", STYLESHEETPATH);
                Assert.AreEqual(expect, result);
            }
        }
Exemplo n.º 4
0
        public void DontRenderHeadTagIfNestedWithinStandardHeadControl()
        {
            using (new TestWebContext("/", "testpage.aspx"))
            {
                TestPage page = new TestPage(HttpContext.Current);
                HtmlHead htmlHead = new HtmlHead();
                Head head = new Head();
                head.Controls.Add(new LiteralControl("literal child"));
                htmlHead.Controls.Add(head);
                page.Controls.Add(htmlHead);

                // initialize page to force head control initialization
                page.InitRecursive(null);
                string result = page.Render(string.Empty);
                string expect = @"<head>literal child<title></title></head>";
                Assert.AreEqual(expect, result);
            }
        }
Exemplo n.º 5
0
        public void Validate()
        {           
            Page page = new TestPage(HttpContext.Current);
            IValidator[] validators = new IValidator[] {new RequiredValidator("Name", null), new ConditionValidator("Loan == 0", "Age > 21")};
            Contact contact = new Contact("Goran", 24, 0);
            bool result = page.Validate(contact, validators);
            Assert.IsTrue(result);

            contact = new Contact(null, 24, 0);
            result = page.Validate(contact, validators);
            Assert.IsFalse(result);

            contact = new Contact("Goran", 24, 1);
            result = page.Validate(contact, validators);
            Assert.IsFalse(result);
        }
Exemplo n.º 6
0
 public void StoresAndLoadsModelUsingModelPersistenceMedium()
 {
     TestPage tuc = new TestPage();
     tuc.ModelPersistenceMedium = new DictionaryModelPersistenceMedium();
     tuc.SaveModelToPersistenceMedium( this );
     Assert.AreEqual(this, tuc.LoadModelFromPersistenceMedium());
 }
Exemplo n.º 7
0
 public void NoNullModelPersistenceMediumAllowed()
 {
     TestPage tuc = new TestPage();
     tuc.ModelPersistenceMedium = null;
 }
Exemplo n.º 8
0
        public void SetResultSelectsCorrectResult()
        {
            MockRepository mocks = new MockRepository();
            TestPage page = new TestPage();

            Result theResult = (Result) mocks.CreateMock(typeof (Result));
            theResult.Navigate(page);
            mocks.ReplayAll();

            page.Results.Add( "theResult", theResult );
            page.SetResult("theResult");
            mocks.VerifyAll();
        }
Exemplo n.º 9
0
        public void SetResultThrowsVerboseExceptionOnUnknownResultName()
        {
            string RESULTNAME = "nonexistant result";

            TestPage page = new TestPage();
            try
            {
                page.SetResult(RESULTNAME);
                Assert.Fail();
            }
            catch(ArgumentException ae)
            {
                string expected = string.Format("No mapping found for the specified destination '{0}'.", RESULTNAME);
                string msg = ae.Message.Substring(0, expected.Length);
                Assert.AreEqual(expected, msg);
            }
        }
Exemplo n.º 10
0
 public void AllowsNeutralUserCulture()
 {
     TestPage page = new TestPage();
     // DefaultWebCultureResolver does not allow culture to be set
     page.CultureResolver = new DefaultCultureResolver();
     page.UserCulture = new CultureInfo("de");
     
     page.InitializeCulture();
     Assert.AreEqual( page.UserCulture, Thread.CurrentThread.CurrentUICulture );
     Assert.AreEqual( CultureInfo.CreateSpecificCulture(page.UserCulture.Name), Thread.CurrentThread.CurrentCulture);
 }
Exemplo n.º 11
0
 public void DefaultsToDefaultWebCultureResolver()
 {
     TestPage page = new TestPage();
     Assert.AreEqual( typeof(DefaultWebCultureResolver), page.CultureResolver.GetType() );            
 }
Exemplo n.º 12
0
        public void ScriptBlockRendersTypeAttribute()
        {
            TestPage page = new TestPage();
            Head head = new Head();
            page.Controls.Add(head);

            page.RegisterHeadScriptBlock( "scriptname", "scriptcode" );

            string result = page.Render(string.Empty);
            string expect = @"<head><script type=""text/javascript"">scriptcode</script></head>";
            Assert.AreEqual(expect, result);
        }
Exemplo n.º 13
0
        public void RenderChildrenFirst()
        {
            TestPage page = new TestPage();
            Head head = new Head();
            page.Controls.Add(head);
            
            head.Controls.Add(new LiteralControl("literal child"));
            page.Styles.Add("stylename", "stylevalue");

            string result = page.Render(string.Empty);
            string expect = @"<head>literal child<style type=""text/css"">stylename { stylevalue }</style></head>";
            Assert.AreEqual( expect, result);
        }
Exemplo n.º 14
0
        public void ScriptFileRendersTypeAttributeAndUsesScriptsRootPath()
        {
            const string SCRIPTFILEPATH = "filepath";

            using (new TestWebContext("/", "testpage.aspx"))
            {
                TestPage page = new TestPage(HttpContext.Current);
                Head head = new Head();
                page.Controls.Add(head);

                page.ScriptsRoot = "testscriptroot";
                page.RegisterHeadScriptFile("filename", SCRIPTFILEPATH);

                string result = page.Render(string.Empty);
                string expect = string.Format(@"<head><script type=""text/javascript"" src=""/testscriptroot/{0}""></script></head>", SCRIPTFILEPATH);
                Assert.AreEqual(expect, result);
            }
        }
Exemplo n.º 15
0
 public void NoNullModelPersistenceMediumAllowed()
 {
     TestPage tuc = new TestPage();
     Assert.Throws<ArgumentNullException>(() => tuc.ModelPersistenceMedium = null);
 }