public IEnumerable <IArgumentSpecification> Create(IList <IArgumentSpecification> argumentSpecs, object[] arguments, IParameterInfo[] parameterInfos)
        {
            var suppliedArgumentSpecifications = _suppliedArgumentSpecificationsFactory.Create(argumentSpecs);

            return
                (new List <IArgumentSpecification>(
                     arguments.Select(
                         (argument, i) => _argumentSpecificationFactory.Create(
                             argument, parameterInfos[i], suppliedArgumentSpecifications)
                         )
                     ));
        }
예제 #2
0
        public IEnumerable <IArgumentSpecification> Create(IList <IArgumentSpecification> argumentSpecs, object[] arguments, IParameterInfo[] parameterInfos)
        {
            var suppliedArgumentSpecifications = _suppliedArgumentSpecificationsFactory.Create(argumentSpecs);

            var result = arguments
                         .Select((arg, i) => _argumentSpecificationFactory.Create(arg, parameterInfos[i], suppliedArgumentSpecifications))
                         .ToArray();

            var remainingArgumentSpecifications = suppliedArgumentSpecifications.DequeueRemaining();

            if (remainingArgumentSpecifications.Any())
            {
                throw new RedundantArgumentMatcherException(remainingArgumentSpecifications, suppliedArgumentSpecifications.AllSpecifications);
            }

            return(result);
        }
예제 #3
0
        public IEnumerable <IArgumentSpecification> Create(IList <IArgumentSpecification> argumentSpecs, object[] arguments, IParameterInfo[] parameterInfos, MethodInfo methodInfo, MatchArgs matchArgs)
        {
            var suppliedArgumentSpecifications = _suppliedArgumentSpecificationsFactory.Create(argumentSpecs);

            var result = new List <IArgumentSpecification>();

            for (var i = 0; i < arguments.Length; i++)
            {
                var arg       = arguments[i];
                var paramInfo = parameterInfos[i];

                try
                {
                    result.Add(_argumentSpecificationFactory.Create(arg, paramInfo, suppliedArgumentSpecifications));
                }
                catch (AmbiguousArgumentsException ex) when(ex.ContainsDefaultMessage)
                {
                    IEnumerable <IArgumentSpecification> alreadyResolvedSpecs = result;

                    if (ex.Data[AmbiguousArgumentsException.NonReportedResolvedSpecificationsKey] is IEnumerable <IArgumentSpecification> additional)
                    {
                        alreadyResolvedSpecs = alreadyResolvedSpecs.Concat(additional);
                    }

                    throw new AmbiguousArgumentsException(methodInfo, arguments, alreadyResolvedSpecs, argumentSpecs);
                }
            }

            var remainingArgumentSpecifications = suppliedArgumentSpecifications.DequeueRemaining();

            if (remainingArgumentSpecifications.Any())
            {
                throw new RedundantArgumentMatcherException(remainingArgumentSpecifications, argumentSpecs);
            }

            return(matchArgs == MatchArgs.Any
                ? ConvertToMatchAnyValue(result)
                : result);
        }