예제 #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
파일: Target.cs 프로젝트: joshampton/Demand
        public TargetDebuggerProxy(Target target)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            this.target = target;
        }