/// <summary> /// Initializes a new instance of the <see cref="ExpressionCallMatcher"/> class. /// </summary> /// <param name="callSpecification">The call specification.</param> /// <param name="validatorFactory">The validator factory.</param> public ExpressionCallMatcher(LambdaExpression callSpecification, ArgumentValidatorFactory validatorFactory, MethodInfoManager methodInfoManager) { this.methodInfoManager = methodInfoManager; this.Method = GetMethodInfo(callSpecification); this.argumentValidators = GetArgumentValidators(callSpecification, validatorFactory).ToArray(); this.argumentsPredicate = this.ArgumentsMatchesArgumentValidators; }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionCallMatcher" /> class. /// </summary> /// <param name="parsedExpression">The parsed call specification.</param> /// <param name="constraintFactory">The constraint factory.</param> /// <param name="methodInfoManager">The method info manager to use.</param> public ExpressionCallMatcher(ParsedCallExpression parsedExpression, ExpressionArgumentConstraintFactory constraintFactory, MethodInfoManager methodInfoManager) { this.methodInfoManager = methodInfoManager; this.Method = parsedExpression.CalledMethod; this.argumentConstraints = GetArgumentConstraints(parsedExpression.ArgumentsExpressions, constraintFactory).ToArray(); this.argumentsPredicate = this.ArgumentsMatchesArgumentConstraints; }
public void SetUp() { this.validatorFactory = A.Fake <ArgumentValidatorFactory>(); var validator = A.Fake <IArgumentValidator>(); Configure.Fake(validator).CallsTo(x => x.IsValid(A <object> .Ignored)).Returns(true); Configure.Fake(validatorFactory).CallsTo(x => x.GetArgumentValidator(A <Expression> .Ignored)).Returns(validator); this.methodInfoManager = A.Fake <MethodInfoManager>(); }
public void SetUp() { this.validatorFactory = A.Fake <ArgumentValidatorFactory>(); var validator = A.Fake <IArgumentValidator>(); A.CallTo(() => validator.IsValid(A <object> .Ignored)).Returns(true); A.CallTo(() => validatorFactory.GetArgumentValidator(A <Expression> .Ignored)).Returns(validator); this.methodInfoManager = A.Fake <MethodInfoManager>(); }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionCallMatcher" /> class. /// </summary> /// <param name="parsedExpression">The parsed call specification.</param> /// <param name="constraintFactory">The constraint factory.</param> /// <param name="methodInfoManager">The method info manager to use.</param> /// <param name="outputWriterFactory">The output writer factory to use.</param> public ExpressionCallMatcher(ParsedCallExpression parsedExpression, ExpressionArgumentConstraintFactory constraintFactory, MethodInfoManager methodInfoManager, StringBuilderOutputWriter.Factory outputWriterFactory) { this.methodInfoManager = methodInfoManager; this.outputWriterFactory = outputWriterFactory; this.Method = parsedExpression.CalledMethod; this.argumentConstraints = GetArgumentConstraints(parsedExpression.ArgumentsExpressions, constraintFactory).ToArray(); this.argumentsPredicate = this.ArgumentsMatchesArgumentConstraints; }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionCallMatcher" /> class. /// </summary> /// <param name="callSpecification">The call specification.</param> /// <param name="constraintFactory">The constraint factory.</param> /// <param name="methodInfoManager">The method info manager to use.</param> /// <param name="callExpressionParser">A parser to use to parse call expressions.</param> public ExpressionCallMatcher(LambdaExpression callSpecification, ExpressionArgumentConstraintFactory constraintFactory, MethodInfoManager methodInfoManager, ICallExpressionParser callExpressionParser) { this.methodInfoManager = methodInfoManager; var parsedExpression = callExpressionParser.Parse(callSpecification); this.Method = parsedExpression.CalledMethod; this.argumentConstraints = GetArgumentConstraints(parsedExpression.ArgumentsExpressions, constraintFactory).ToArray(); this.argumentsPredicate = this.ArgumentsMatchesArgumentConstraints; }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionCallMatcher"/> class. /// </summary> /// <param name="callSpecification">The call specification.</param> /// <param name="validatorFactory">The validator factory.</param> public ExpressionCallMatcher(LambdaExpression callSpecification, ArgumentValidatorFactory validatorFactory, MethodInfoManager methodInfoManager) { Guard.IsNotNull(callSpecification, "callSpecification"); Guard.IsNotNull(validatorFactory, "validatorFactory"); Guard.IsNotNull(methodInfoManager, "methodInfoManager"); this.methodInfoManager = methodInfoManager; this.Method = GetMethodInfo(callSpecification); this.argumentValidators = GetArgumentValidators(callSpecification, validatorFactory).ToArray(); }
public void SetUp() { this.constraintFactory = A.Fake <ExpressionArgumentConstraintFactory>(); var validator = A.Fake <IArgumentConstraint>(); A.CallTo(() => validator.IsValid(A <object> ._)).Returns(true); A.CallTo(() => this.constraintFactory.GetArgumentConstraint(A <ParsedArgumentExpression> ._)).Returns(validator); this.methodInfoManager = A.Fake <MethodInfoManager>(); this.parser = new CallExpressionParser(); }
/// <summary> /// Initializes a new instance of the <see cref="ExpressionCallMatcher" /> class. /// </summary> /// <param name="parsedExpression">The parsed call specification.</param> /// <param name="constraintFactory">The constraint factory.</param> /// <param name="methodInfoManager">The method info manager to use.</param> public ExpressionCallMatcher(ParsedCallExpression parsedExpression, ExpressionArgumentConstraintFactory constraintFactory, MethodInfoManager methodInfoManager) { this.methodInfoManager = methodInfoManager; this.Method = parsedExpression.CalledMethod; var constraints = new IArgumentConstraint[parsedExpression.ArgumentsExpressions.Length]; for (var i = 0; i < constraints.Length; i++) { constraints[i] = constraintFactory.GetArgumentConstraint(parsedExpression.ArgumentsExpressions[i]); } this.argumentConstraints = constraints; this.argumentsPredicate = this.ArgumentsMatchesArgumentConstraints; }
public ExpressionCallMatcherTests() { this.constraintFactory = A.Fake <ExpressionArgumentConstraintFactory>(); var validator = A.Fake <IArgumentConstraint>(); A.CallTo(() => validator.IsValid(A <object> ._)).Returns(true); A.CallTo(() => this.constraintFactory.GetArgumentConstraint(A <ParsedArgumentExpression> ._)).Returns(validator); this.methodInfoManager = A.Fake <MethodInfoManager>(); this.parser = new CallExpressionParser(); this.outputWriterFactory = () => new StringBuilderOutputWriter( new ArgumentValueFormatter(Enumerable.Empty <IArgumentValueFormatter>())); }
public void SetUp() { this.methodInfoManager = new MethodInfoManager(); this.validator = new CastleDynamicProxyInterceptionValidator(this.methodInfoManager); }
public RecordedCallRule(MethodInfoManager methodInfoManager) { this.methodInfoManager = methodInfoManager; }
public static void RegisterDependencies(IServiceRegistrar registrar) { var bootstrapper = BootstrapperLocator.FindBootstrapper(); var typeCatalogue = new TypeCatalogue(); var assemblyFilesNames = bootstrapper.GetAssemblyFileNamesToScanForExtensions() ?? throw new InvalidOperationException(ExceptionMessages.GetAssemblyFileNamesToScanForExtensionsShouldntReturnNull); typeCatalogue.Load(assemblyFilesNames); var typeCatalogueInstanceProvider = new TypeCatalogueInstanceProvider(typeCatalogue); var argumentValueFormatters = typeCatalogueInstanceProvider.InstantiateAllOfType <IArgumentValueFormatter>(); var dummyFactories = typeCatalogueInstanceProvider.InstantiateAllOfType <IDummyFactory>(); var fakeOptionsBuilders = typeCatalogueInstanceProvider.InstantiateAllOfType <IFakeOptionsBuilder>(); var implicitOptionsBuilderCatalogue = new ImplicitOptionsBuilderCatalogue(fakeOptionsBuilders); var methodInfoManager = new MethodInfoManager(); var argumentConstraintTrap = new ArgumentConstraintTrap(); var expressionArgumentConstraintFactory = new ExpressionArgumentConstraintFactory(argumentConstraintTrap); var fakeManagerAccessor = new DefaultFakeManagerAccessor(); var fakeObjectCreator = new FakeObjectCreator( FakeCallProcessorProviderFactory, new CastleDynamicProxyInterceptionValidator(methodInfoManager), new DelegateProxyInterceptionValidator()); var callExpressionParser = new CallExpressionParser(); var interceptionAsserter = new DefaultInterceptionAsserter(fakeObjectCreator); var argumentValueFormatter = new ArgumentValueFormatter(argumentValueFormatters); var fakeObjectCallFormatter = new DefaultFakeObjectCallFormatter(argumentValueFormatter, fakeManagerAccessor); var callWriter = new CallWriter(fakeObjectCallFormatter, new FakeCallEqualityComparer()); var configurationFactory = new ConfigurationFactory(RuleBuilderFactory); registrar.Register <IExpressionCallMatcherFactory>(new ExpressionCallMatcherFactory(expressionArgumentConstraintFactory, methodInfoManager)); registrar.Register(expressionArgumentConstraintFactory); registrar.Register <FakeAndDummyManager>( new FakeAndDummyManager( new DummyValueResolver(new DynamicDummyFactory(dummyFactories), fakeObjectCreator), fakeObjectCreator, implicitOptionsBuilderCatalogue)); registrar.Register <IArgumentConstraintManagerFactory>(new ArgumentConstraintManagerFactory()); registrar.Register(new EventHandlerArgumentProviderMap()); registrar.Register <SequentialCallContext.Factory>(SequentialCallContextFactory); registrar.Register <IStartConfigurationFactory>( new StartConfigurationFactory(ExpressionCallRuleFactory, configurationFactory, callExpressionParser, interceptionAsserter)); registrar.Register <IFakeConfigurationManager>( new FakeConfigurationManager(configurationFactory, ExpressionCallRuleFactory, callExpressionParser, interceptionAsserter)); registrar.Register <IFakeManagerAccessor>(fakeManagerAccessor); registrar.Register <ICallExpressionParser>(callExpressionParser); registrar.Register((StringBuilderOutputWriter.Factory)StringBuilderOutputWriterFactory); registrar.Register <IFakeObjectCallFormatter>(fakeObjectCallFormatter); StringBuilderOutputWriter StringBuilderOutputWriterFactory() => new StringBuilderOutputWriter(argumentValueFormatter !); FakeManager FakeManagerFactory(Type fakeObjectType, object proxy, string?name) => new FakeManager(fakeObjectType, proxy, name); IFakeCallProcessorProvider FakeCallProcessorProviderFactory(Type typeOfFake, IProxyOptions proxyOptions) => new FakeManagerProvider(FakeManagerFactory, fakeManagerAccessor, typeOfFake, proxyOptions); ExpressionCallRule ExpressionCallRuleFactory(ParsedCallExpression callSpecification) => new ExpressionCallRule(new ExpressionCallMatcher(callSpecification, expressionArgumentConstraintFactory, methodInfoManager)); IFakeAsserter FakeAsserterFactory(IEnumerable <CompletedFakeObjectCall> calls, int lastSequenceNumber) => new FakeAsserter(calls, lastSequenceNumber, callWriter, StringBuilderOutputWriterFactory); SequentialCallContext SequentialCallContextFactory() => new SequentialCallContext(callWriter, StringBuilderOutputWriterFactory); RuleBuilder RuleBuilderFactory(BuildableCallRule rule, FakeManager fake) => new RuleBuilder(rule, fake, FakeAsserterFactory); }
public ExpressionCallMatcherFactory(ExpressionArgumentConstraintFactory expressionArgumentConstraintFactory, MethodInfoManager methodInfoManager) { this.expressionArgumentConstraintFactory = expressionArgumentConstraintFactory; this.methodInfoManager = methodInfoManager; }
public CastleDynamicProxyInterceptionValidator(MethodInfoManager methodInfoManager) { this.methodInfoManager = methodInfoManager; }
protected virtual void OnSetUp() { this.methodInfoManager = A.Fake <MethodInfoManager>(); }