public InterceptionTestCase(Expression <Action> expression)
            {
                var parser = new CallExpressionParser();
                var parsed = parser.Parse(expression);

                this.Method = parsed.CalledMethod;
                this.Target = parsed.CallTarget;
            }
Пример #2
0
        private void OnSetup()
        {
            this.configurationFactory = A.Fake <IConfigurationFactory>();
            this.callExpressionParser = new CallExpressionParser();
            this.interceptionAsserter = A.Fake <IInterceptionAsserter>();

            this.ruleFactory = x => null;

            this.configurationManager = this.CreateManager();
        }
Пример #3
0
            protected static T Create <T>(Expression <Action> expression) where T : InterceptionTestCase, new()
            {
                var parser = new CallExpressionParser();
                var parsed = parser.Parse(expression);

                return(new T()
                {
                    Method = parsed.CalledMethod,
                    Target = parsed.CallTarget
                });
            }
Пример #4
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();
        }
        public FakeConfigurationManagerTests()
        {
            this.configurationFactory = A.Fake <IConfigurationFactory>();
            this.callExpressionParser = new CallExpressionParser();
            this.interceptionAsserter = A.Fake <IInterceptionAsserter>();

            ExpressionCallRule.Factory ruleFactory = A.Dummy <ExpressionCallRule.Factory>();

            this.configurationManager = new FakeConfigurationManager(
                this.configurationFactory,
                ruleFactory,
                this.callExpressionParser,
                this.interceptionAsserter);
        }
        private void OnSetup()
        {
            this.configurationFactory = A.Fake <IConfigurationFactory>();
            this.callExpressionParser = new CallExpressionParser();
            this.interceptionAsserter = A.Fake <IInterceptionAsserter>();

            Expression <Action <IFoo> > dummyExpression = x => x.Bar();
            var parsedDummyExpression = this.callExpressionParser.Parse(dummyExpression);

            this.ruleReturnedFromFactory = ServiceLocator.Current.Resolve <ExpressionCallRule.Factory>().Invoke(parsedDummyExpression);
            this.ruleFactory             = x => this.ruleReturnedFromFactory;

            this.configurationManager = this.CreateManager();
        }
        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>()));
        }
        private void OnSetup()
        {
            this.configurationFactory = A.Fake <IConfigurationFactory>();
            this.expressionParser     = A.Fake <IExpressionParser>();
            this.callExpressionParser = new CallExpressionParser();
            this.interceptionAsserter = A.Fake <IInterceptionAsserter>();

            Expression <Action <IFoo> > dummyExpression = x => x.Bar();

            this.ruleReturnedFromFactory = ServiceLocator.Current.Resolve <ExpressionCallRule.Factory>().Invoke(dummyExpression);
            this.ruleFactory             = x =>
            {
                return(this.ruleReturnedFromFactory);
            };

            this.fakeObjectReturnedFromParser = A.Fake <FakeManager>(o => o.CallsBaseMethods());

            A.CallTo(() => this.expressionParser.GetFakeManagerCallIsMadeOn(A <LambdaExpression> ._)).ReturnsLazily(x => this.fakeObjectReturnedFromParser);

            this.configurationManager = this.CreateManager();
        }
 public void Setup()
 {
     this.parser = new CallExpressionParser();
 }
Пример #10
0
        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);
        }
Пример #11
0
 public CallExpressionParserTests()
 {
     this.parser = new CallExpressionParser();
 }