public void Process_GivenNullRuleEngineContext_ThrowsArgumentException() { var mockRuleCollection = new MockRuleCollection(); var ruleProcessor = new RuleProcessor(); ruleProcessor.Process(null, mockRuleCollection.MyMockRule); }
public void Process_GivenARule_CallsWhenClause() { var customer = new Customer(); var ruleEngineContext = new RuleEngineContext <Customer> (customer); var mockRuleCollection = new MockRuleCollection(); var ruleProcessor = new RuleProcessor(); ruleProcessor.Process(ruleEngineContext, mockRuleCollection.MyMockRule); Assert.IsTrue(mockRuleCollection.WhenClauseCalled); }
public void Process_WhenWhenClauseReturnsFalse_DoesNotCallThenClause() { var customer = new Customer(); var ruleEngineContext = new RuleEngineContext <Customer> (customer); var mockRuleCollection = new MockRuleCollection { WhenClauseReturns = false }; var ruleProcessor = new RuleProcessor(); ruleProcessor.Process(ruleEngineContext, mockRuleCollection.MyMockRule); Assert.IsFalse(mockRuleCollection.ThenClauseCalled); }
public void Process_WhenRuleIsSkipAndViolationError_RuleIsSkiped() { var customer = new Customer(); var ruleEngineContext = new RuleEngineContext <Customer> (customer); var mockRuleCollection = new MockRuleCollection { WhenClauseReturns = false }; ruleEngineContext.RuleViolationReporter.Report(new RuleViolation(mockRuleCollection.MyMockRule, null, null)); (mockRuleCollection.MyMockRule as Rule).AddShouldRunClause(ctx => ctx.RuleViolationReporter.Count() == 0); var ruleProcessor = new RuleProcessor(); ruleProcessor.Process(ruleEngineContext, mockRuleCollection.MyMockRule); Assert.IsFalse(mockRuleCollection.WhenClauseCalled); }