private void InitializeInterceptorBeingBuilt(LambdaExpression expression) { var callRule = new ExpressionCallRule(expression); Fake.AddRule(callRule); this.RuleBeingBuilt = callRule; }
private IEnumerable <ICompletedFakeObjectCall> OnMatching(LambdaExpression callSpecification) { var rule = new ExpressionCallRule(callSpecification); return (from call in this.Fake.RecordedCallsInScope where rule.IsApplicableTo(call) select call); }
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."); } }
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); } }
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>(); }
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(); }
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())); } }
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(); }
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); }
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>(); }
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)); }
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 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)); }
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(); }
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); }
public void Constructor_should_work_with_expression_of_property() { var rule = new ExpressionCallRule((Expression <Func <IFoo, int> >)(x => x.SomeProperty)); }