public void NoExceptionWhenNoValidationContainer()
        {
            TestValidationControl vc = new TestValidationControl();

            Assert.IsFalse(vc.TheDesignMode);
            Assert.IsNull(vc.TheMessageSource);
            Assert.IsNull(vc.TheValidationContainer);

            vc.TestRender(null);
        }
        public void ResolvesAndRendersValidationErrorsUsingValidationContainer()
        {
            TestValidationControl vc = new TestValidationControl();
            vc.ID = "TestControl";

            Page page = new Page();
            page.Controls.Add(vc);
            page.ValidationErrors.AddError(vc.Provider, new ErrorMessage("msgId"));
            StaticMessageSource msgSrc = new StaticMessageSource();
            msgSrc.AddMessage("msgId", CultureInfo.CurrentUICulture, "Resolved Message Text");
            page.MessageSource = msgSrc;

            vc.TestRender(null);
            Assert.AreEqual("Resolved Message Text", vc.LastErrorsRendered[0]);
        }
        public void NoExceptionWhenNoErrors()
        {
            Page page = new Page();

            page.MessageSource = new StaticMessageSource();
            TestValidationControl vc = new TestValidationControl();

            page.Controls.Add(vc);

            // assert assumptions
            Assert.IsFalse(vc.TheDesignMode);
            Assert.AreSame(page, vc.TheValidationContainer);
            Assert.AreSame(page.MessageSource, vc.TheMessageSource);
            Assert.AreEqual(0, page.ValidationErrors.GetResolvedErrors(vc.Provider, vc.TheMessageSource).Count);

            vc.TestRender(null);
        }
        public void ResolvesAndRendersValidationErrorsUsingValidationContainer()
        {
            TestValidationControl vc = new TestValidationControl();

            vc.ID = "TestControl";

            Page page = new Page();

            page.Controls.Add(vc);
            page.ValidationErrors.AddError(vc.Provider, new ErrorMessage("msgId"));
            StaticMessageSource msgSrc = new StaticMessageSource();

            msgSrc.AddMessage("msgId", CultureInfo.CurrentUICulture, "Resolved Message Text");
            page.MessageSource = msgSrc;

            vc.TestRender(null);
            Assert.AreEqual("Resolved Message Text", vc.LastErrorsRendered[0]);
        }
        public void ThrowsIfCreateValidationErrorsRendererReturnsNull()
        {
            TestValidationControl vc = new TestValidationControl(null);

            vc.ID = "TestControl";

            Page page = new Page();

            page.Controls.Add(vc);
            page.ValidationErrors.AddError(vc.Provider, new ErrorMessage("msgId"));

            try
            {
                vc.TestRender(null);
                Assert.Fail();
            }
            catch (ArgumentNullException ane)
            {
                Assert.AreEqual("Renderer", ane.ParamName);
            }
        }
        public void NoExceptionWhenNoErrors()
        {
            Page page = new Page();
            page.MessageSource = new StaticMessageSource();
            TestValidationControl vc = new TestValidationControl();
            page.Controls.Add(vc);

            // assert assumptions
            Assert.IsFalse(vc.TheDesignMode);
            Assert.AreSame(page, vc.TheValidationContainer);
            Assert.AreSame( page.MessageSource, vc.TheMessageSource );
            Assert.AreEqual(0, page.ValidationErrors.GetResolvedErrors(vc.Provider, vc.TheMessageSource).Count);

            vc.TestRender(null);
        }
        public void NoExceptionWhenNoValidationContainer()
        {
            TestValidationControl vc = new TestValidationControl();
            Assert.IsFalse(vc.TheDesignMode);
            Assert.IsNull(vc.TheMessageSource);
            Assert.IsNull(vc.TheValidationContainer);

            vc.TestRender(null);
        }
        public void ThrowsIfCreateValidationErrorsRendererReturnsNull()
        {
            TestValidationControl vc = new TestValidationControl(null);
            vc.ID = "TestControl";

            Page page = new Page();
            page.Controls.Add(vc);
            page.ValidationErrors.AddError(vc.Provider, new ErrorMessage("msgId"));

            try
            {
                vc.TestRender(null);
                Assert.Fail();
            }
            catch (ArgumentNullException ane)
            {
                Assert.AreEqual("Renderer", ane.ParamName);
            }
        }