Exemplo n.º 1
0
        public bool IsSatisfiedBy(T candidate, out SpecificationResult result)
        {
            if (candidate == null)
            {
                result = new SpecificationResult(false,
                                                 CreateTraceMessage("", false),
                                                 new FailedSpecification(GetType(), GetParameters(), (object)null, "Collection is null"));
                return(false);
            }

            var overall = OverallForEmpty;
            var failedSpecifications = new List <FailedSpecification>();
            var traces = new List <string>();

            var idx   = 0;
            var total = 1;

            foreach (var el in candidate)
            {
                var specOverall = CollectionElementSpecification.IsSatisfiedBy(el, out var specResult);

                total += specResult.TotalSpecificationsCount;
                if (!string.IsNullOrEmpty(specResult.Trace))
                {
                    traces.Add($"[{idx}]({specResult.Trace})");
                }

                if (!CanContinue(specOverall, ref overall))
                {
                    break;
                }

                if (!specOverall)
                {
                    var failures = CreateFailedSpecifications(specResult.FailedSpecifications, idx);
                    failedSpecifications.AddRange(failures);
                }

                idx++;
            }

            if (!overall)
            {
                failedSpecifications.Insert(0, new FailedSpecification(
                                                GetType(),
                                                GetParameters(),
                                                candidate,
                                                CreateFailedMessage()));
            }
            else
            {
                failedSpecifications.Clear();
            }

            var trace = CreateTraceMessage(string.Join($" {TraceConnector} ", traces), overall);

            result = new SpecificationResult(total, overall, trace, failedSpecifications.ToArray());

            return(overall);
        }
Exemplo n.º 2
0
 public override bool IsSatisfiedBy(T candidate)
 {
     return(candidate != null && candidate.All(c => CollectionElementSpecification.IsSatisfiedBy(c)));
 }