Пример #1
0
 dynamic Add(ChainStep name)
 {
     return new Check(subject, chain, name);
 }
Пример #2
0
 static bool StepIndex(Result result, ChainStep step, object[] container, out object next, ref string pathHere)
 {
     next = null;
     if (step.SingleIndex < 0 || step.SingleIndex >= container.Length)
     {
         result.FailBecause(pathHere + " has length of " + container.Length + ", tried to access index " + step.SingleIndex);
         return false;
     }
     pathHere += "[" + step.SingleIndex + "]";
     next = container[step.SingleIndex];
     return true;
 }
Пример #3
0
 Check(object subject, IEnumerable<ChainStep> oldChain, ChainStep nextItem)
 {
     this.subject = subject;
     chain = new List<ChainStep>(oldChain) { nextItem };
 }
Пример #4
0
        static object[] FilterWithNamedPredicate(IEnumerable source, ChainStep step, out string message)
        {
            string stepMsg = "";
            var container = source.Cast<object>().Where(o => step.FilterPredicate.Matches(o, out stepMsg)).ToArray();

            message = (string.IsNullOrEmpty(stepMsg))
                ? ""
                : "(Matching: " + stepMsg + ")";

            return container;
        }
Пример #5
0
        static void ApplyPredicatesToTerminalEnumerable(string path, Result result, IList<INamedPredicate> predicates, ChainStep step)
        {
            string stepMsg;
            var container = FilterWithNamedPredicate((IEnumerable)result.Target, step, out stepMsg);
            path += stepMsg;
            object target;
            switch (step.ListAssertionType)
            {
                case ListAssertion.Simple:
                    ApplyPredicatesToSimpleTerminal(path, result, predicates);
                    break;

                case ListAssertion.Single:
                    if (!StepSingle(result, path, container, out target)) return;
                    var singleResult = new Result{Target = target};
                    ApplyPredicatesToSimpleTerminal(path, singleResult, predicates);
                    result.Merge(singleResult);
                    break;

                case ListAssertion.Index:
                    if (!StepIndex(result, step, container, out target, ref path)) return;
                    var indexResult = new Result{Target = target};
                    ApplyPredicatesToSimpleTerminal(path, indexResult, predicates);
                    result.Merge(indexResult);
                    break;

                case ListAssertion.All:
                    CheckAll(result, predicates, path, container);
                    return;

                case ListAssertion.Any:
                    CheckAny(result, predicates, path, container);
                    return;

                default:
                    throw new Exception("Unexpected list assertion type");
            }
        }