Esempio n. 1
0
        private static void ThrowSpecificationErrorWithoutLabel(SpecificationContext context, SpecificationResult result, SetDefinitionTarget?priorTarget, SetDefinitionTarget target)
        {
            string targetDescription;
            Type   targetType;
            string targetName;

            if (priorTarget == null)
            {
                var parameter = context.GetFirstVariable();
                targetDescription = $"parameter \"{parameter.Label.Name}\"";
                targetType        = parameter.Type;
                targetName        = parameter.Label.Name;
            }
            else if (result.TryGetLabelOf(priorTarget, out var priorLabel))
            {
                targetDescription = $"prior variable \"{priorLabel.Name}\"";
                targetType        = priorTarget.Type;
                targetName        = priorLabel.Name;
            }
            else
            {
                targetDescription = $"prior variable";
                targetType        = priorTarget.Type;
                targetName        = "x";
            }
            var typeName       = target.Type.Name;
            var variable       = ToInitialLowerCase(typeName);
            var message        = $"The set should be joined to the {targetDescription}.";
            var recommendation = RecommendationEngine.RecommendJoin(
                new CodeExpression(target.Type, variable),
                new CodeExpression(targetType, targetName)
                );

            throw new SpecificationException(recommendation == null ? message : $"{message} Consider \"facts.OfType<{typeName}>({variable} => {recommendation})\".");
        }
Esempio n. 2
0
        public static Pipeline CreatePipeline(SpecificationContext context, SpecificationResult result)
        {
            SetDefinitionTarget?priorTarget = null;

            foreach (var target in result.Targets)
            {
                if (!result.SetDefinitions.Any(set => IsJoinTargeting(set, target)))
                {
                    if (result.TryGetLabelOf(target, out var label))
                    {
                        ThrowSpecificationErrorWithLabel(context, result, priorTarget, target, label);
                    }
                    else
                    {
                        ThrowSpecificationErrorWithoutLabel(context, result, priorTarget, target);
                    }
                }
                priorTarget = target;
            }
            var pipeline = context.Labels
                           .Aggregate(Pipeline.Empty, (p, label) => p.AddStart(label));

            foreach (var setDefinition in result.SetDefinitions)
            {
                pipeline = AppendToPipeline(pipeline, context, setDefinition, result);
            }
            return(pipeline);
        }