Пример #1
0
        public void Fails_Fails_Exception()
        {
            var target = new Target<string>("name", "value");

            var returnTarget = Expression.Label(typeof(bool));
            var returnExpression = Expression.Return(returnTarget, Expression.Constant(true, typeof(bool)), typeof(bool));
            var returnLabel = Expression.Label(returnTarget, Expression.Default(typeof(bool)));

            var body = Expression.Block(
                Expression.Throw(Expression.New(typeof(Exception))),
                returnExpression,
                returnLabel
                );

            Expression<Predicate<string>> expr = Expression.Lambda<Predicate<string>>(body, Expression.Parameter(typeof(string), "s"));

            try
            {
                CoreExtensions.Fails(target, expr);
            }
            catch (ValidationFailedException e)
            {
                Assert.IsNotNull(e.InnerException);
                Assert.AreEqual(e.TargetName, "name");
                Assert.AreEqual(typeof(Exception), e.InnerException.GetType());
                throw;
            }
        }
Пример #2
0
        public void Constructor()
        {
            var target = new Target<string>("asdf", "fdsa");
            var proxy = new TargetDebuggerProxy(target);

            Assert.AreEqual("asdf", proxy.Name);
            Assert.AreEqual("fdsa", proxy.Value);
            Assert.ReferenceEquals(target.Name, proxy.Name);
            Assert.ReferenceEquals(target.Value, target.Value);
        }
Пример #3
0
        public void Constructor()
        {
            string name = "asdf";
            string value = "asdf";

            var target = new Target<string>(name, value);

            Assert.AreEqual(target.Name, name);
            Assert.AreEqual(target.Value, value);
            Assert.AreEqual(target.TypeSafeValue, value);
        }
Пример #4
0
 public void Fails_Fails()
 {
     var target = new Target<string>("name", "value");
     Expression<Predicate<string>> expr = s => true;
     try
     {
         CoreExtensions.Fails(target, expr);
     }
     catch (ValidationFailedException e)
     {
         Assert.AreEqual(target.Name, e.TargetName);
         Assert.AreEqual("True", e.Validation);
         throw;
     }
 }
Пример #5
0
        public void Constructor_NullName()
        {
            string value = "asdf";
            try
            {

                var target = new Target<string>(null, value);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual("name cannot be null or empty\r\nParameter name: name", e.Message);
                Assert.AreEqual("name", e.ParamName);
                throw;
            }
        }
Пример #6
0
 public void Fails_NullValidation()
 {
     Target<string> target = new Target<string>("name", "value");
     try
     {
         CoreExtensions.Fails(target, null);
     }
     catch (ArgumentNullException e)
     {
         Assert.AreEqual("validation", e.ParamName);
         throw;
     }
 }
Пример #7
0
        public void Passes_Pass()
        {
            var target = new Target<string>("name", "value");
            Expression<Predicate<string>> expr = s => true;

            CoreExtensions.Passes(target, expr);
        }
Пример #8
0
        public void Fails_Pass()
        {
            var target = new Target<string>("name", "value");
            Expression<Predicate<string>> expr = s => false;

            CoreExtensions.Fails(target, expr);
        }
Пример #9
0
        public TargetDebuggerProxy(Target target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            this.target = target;
        }