public void WhenValid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IValidationErrors errors = new ValidationErrors(); ErrorMessageAction action = new ErrorMessageAction("error", "errors"); action.Execute(true, context, null, errors); Assert.IsTrue(errors.IsEmpty); }
public void WhenActionIsNotExecutedBecauseWhenExpressionReturnsFalse() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IValidationErrors errors = new ValidationErrors(); ErrorMessageAction action = new ErrorMessageAction("{0}, {1}", "errors"); action.When = Expression.Parse("false"); action.Execute(false, context, null, errors); Assert.IsTrue(errors.IsEmpty); }
public void WhenInvalid() { Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"); IValidationErrors errors = new ValidationErrors(); ErrorMessageAction action = new ErrorMessageAction("{0}, {1}", "errors"); action.Parameters = new IExpression[] { Expression.Parse("Name"), Expression.Parse("Nationality") }; action.Execute(false, context, null, errors); Assert.IsFalse(errors.IsEmpty); Assert.AreEqual(1, errors.GetErrors("errors").Count); Assert.AreEqual(context.Name + ", " + context.Nationality, errors.GetResolvedErrors("errors", new NullMessageSource())[0]); }