public void ReturnsExpectedResultForARuleSetThatReturnsSuccess() { var rules = new List <IRule> { AnyRuleThatReturns(Result.Ok()), AnyRuleThatReturns(Result.Ok()) }; _ruleSet.GetRules().Returns(rules); _ruleSetFactory.GetRuleSet(Arg.Any <RuleSetType>()).Returns(_ruleSet); var ruleSetProcessor = new RuleSetProcessor(_ruleSetFactory); var result = ruleSetProcessor.ApplyRuleSet(new ScheduledFlightContext()); result.IsSuccess.ShouldBeTrue(); }
public Result ApplyRuleSet(ScheduledFlightContext ruleContext) { var ruleSet = _ruleSetFactory.GetRuleSet(ruleContext.RuleSetType); var results = ruleSet.GetRules().Select(rule => rule.Apply(ruleContext)).ToList(); return(results.Any(r => r.IsFailure) ? Result.Fail(string.Join(",", results.Where(r => r.IsFailure).Select(r => r.Error))) : Result.Ok()); }