/// <summary> /// Adds a rule to be asserted. If <code>AutoAssertWhenAddingRule</code> is <code>true</code> then will also assert the new rule. /// </summary> /// <param name="rule"></param> public void AddRule(AssertionRule rule) { _rules.Add(rule); if (AutoAssertWhenAddingRule) { if (Request.Assertion == null) { throw new InvalidOperationException(ErrorMessages.NoAssertion); } var assertionResults = rule.Assert(Context); if (assertionResults.Any()) { var result = CreateExecutionResult(); result.Results.AddRange(assertionResults); Request.Assertion.Assert(result); } } }
/// <summary> /// Constructor to create the assertion result based on a rule and the explanation message /// </summary> /// <param name="rule">Rule that caused this result</param> /// <param name="message">Human friendly message that explains the result</param> public AssertionResult(AssertionRule rule, string message) { CausedBy = rule ?? throw new ArgumentNullException(nameof(rule)); ErrorMessage = message ?? throw new ArgumentNullException(nameof(ErrorMessage)); }
/// <inheritdoc/> public void AddRule(AssertionRule rule) { _response.AddRule(rule); }