public void IsValidShouldReturnsRuleOneTime() { var myField = -1; var v = new ValidatorRules(); var rule = new Mock <IValidatorRule>(); v.AddRule(nameof(myField), rule.Object); v.IsValid(nameof(myField), myField); rule.Verify(s => s.IsValid(It.IsAny <object>()), Times.Once); }
public void AddRuleIncorrectShouldReturnException() { var myField = 400000000; var v = new ValidatorRules(); var rule = new Mock <IValidatorRule>(); rule.Setup(s => s.IsValid(myField)).Throws <StackOverflowException>(); v.AddRule(nameof(myField), rule.Object); void del() => v.IsValid(nameof(myField), myField); Assert.Throws <StackOverflowException>(del); }
public void IsValidShouldReturnsTrueIfRuleIsValid() { var myField = -1; var v = new ValidatorRules(); var rule = new Mock <IValidatorRule>(); rule.Setup(s => s.IsValid(myField)).Returns(true); v.AddRule(nameof(myField), rule.Object); var actual = v.IsValid(nameof(myField), myField); Assert.That(actual, Is.True); }