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; } }
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); }
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); }
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; } }
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; } }
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; } }
public void Passes_Pass() { var target = new Target<string>("name", "value"); Expression<Predicate<string>> expr = s => true; CoreExtensions.Passes(target, expr); }
public void Fails_Pass() { var target = new Target<string>("name", "value"); Expression<Predicate<string>> expr = s => false; CoreExtensions.Fails(target, expr); }
public TargetDebuggerProxy(Target target) { if (target == null) throw new ArgumentNullException("target"); this.target = target; }