コード例 #1
0
        private void InitializeInterceptorBeingBuilt(LambdaExpression expression)
        {
            var callRule = new ExpressionCallRule(expression);

            Fake.AddRule(callRule);
            this.RuleBeingBuilt = callRule;
        }
コード例 #2
0
        private IEnumerable <ICompletedFakeObjectCall> OnMatching(LambdaExpression callSpecification)
        {
            var rule = new ExpressionCallRule(callSpecification);

            return
                (from call in this.Fake.RecordedCallsInScope
                 where rule.IsApplicableTo(call)
                 select call);
        }
コード例 #3
0
        private void OnWasNotCalled(LambdaExpression expression)
        {
            var rule = new ExpressionCallRule(expression);

            if (this.Fake.RecordedCalls.Any(x => rule.IsApplicableTo(x)))
            {
                throw new ExpectationException("Expected call not to be found but found it.");
            }
        }
コード例 #4
0
        private void OnWasCalled(LambdaExpression expression, Expression <Func <int, bool> > repeatValidation)
        {
            var rule   = new ExpressionCallRule(expression);
            var repeat = this.Fake.RecordedCallsInScope.Where(x => rule.IsApplicableTo(x)).Count();

            if (!repeatValidation.Compile().Invoke(repeat))
            {
                ThrowWhenNotCalledWithCorrectRepeat(rule, repeatValidation, repeat);
            }
        }
コード例 #5
0
        protected virtual void OnSetUp()
        {
            this.fakeObject  = new FakeObject();
            this.rule        = ExpressionHelper.CreateRule <IFoo>(x => x.Bar());
            this.ruleFactory = x =>
            {
                this.argumentToRuleFactory = x;
                return(this.rule);
            };

            this.configurationFactory = A.Fake <IConfigurationFactory>();
        }
コード例 #6
0
        protected virtual void OnSetUp()
        {
            this.fake = new FakeObject(typeof(IFoo));
            this.expressionRuleFactory = x =>
            {
                var result = new ExpressionCallRule(new ExpressionCallMatcher(x, A.Fake <ArgumentValidatorFactory>(), A.Fake <MethodInfoManager>()));
                this.ruleProducedByFactory = result;
                return(result);
            };

            this.configuration = this.CreateConfiguration();
        }
コード例 #7
0
        private void OnWasCalled(LambdaExpression expression)
        {
            var rule = new ExpressionCallRule(expression);

            if (!this.Fake.RecordedCalls.Any(x => rule.IsApplicableTo(x)))
            {
                var writer = new StringWriter(CultureInfo.InvariantCulture);
                this.Fake.RecordedCalls.WriteCalls(writer);

                var messageTemplate = "Expected to find call {0} but could not find it among the calls: \r\n {1}";
                throw new ExpectationException(messageTemplate.FormatInvariant(rule.ToString(), writer.ToString()));
            }
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        protected virtual void OnSetUp()
        {
            this.fakeObject  = new FakeObject();
            this.rule        = ExpressionHelper.CreateRule <IFoo>(x => x.Bar());
            this.ruleFactory = x =>
            {
                this.argumentToRuleFactory = x;
                return(this.rule);
            };

            this.configurationFactory = A.Fake <IConfigurationFactory>();

            this.proxyGenerator = A.Fake <IProxyGenerator>();
            A.CallTo(() => this.proxyGenerator.MemberCanBeIntercepted(A <MemberInfo> .Ignored)).Returns(true);
        }
コード例 #10
0
        protected virtual void OnSetup()
        {
            this.fakeObject  = A.Fake <FakeManager>();
            this.rule        = ExpressionHelper.CreateRule <IFoo>(x => x.Bar());
            this.ruleFactory = x =>
            {
                this.argumentToRuleFactory = x;
                return(this.rule);
            };

            this.configurationFactory = A.Fake <IConfigurationFactory>();

            this.expressionParser = A.Fake <ICallExpressionParser>();

            this.interceptionAsserter = A.Fake <IInterceptionAsserter>();
        }
コード例 #11
0
        public void CallTo_with_function_call_should_add_rule_to_fake_object()
        {
            // Arrange
            var foo = A.Fake <IFoo>();

            ExpressionCallRule ruleFromFactory = null;
            var ruleFactory = ServiceLocator.Current.Resolve <ExpressionCallRule.Factory>();

            this.StubResolve <ExpressionCallRule.Factory>(x =>
            {
                ruleFromFactory = ruleFactory.Invoke(x);
                return(ruleFromFactory);
            });

            // Act
            A.CallTo(() => foo.Baz());

            // Assert
            Assert.That(Fake.GetFakeObject(foo).Rules, Has.Some.EqualTo(ruleFromFactory));
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        public void CallTo_with_function_call_should_call_configuration_factory_with_call_rule_from_factory()
        {
            // Arrange
            var foo = A.Fake <IFoo>();

            ExpressionCallRule ruleFromFactory = null;
            var ruleFactory = ServiceLocator.Current.Resolve <ExpressionCallRule.Factory>();

            this.StubResolve <ExpressionCallRule.Factory>(x =>
            {
                ruleFromFactory = ruleFactory.Invoke(x);
                return(ruleFromFactory);
            });

            // Act
            A.CallTo(() => foo.Baz());

            // Assert
            Assert.That(ruleFromFactory, Is.Not.Null);
            Fake.Assert(this.configurationFactory)
            .WasCalled(x => x.CreateConfiguration <int>(A <FakeObject> .Ignored, ruleFromFactory));
        }
コード例 #14
0
        private void OnSetUp()
        {
            this.configurationFactory = A.Fake <IConfigurationFactory>();
            this.expressionParser     = A.Fake <IExpressionParser>();
            this.proxyGenerator       = A.Fake <IProxyGenerator>();
            A.CallTo(() => this.proxyGenerator.MemberCanBeIntercepted(A <MemberInfo> .Ignored)).Returns(true);

            this.callSpecification = ExpressionHelper.CreateExpression <IFoo>(x => x.Bar());

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

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

            this.fakeObjectReturnedFromParser = new FakeObject();

            A.CallTo(() => this.expressionParser.GetFakeObjectCallIsMadeOn(A <LambdaExpression> .Ignored)).Returns(x => this.fakeObjectReturnedFromParser);

            this.configurationManager = this.CreateManager();
        }
コード例 #15
0
        private static void ThrowWhenNotCalledWithCorrectRepeat(ExpressionCallRule rule, Expression <Func <int, bool> > repeatValidation, int repeat)
        {
            var messageTemplate = ExceptionMessages.WasCalledWrongNumberOfTimes.FormatInvariant(rule.ToString(), repeatValidation.ToString(), repeat);

            throw new ExpectationException(messageTemplate);
        }
コード例 #16
0
 public void Constructor_should_work_with_expression_of_property()
 {
     var rule = new ExpressionCallRule((Expression <Func <IFoo, int> >)(x => x.SomeProperty));
 }