コード例 #1
0
        /// <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;
        }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
        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>();
        }
コード例 #4
0
        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>();
        }
コード例 #5
0
        /// <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;
        }
コード例 #6
0
        /// <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;
        }
コード例 #7
0
        /// <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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        /// <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;
        }
コード例 #10
0
        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>()));
        }
コード例 #11
0
        public void SetUp()
        {
            this.methodInfoManager = new MethodInfoManager();

            this.validator = new CastleDynamicProxyInterceptionValidator(this.methodInfoManager);
        }
コード例 #12
0
ファイル: RecordedCallRule.cs プロジェクト: drauch/FakeItEasy
 public RecordedCallRule(MethodInfoManager methodInfoManager)
 {
     this.methodInfoManager = methodInfoManager;
 }
コード例 #13
0
ファイル: RootModule.cs プロジェクト: alex-valchuk/FakeItEasy
        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);
        }
コード例 #14
0
ファイル: RootModule.cs プロジェクト: alex-valchuk/FakeItEasy
 public ExpressionCallMatcherFactory(ExpressionArgumentConstraintFactory expressionArgumentConstraintFactory, MethodInfoManager methodInfoManager)
 {
     this.expressionArgumentConstraintFactory = expressionArgumentConstraintFactory;
     this.methodInfoManager = methodInfoManager;
 }
コード例 #15
0
 public CastleDynamicProxyInterceptionValidator(MethodInfoManager methodInfoManager)
 {
     this.methodInfoManager = methodInfoManager;
 }
コード例 #16
0
 public CastleDynamicProxyInterceptionValidator(MethodInfoManager methodInfoManager)
 {
     this.methodInfoManager = methodInfoManager;
 }
コード例 #17
0
 protected virtual void OnSetUp()
 {
     this.methodInfoManager = A.Fake <MethodInfoManager>();
 }