public void Validator_RuleDependOnContext_GenerateError() { var entity = GetEntity(); entity.Setup(p => p.DocType).Returns("Excel"); var validator = new Validator(); var rule = new FluentRule(); var validationContext = new FluentRuleRuleSet(rule); var res = validator.Validate(validationContext, entity.Object, new ValidationContext(12)); Assert.IsTrue(res.Results.Any()); }
public void Validator_FluentRule_HasManyMessages() { var entity = GetEntity(); entity.Setup(p => p.DocType).Returns("Excel"); var accountInfo = new Mock <IAccInfo>(); accountInfo.Setup(info => info.AccountType).Returns("CurrentInThirdpartyBank"); accountInfo.Setup(a => a.Account).Returns("New account"); accountInfo.Setup(a => a.AccountCba).Returns("1234567890"); entity.Setup(p => p.AccountsInfo).Returns(accountInfo.Object); var validator = new Validator(); var rule = new FluentRule(); var validationContext = new FluentRuleRuleSet(rule); var res = validator.Validate(validationContext, entity.Object, null); Assert.IsTrue(res.Results.Count == 1); Assert.IsTrue(res.Results[0].Messages.Count() == 2); }
public void Validator_FluentRule_OverrideMessages() { var entity = GetEntity(); entity.Setup(p => p.DocType).Returns("Excel"); var accountInfo = new Mock <IAccInfo>(); accountInfo.Setup(info => info.AccountType).Returns("CurrentInThirdpartyBank"); accountInfo.Setup(a => a.Account).Returns("New account"); accountInfo.Setup(a => a.AccountCba).Returns("1234567890"); entity.Setup(p => p.AccountsInfo).Returns(accountInfo.Object); var validator = new Validator(); var rule = new FluentRule(); var validationContext = new FluentRuleRuleSet(rule); var res = validator.Validate(validationContext, entity.Object, null); var formatter = new FluentRuleMessageFormatter(); res = formatter.Format(res); Assert.IsTrue(res.Results[0].Messages.First().Error == "A type of an account 1234567890 must be CurrentInThirdpartyBank"); Assert.IsTrue(res.Results[0].Messages.Last().Error == "A type of an action must not be Update"); }