private static void AddRecordingRuleWhenRecorderIsSpecified(ISelfInitializingFakeRecorder recorder, FakeManager fake, WrappedObjectRule wrapperRule) { if (recorder != null) { fake.AddRuleFirst(new SelfInitializationRule(wrapperRule, recorder)); } }
public void SetUp() { this.fake = Fake.GetFakeManager(A.Fake<IFoo>()); this.fakeAsserter = A.Fake<IFakeAsserter>(); this.matcher = A.Fake<ExpressionCallMatcher>(x => x.WithArgumentsForConstructor(() => new ExpressionCallMatcher( ExpressionHelper.CreateExpression<IFoo>(_ => Console.WriteLine("")), ServiceLocator.Current.Resolve<ArgumentConstraintFactory>(), ServiceLocator.Current.Resolve<MethodInfoManager>()))); this.callMatcherFactory = A.Fake<IExpressionCallMatcherFactory>(); A.CallTo(() => this.callMatcherFactory.CreateCallMathcer(A<LambdaExpression>.Ignored)).ReturnsLazily(x => this.matcher); this.fakeAsserterFactory = x => { this.argumentToFakeAsserterFactory = x; return this.fakeAsserter; }; this.assertions = new FakeAssertions<IFoo>(this.fake, this.callMatcherFactory, this.fakeAsserterFactory); this.FakedFoo.Bar(); this.FakedFoo.Baz(); }
public void SetUp() { this.managerFactory = () => this.managerToReturnFromFactory; this.managerToReturnFromFactory = A.Fake<FakeManager>(); this.accessor = new DefaultFakeManagerAccessor(this.managerFactory); }
internal UnorderedCallAssertion(FakeManager fakeManager, ICallMatcher matcher, string callDescription, Repeated repeatConstraint) { this.fakeManager = fakeManager; this.matcher = matcher; this.callDescription = callDescription; this.repeatConstraint = repeatConstraint; }
public PropertyBehaviorRule(MethodInfo propertyGetterOrSetter, FakeManager fakeManager) { this.fakeManager = fakeManager; var property = GetProperty(propertyGetterOrSetter); this.propertySetter = property.GetSetMethod(); this.propertyGetter = property.GetGetMethod(true); }
public void Setup() { Fake.InitializeFixture(this); this.proxy = new object(); this.fakeManager = new FakeManager(typeof(int), this.proxy); A.CallTo(() => this.fakeManagerFactory(A<Type>._, this.proxy)).Returns(this.fakeManager); }
public void Setup() { Fake.InitializeFixture(this); this.fakeManager = A.Fake<FakeManager>(o => o.CallsBaseMethods()); this.builder = this.CreateBuilder(); }
public void TagProxy(object proxy, FakeManager manager) { Guard.AgainstNull(proxy, "proxy"); Guard.AgainstNull(manager, "manager"); var taggable = AsTaggable(proxy); taggable.Tag = manager; }
public void Should_set_proxy_and_event_raiser_to_manager() { // Arrange this.managerToReturnFromFactory = A.Fake<FakeManager>(); var proxy = A.Dummy<ITaggable>(); var eventRaiser = A.Dummy<ICallInterceptedEventRaiser>(); // Act this.accessor.AttachFakeManagerToProxy(typeof(object), proxy, eventRaiser); // Assert A.CallTo(() => this.managerToReturnFromFactory.AttachProxy(typeof(object), proxy, eventRaiser)).MustHaveHappened(); }
public void Setup() { this.fakedObject = A.Fake<IFoo>(); this.fakeObject = Fake.GetFakeManager(this.fakedObject); this.recordedRule = A.Fake<RecordedCallRule>(x => x.WithArgumentsForConstructor(() => new RecordedCallRule(A.Fake<MethodInfoManager>()))); this.callFormatter = A.Fake<IFakeObjectCallFormatter>(); this.asserter = A.Fake<IFakeAsserter>(); this.asserterFactory = x => { this.argumentUsedForAsserterFactory = x; return this.asserter; }; }
public FakeManagerProvider( FakeManager.Factory fakeManagerFactory, IFakeManagerAccessor fakeManagerAccessor, Type typeOfFake, IProxyOptions proxyOptions) { Guard.AgainstNull(fakeManagerFactory, "fakeManagerFactory"); Guard.AgainstNull(fakeManagerAccessor, "fakeManagerAccessor"); Guard.AgainstNull(typeOfFake, "typeOfFake"); Guard.AgainstNull(proxyOptions, "proxyOptions"); this.fakeManagerFactory = fakeManagerFactory; this.fakeManagerAccessor = fakeManagerAccessor; this.typeOfFake = typeOfFake; this.proxyOptions = proxyOptions; }
public FakeManagerProvider( FakeManager.Factory fakeManagerFactory, IFakeManagerAccessor fakeManagerAccessor, Type typeOfFake, IProxyOptions proxyOptions) { Guard.AgainstNull(fakeManagerFactory, nameof(fakeManagerFactory)); Guard.AgainstNull(fakeManagerAccessor, nameof(fakeManagerAccessor)); Guard.AgainstNull(typeOfFake, nameof(typeOfFake)); Guard.AgainstNull(proxyOptions, nameof(proxyOptions)); this.fakeManagerFactory = fakeManagerFactory; this.fakeManagerAccessor = fakeManagerAccessor; this.typeOfFake = typeOfFake; this.proxyOptions = proxyOptions; }
public void EnsureInitialized(object proxy) { Guard.AgainstNull(proxy, "proxy"); lock (this.initializedFakeManagerLock) { if (this.initializedFakeManager == null) { this.initializedFakeManager = this.fakeManagerFactory(this.typeOfFake, proxy); this.fakeManagerAccessor.TagProxy(proxy, this.initializedFakeManager); this.ApplyInitialConfiguration(proxy); } } }
public FakeManagerProvider( FakeManager.Factory fakeManagerFactory, IFakeManagerAccessor fakeManagerAccessor, IFakeObjectConfigurator fakeObjectConfigurator, Type typeOfFake, FakeOptions fakeOptions) { Guard.AgainstNull(fakeManagerFactory, "fakeManagerFactory"); Guard.AgainstNull(fakeManagerAccessor, "fakeManagerAccessor"); Guard.AgainstNull(fakeObjectConfigurator, "fakeObjectConfigurator"); Guard.AgainstNull(typeOfFake, "typeOfFake"); Guard.AgainstNull(fakeOptions, "fakeOptions"); this.fakeManagerFactory = fakeManagerFactory; this.fakeManagerAccessor = fakeManagerAccessor; this.fakeObjectConfigurator = fakeObjectConfigurator; this.typeOfFake = typeOfFake; this.fakeOptions = fakeOptions; }
public void CheckNextCall( FakeManager fakeManager, Func<IFakeObjectCall, bool> callPredicate, string callDescription, Repeated repeatConstraint) { Guard.AgainstNull(fakeManager, nameof(fakeManager)); Guard.AgainstNull(callPredicate, nameof(callPredicate)); Guard.AgainstNull(callDescription, nameof(callDescription)); Guard.AgainstNull(repeatConstraint, nameof(repeatConstraint)); this.fakeManagers.Add(fakeManager); this.assertedCalls.Add( new AssertedCall { CallDescription = callDescription, RepeatDescription = repeatConstraint.ToString() }); var allCalls = this.fakeManagers.SelectMany(f => f.GetRecordedCalls()).OrderBy(SequenceNumberManager.GetSequenceNumber).ToList(); int matchedCallCount = 0; foreach (var currentCall in allCalls.SkipWhile(c => SequenceNumberManager.GetSequenceNumber(c) <= this.currentSequenceNumber)) { if (repeatConstraint.Matches(matchedCallCount)) { return; } if (callPredicate(currentCall)) { matchedCallCount++; this.currentSequenceNumber = SequenceNumberManager.GetSequenceNumber(currentCall); } } if (!repeatConstraint.Matches(matchedCallCount)) { ThrowExceptionWhenAssertionFailed(this.assertedCalls, this.callWriter, allCalls); } }
protected abstract void OnAddInterceptedCall(FakeManager fakeObject, ICompletedFakeObjectCall call);
protected override void OnAddRule(FakeManager fakeObject, CallRuleMetadata rule) { List<CallRuleMetadata> rules; if (!this.rulesField.TryGetValue(fakeObject, out rules)) { rules = new List<CallRuleMetadata>(); this.rulesField.Add(fakeObject, rules); } rules.Add(rule); }
private static bool TryHandleEquals(IInterceptedFakeObjectCall fakeObjectCall, FakeManager fakeManager) { if (!IsSameMethod(fakeObjectCall.Method, EqualsMethod)) { return(false); } var argument = fakeObjectCall.Arguments[0]; if (argument is object) { var argumentFakeManager = Fake.TryGetFakeManager(argument); bool hasSameFakeManager = ReferenceEquals(argumentFakeManager, fakeManager); fakeObjectCall.SetReturnValue(hasSameFakeManager); } else { fakeObjectCall.SetReturnValue(false); } return(true); }
public EventRule(FakeManager fakeManager) { this.fakeManager = fakeManager; }
protected override void OnAddRule(FakeManager fakeObject, CallRuleMetadata rule) { }
/// <summary> /// Adds an intercepted call to the current scope. /// </summary> /// <param name="fakeManager">The fake object.</param> /// <param name="call">The call that is intercepted.</param> internal void AddInterceptedCall(FakeManager fakeManager, ICompletedFakeObjectCall call) { fakeManager.AllRecordedCalls.Add(call); this.OnAddInterceptedCall(fakeManager, call); }
private static bool TryHandleGetHashCode(IInterceptedFakeObjectCall fakeObjectCall, FakeManager fakeManager) { if (!fakeObjectCall.Method.HasSameBaseMethodAs(GetHashCodeMethod)) { return(false); } fakeObjectCall.SetReturnValue(fakeManager.GetHashCode()); return(true); }
private static bool TryHandleToString(IInterceptedFakeObjectCall fakeObjectCall, FakeManager fakeManager) { if (!fakeObjectCall.Method.HasSameBaseMethodAs(ToStringMethod)) { return(false); } fakeObjectCall.SetReturnValue(fakeManager.FakeObjectDisplayName); return(true); }
public PropertySetterRule(FakeManager fakeManager) { this.fakeManager = fakeManager; }
private static bool TryHandleToString(IInterceptedFakeObjectCall fakeObjectCall, FakeManager fakeManager) { if (!IsSameMethod(fakeObjectCall.Method, ToStringMethod)) { return(false); } fakeObjectCall.SetReturnValue("Faked " + fakeManager.FakeObjectType); return(true); }
internal abstract IEnumerable <ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject);
private static void TagProxy(object proxy, FakeManager manager) { var taggable = AsTaggable(proxy); taggable.Tag = manager; }
public DefaultFakeManagerAccessor(FakeManager.Factory managerFactory) { this.managerFactory = managerFactory; }
internal override IEnumerable <ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject) { List <ICompletedFakeObjectCall> calls; if (!this.recordedCallsGroupedByFakeManager.TryGetValue(fakeObject, out calls)) { calls = new List <ICompletedFakeObjectCall>(); } return(calls); }
private static bool TryHandleEquals(IInterceptedFakeObjectCall fakeObjectCall, FakeManager fakeManager) { if (!fakeObjectCall.Method.HasSameBaseMethodAs(EqualsMethod)) { return(false); } var argument = fakeObjectCall.Arguments[0]; if (argument is not null) { Fake.TryGetFakeManager(argument, out var argumentFakeManager); bool hasSameFakeManager = ReferenceEquals(argumentFakeManager, fakeManager); fakeObjectCall.SetReturnValue(hasSameFakeManager); } else { fakeObjectCall.SetReturnValue(false); } return(true); }
internal override IEnumerable <ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject) { return(fakeObject.AllRecordedCalls); }
public AutoFakePropertyRule(FakeManager fakeManager) { this.fakeManager = fakeManager; }
protected override void OnAddInterceptedCall(FakeManager fakeObject, ICompletedFakeObjectCall call) { }
internal void AddRuleLast(FakeManager fakeManager, CallRuleMetadata rule) { fakeManager.AllUserRules.AddLast(rule); this.OnAddRule(fakeManager, rule); }
internal override IEnumerable<ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject) { List<ICompletedFakeObjectCall> calls; if (!this.recordedCallsGroupedByFakeManager.TryGetValue(fakeObject, out calls)) { calls = new List<ICompletedFakeObjectCall>(); } return calls; }
public EventCallHandler(FakeManager fakeManager) { this.fakeManager = fakeManager; this.registeredEventHandlers = new Dictionary<object, Delegate>(); }
private static WrappedObjectRule CreateAndAddWrapperRule(object wrappedInstance, FakeManager fake) { var wrappingRule = new WrappedObjectRule(wrappedInstance); fake.AddRuleFirst(wrappingRule); return(wrappingRule); }
internal abstract IEnumerable<ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject);
protected abstract void OnAddRule(FakeManager fakeObject, CallRuleMetadata rule);
protected override void OnAddInterceptedCall(FakeManager fakeManager, ICompletedFakeObjectCall call) { this.parentScope.OnAddInterceptedCall(fakeManager, call); this.recordedCalls.AddLast(call); List<ICompletedFakeObjectCall> calls; if (!this.recordedCallsGroupedByFakeManager.TryGetValue(fakeManager, out calls)) { calls = new List<ICompletedFakeObjectCall>(); this.recordedCallsGroupedByFakeManager.Add(fakeManager, calls); } calls.Add(call); }
internal override IEnumerable<ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject) { return fakeObject.AllRecordedCalls; }
public ObjectMemberRule(FakeManager fakeManager) { this.fakeManager = fakeManager; }
/// <summary> /// Adds a fake object call to the current scope. /// </summary> /// <param name="fakeManager">The fake object.</param> /// <param name="rule">The rule to add.</param> internal void AddRuleFirst(FakeManager fakeManager, CallRuleMetadata rule) { fakeManager.AllUserRules.AddFirst(rule); this.OnAddRule(fakeManager, rule); }
public ObjectMemberRule(FakeManager fakeManager, IFakeManagerAccessor fakeManagerAccessor) { this.fakeManager = fakeManager; this.fakeManagerAccessor = fakeManagerAccessor; }