public override void Context() { base.Context(); _parameterInfo = mock <IParameterInfo>(); _argumentEqualsSpecificationFactory = mock <IArgumentEqualsSpecificationFactory>(); _suppliedArgumentSpecifications = mock <ISuppliedArgumentSpecifications>(); }
public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { if (_defaultChecker.IsDefault(argument, parameterInfo.ParameterType)) { if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType)) { var argumentSpecification = suppliedArgumentSpecifications.Dequeue(); if (suppliedArgumentSpecifications.DequeueRemaining().Count() == 0) { return argumentSpecification; } } else if (!suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType)) { if (suppliedArgumentSpecifications.DequeueRemaining().Count() == 0) { return _argumentEqualsSpecificationFactory.Create(argument, parameterInfo.ParameterType); } } } else { var paramterInfosFromParamsArray = _parameterInfosFromParamsArrayFactory.Create(argument, parameterInfo.ParameterType); var suppliedArgumentSpecificationsFromParamsArray = _suppliedArgumentSpecificationsFactory.Create(suppliedArgumentSpecifications.DequeueRemaining()); var arrayArgumentSpecifications = _arrayArgumentSpecificationsFactory.Create(argument, paramterInfosFromParamsArray, suppliedArgumentSpecificationsFromParamsArray); return _arrayContentsArgumentSpecificationFactory.Create(arrayArgumentSpecifications, parameterInfo.ParameterType); } throw new AmbiguousArgumentsException(); }
public IArgumentSpecification Create(object?argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { return(parameterInfo.IsParams ? CreateSpecFromParamsArg(argument, parameterInfo, suppliedArgumentSpecifications) : CreateSpecFromNonParamsArg(argument, parameterInfo, suppliedArgumentSpecifications)); }
public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { if (parameterInfo.IsParams) { return _paramsArgumentSpecificationFactory.Create(argument, parameterInfo, suppliedArgumentSpecifications); } else { return _nonParamsArgumentSpecificationFactory.Create(argument, parameterInfo, suppliedArgumentSpecifications); } }
public override void Context() { _expectedResult = new[] { mock <IArgumentSpecification>(), mock <IArgumentSpecification>() }; _arrayArgument = new[] { "one", "two" }; _parameterInfos = new[] { mock <IParameterInfo>(), mock <IParameterInfo>() }; _suppliedArgumentSpecifications = mock <ISuppliedArgumentSpecifications>(); _nonParamsArgumentSpecificationFactory = mock <INonParamsArgumentSpecificationFactory>(); _nonParamsArgumentSpecificationFactory.stub(x => x.Create(_arrayArgument[0], _parameterInfos[0], _suppliedArgumentSpecifications)).Return(_expectedResult[0]); _nonParamsArgumentSpecificationFactory.stub(x => x.Create(_arrayArgument[1], _parameterInfos[1], _suppliedArgumentSpecifications)).Return(_expectedResult[1]); }
public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType)) { return suppliedArgumentSpecifications.Dequeue(); } if (!suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType) || parameterInfo.IsOptional || parameterInfo.IsOut) { return _argumentEqualsSpecificationFactory.Create(argument, parameterInfo.ParameterType); } throw new AmbiguousArgumentsException(); }
public IEnumerable<IArgumentSpecification> Create(object arrayArgument, IEnumerable<IParameterInfo> parameterInfos, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { var arrayMembers = (IEnumerable)arrayArgument; var index = 0; var result = new List<IArgumentSpecification>(); foreach (var member in arrayMembers) { result.Add(_nonParamsArgumentSpecificationFactory.Create(member, parameterInfos.ElementAt(index), suppliedArgumentSpecifications)); index++; } return result; }
public override void Context() { base.Context(); _argument = new[] { "one", "two", "three" }; _parameterInfo = mock <IParameterInfo>(); _parameterInfo.stub(x => x.ParameterType).Return(typeof(string[])); _argumentEqualsSpecificationFactory = mock <IArgumentEqualsSpecificationFactory>(); _arrayArgumentSpecificationsFactory = mock <IArrayArgumentSpecificationsFactory>(); _parameterInfosFromParamsArrayFactory = mock <IParameterInfosFromParamsArrayFactory>(); SuppliedArgumentSpecificationsFactory = mock <ISuppliedArgumentSpecificationsFactory>(); _arrayContentsArgumentSpecificationFactory = mock <IArrayContentsArgumentSpecificationFactory>(); _defaultChecker = mock <IDefaultChecker>(); _argumentSpecificationsToSupply = new Queue <IArgumentSpecification>(); _suppliedArgumentSpecifications = mock <ISuppliedArgumentSpecifications>(); _suppliedArgumentSpecifications.stub(x => x.Dequeue()).Return(null).WhenCalled(x => x.ReturnValue = _argumentSpecificationsToSupply.Dequeue()); _suppliedArgumentSpecifications.stub(x => x.DequeueRemaining()).Return(null).WhenCalled(x => x.ReturnValue = _argumentSpecificationsToSupply); }
public IEnumerable <IArgumentSpecification> Create(object arrayArgument, IEnumerable <IParameterInfo> parameterInfos, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { var arrayMembers = (IEnumerable)arrayArgument; var index = 0; var result = new List <IArgumentSpecification>(); foreach (var member in arrayMembers) { result.Add(_nonParamsArgumentSpecificationFactory.Create(member, parameterInfos.ElementAt(index), suppliedArgumentSpecifications)); index++; } return(result); }
private IEnumerable <IArgumentSpecification> UnwrapParamsArguments(IEnumerable <object?> args, Type paramsElementType, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { var fakeParameterInfo = new ParameterInfoFromType(paramsElementType); var result = new List <IArgumentSpecification>(); foreach (var arg in args) { try { result.Add(CreateSpecFromNonParamsArg(arg, fakeParameterInfo, suppliedArgumentSpecifications)); } catch (AmbiguousArgumentsException ex) { ex.Data[AmbiguousArgumentsException.NonReportedResolvedSpecificationsKey] = result; throw; } } return(result); }
public override void Because() { _result = sut.Create(_argumentSpecifications); }
private IArgumentSpecification CreateSpecFromNonParamsArg(object?argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType)) { return(suppliedArgumentSpecifications.Dequeue()); } bool isAmbiguousSpecificationPresent = suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType); if (!isAmbiguousSpecificationPresent || parameterInfo.IsOptional || parameterInfo.IsOut) { return(new ArgumentSpecification(parameterInfo.ParameterType, new EqualsArgumentMatcher(argument))); } throw new AmbiguousArgumentsException(); }
private IArgumentSpecification CreateSpecFromParamsArg(object?argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { // Next specification is for the whole params array. if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType)) { return(suppliedArgumentSpecifications.Dequeue()); } // Check whether the specification ambiguity could happen. bool isAmbiguousSpecificationPresent = suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType); if (isAmbiguousSpecificationPresent) { throw new AmbiguousArgumentsException(); } // User passed "null" as the params array value. if (argument == null) { return(new ArgumentSpecification(parameterInfo.ParameterType, new EqualsArgumentMatcher(null))); } // User specified arguments using the native params syntax. var arrayArg = argument as Array; if (arrayArg == null) { throw new SubstituteInternalException($"Expected to get array argument, but got argument of '{argument.GetType().FullName}' type."); } var arrayArgumentSpecifications = UnwrapParamsArguments(arrayArg.Cast <object?>(), parameterInfo.ParameterType.GetElementType() !, suppliedArgumentSpecifications); return(new ArgumentSpecification(parameterInfo.ParameterType, new ArrayContentsArgumentMatcher(arrayArgumentSpecifications))); }
public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType)) { return(suppliedArgumentSpecifications.Dequeue()); } bool isAmbiguousSpecificationPresent = suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType); if (!isAmbiguousSpecificationPresent || parameterInfo.IsOptional || parameterInfo.IsOut) { return(_argumentEqualsSpecificationFactory.Create(argument, parameterInfo.ParameterType)); } throw new AmbiguousArgumentsException(); }
public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { if (_defaultChecker.IsDefault(argument, parameterInfo.ParameterType)) { if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType)) { var argumentSpecification = suppliedArgumentSpecifications.Dequeue(); if (suppliedArgumentSpecifications.DequeueRemaining().Count() == 0) { return(argumentSpecification); } } else if (!suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType)) { if (suppliedArgumentSpecifications.DequeueRemaining().Count() == 0) { return(_argumentEqualsSpecificationFactory.Create(argument, parameterInfo.ParameterType)); } } } else { var paramterInfosFromParamsArray = _parameterInfosFromParamsArrayFactory.Create(argument, parameterInfo.ParameterType); var suppliedArgumentSpecificationsFromParamsArray = _suppliedArgumentSpecificationsFactory.Create(suppliedArgumentSpecifications.DequeueRemaining()); var arrayArgumentSpecifications = _arrayArgumentSpecificationsFactory.Create(argument, paramterInfosFromParamsArray, suppliedArgumentSpecificationsFromParamsArray); return(_arrayContentsArgumentSpecificationFactory.Create(arrayArgumentSpecifications, parameterInfo.ParameterType)); } throw new AmbiguousArgumentsException(); }
public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { // Next specificaion is for the whole params array. if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType)) { return(suppliedArgumentSpecifications.Dequeue()); } // Check whether the specification ambiguity could happen. bool isAmbiguousSpecificationPresent = suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType); if (isAmbiguousSpecificationPresent) { throw new AmbiguousArgumentsException(suppliedArgumentSpecifications.AllSpecifications); } // User passed "null" as the params array value. if (argument == null) { return(_argumentEqualsSpecificationFactory.Create(null, parameterInfo.ParameterType)); } // User specified arguments using the native params syntax. var paramterInfosFromParamsArray = _parameterInfosFromParamsArrayFactory.Create(argument, parameterInfo.ParameterType); var arrayArgumentSpecifications = _arrayArgumentSpecificationsFactory.Create(argument, paramterInfosFromParamsArray, suppliedArgumentSpecifications); return(_arrayContentsArgumentSpecificationFactory.Create(arrayArgumentSpecifications, parameterInfo.ParameterType)); }
public IEnumerable <IArgumentSpecification> Create(object arrayArgument, IEnumerable <IParameterInfo> parameterInfos, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { var arrayMembers = (IEnumerable)arrayArgument; var index = 0; var result = new List <IArgumentSpecification>(); foreach (var member in arrayMembers) { try { result.Add(_nonParamsArgumentSpecificationFactory.Create(member, parameterInfos.ElementAt(index), suppliedArgumentSpecifications)); } catch (AmbiguousArgumentsException ex) { ex.Data[AmbiguousArgumentsException.NonReportedResolvedSpecificationsKey] = result; throw; } index++; } return(result); }
public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications) { if (parameterInfo.IsParams) { return(_paramsArgumentSpecificationFactory.Create(argument, parameterInfo, suppliedArgumentSpecifications)); } else { return(_nonParamsArgumentSpecificationFactory.Create(argument, parameterInfo, suppliedArgumentSpecifications)); } }