public void InterpolatingValues()
 {
     var info = new InterpolationInfo(typeof(Foo), new Foo { Number = 82 }, "Number", new RangeAttribute(), null,
                                      "The value of foo is ${Number} + {Number}");
     var result = GetInitializedInterpolator().Interpolate(info);
     Assert.AreEqual("The value of foo is 82 + 12", result);
 }
 public string CreateDefaultMessage(InterpolationInfo info)
 {
     return string.IsNullOrEmpty(info.PropertyName) ?
         string.Format(EntityValidatorConvention, GetEntityValidatorName(info))
         :
         string.Format(EntityPropertyValidatorConvention, info.Entity.Name, info.PropertyName);
 }
 public void InterpolatingValues_WrongMember()
 {
     var info = new InterpolationInfo(typeof(Foo), new Foo { Number = 82 }, "Number", new RangeAttribute(), null,
                                                                  "The value of foo is ${WrongMember}.");
     ActionAssert.Throws<InvalidPropertyNameException>(
         () =>
         GetInitializedInterpolator().Interpolate(info));
 }
 public string Interpolate(InterpolationInfo info)
 {
     string result = info.Message;
     if (string.IsNullOrEmpty(result))
     {
         result = CreateDefaultMessage(info);
     }
     do
     {
         info.Message = Replace(result, info.Entity, info.PropertyName);
         result = info.DefaultInterpolator.Interpolate(info);
     }
     while (!Equals(result, info.Message));
     return result;
 }
        public void Interpolate()
        {
            var defrm = new ResourceManager(Environment.BaseNameOfMessageResource,
                                    typeof (DefaultMessageInterpolatorAggregator).Assembly);
            var custrm = new ResourceManager("NHibernate.Validator.Tests.Resource.Messages", Assembly.GetExecutingAssembly());
            var culture = new CultureInfo("en");

            var mia = new DefaultMessageInterpolatorAggregator();
            var dmi = new DefaultMessageInterpolator();
            mia.Initialize(custrm, defrm, culture);
            var va = new RangeAttribute(2, 10);

            var info = new InterpolationInfo(typeof (object), new object(), null, va, dmi, va.Message);
            Assert.AreEqual(va.Message, mia.Interpolate(info));

            mia.AddInterpolator(va, va);
            var info1 = new InterpolationInfo(typeof(object), new object(), null, va, dmi, va.Message);
            Assert.AreNotEqual(va.Message, mia.Interpolate(info1));
        }
 public string Interpolate(InterpolationInfo info)
 {
     return info.Message;
 }
        public virtual string Interpolate(InterpolationInfo info)
        {
            var message = info.Message;
            bool same = attributeMessage.Equals(message);
            if (same && interpolateMessage != null && !message.Contains("${"))
            {
                return interpolateMessage; //short cut
            }

            string result = Replace(message, info.EntityInstance);
            if (same)
            {
                interpolateMessage = result; //short cut in next iteration
            }
            return result;
        }
 public string Interpolate(InterpolationInfo info)
 {
     return "prefix_" + info.DefaultInterpolator.Interpolate(info);
 }
 public string Interpolate(InterpolationInfo info)
 {
     throw new NotImplementedException();
 }
 public string Interpolate(InterpolationInfo info)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 private string GetEntityValidatorName(InterpolationInfo info)
 {
     var entityValidatorName = info.Entity.Name;
     var validatorType = info.Validator.GetType();
     if (validatorType.IsGenericType)
     {
         entityValidatorName = validatorType.GetGenericArguments().First().Name;
     }
     entityValidatorName = CleanValidatorPostfix(entityValidatorName);
     return entityValidatorName;
 }