예제 #1
0
        /// <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);
                }
            }
        }
예제 #2
0
 /// <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));
 }
예제 #3
0
 /// <inheritdoc/>
 public void AddRule(AssertionRule rule)
 {
     _response.AddRule(rule);
 }