public void StaticMessageSourceToString()
 {
     StaticMessageSource msgSource = new StaticMessageSource();
     msgSource.AddMessage("code1", CultureInfo.CurrentUICulture, "{0} {1}");
     Assert.AreEqual("StaticMessageSource : ['code1_" + CultureInfo.CurrentUICulture.Name + "' : '{0} {1}']",
                     msgSource.ToString());
 }
 public void GetMessageCode()
 {
     StaticMessageSource msgSource = new StaticMessageSource();
     msgSource.AddMessage("code", CultureInfo.CurrentUICulture, "{0} {1}");
     Assert.AreEqual("my message",
                     msgSource.GetMessage("code", CultureInfo.CurrentUICulture, new object[] {"my", "message"}),
                     "message");
 }
        public void GetMessageCode()
        {
            StaticMessageSource msgSource = new StaticMessageSource();

            msgSource.AddMessage("code", CultureInfo.CurrentUICulture, "{0} {1}");
            Assert.AreEqual("my message",
                            msgSource.GetMessage("code", CultureInfo.CurrentUICulture, new object[] { "my", "message" }),
                            "message");
        }
        public void GetMessageDefaultsToCurrentUICulture()
        {
            StaticMessageSource msgSource = new StaticMessageSource();
            msgSource.AddMessage("code", CultureInfo.CurrentUICulture, "{0}");
            Assert.AreEqual("my message", msgSource.GetMessage("code", "my message"), "message");

            try
            {
                msgSource.GetMessage("code", CultureInfo.CurrentCulture);
                Assert.Fail("message");
            }
            catch(NoSuchMessageException)
            {}
        }
        public void GetMessageDefaultsToCurrentUICulture()
        {
            StaticMessageSource msgSource = new StaticMessageSource();

            msgSource.AddMessage("code", CultureInfo.CurrentUICulture, "{0}");
            Assert.AreEqual("my message", msgSource.GetMessage("code", "my message"), "message");

            try
            {
                msgSource.GetMessage("code", CultureInfo.CurrentCulture);
                Assert.Fail("message");
            }
            catch (NoSuchMessageException)
            {}
        }
        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]);
        }
        /// <summary>
        /// Associate the given message with the given code.
        /// </summary>
        /// <param name="code">The lookup code.</param>
        /// <param name="cultureInfo">
        /// The <see cref="System.Globalization.CultureInfo"/> that the message should be found within.
        /// </param>
        /// <param name="defaultMessage">The message associated with the lookup code.</param>
        public void AddMessage(string code, CultureInfo cultureInfo, string defaultMessage)
        {
            StaticMessageSource messageSource = (StaticMessageSource)GetObject(MessageSourceObjectName);

            messageSource.AddMessage(code, cultureInfo, defaultMessage);
        }