Exemplo n.º 1
0
 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);
        }
Exemplo n.º 4
0
 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);
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 10
0
        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;
                };
        }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
0
        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);
                }
            }
        }
Exemplo n.º 14
0
        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;
        }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
 protected abstract void OnAddInterceptedCall(FakeManager fakeObject, ICompletedFakeObjectCall call);
Exemplo n.º 17
0
            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);
            }
Exemplo n.º 19
0
 private static void AddRecordingRuleWhenRecorderIsSpecified(ISelfInitializingFakeRecorder recorder, FakeManager fake, WrappedObjectRule wrapperRule)
 {
     if (recorder != null)
     {
         fake.AddRuleFirst(new SelfInitializationRule(wrapperRule, recorder));
     }
 }
Exemplo n.º 20
0
 public EventRule(FakeManager fakeManager)
 {
     this.fakeManager = fakeManager;
 }
Exemplo n.º 21
0
 protected override void OnAddRule(FakeManager fakeObject, CallRuleMetadata rule)
 {
 }
Exemplo n.º 22
0
 /// <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);
            }
Exemplo n.º 27
0
 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;
 }
Exemplo n.º 30
0
            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);
            }
Exemplo n.º 32
0
 internal override IEnumerable <ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject)
 {
     return(fakeObject.AllRecordedCalls);
 }
 public AutoFakePropertyRule(FakeManager fakeManager)
 {
     this.fakeManager = fakeManager;
 }
Exemplo n.º 34
0
 protected override void OnAddInterceptedCall(FakeManager fakeObject, ICompletedFakeObjectCall call)
 {
 }
Exemplo n.º 35
0
 protected abstract void OnAddInterceptedCall(FakeManager fakeObject, ICompletedFakeObjectCall call);
Exemplo n.º 36
0
 internal void AddRuleLast(FakeManager fakeManager, CallRuleMetadata rule)
 {
     fakeManager.AllUserRules.AddLast(rule);
     this.OnAddRule(fakeManager, rule);
 }
Exemplo n.º 37
0
            internal override IEnumerable<ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject)
            {
                List<ICompletedFakeObjectCall> calls;

                if (!this.recordedCallsGroupedByFakeManager.TryGetValue(fakeObject, out calls))
                {
                    calls = new List<ICompletedFakeObjectCall>();
                }

                return calls;
            }
Exemplo n.º 38
0
 public EventCallHandler(FakeManager fakeManager)
 {
     this.fakeManager = fakeManager;
     this.registeredEventHandlers = new Dictionary<object, Delegate>();
 }
Exemplo n.º 39
0
        private static WrappedObjectRule CreateAndAddWrapperRule(object wrappedInstance, FakeManager fake)
        {
            var wrappingRule = new WrappedObjectRule(wrappedInstance);

            fake.AddRuleFirst(wrappingRule);
            return(wrappingRule);
        }
Exemplo n.º 40
0
 internal abstract IEnumerable<ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject);
Exemplo n.º 41
0
 protected override void OnAddInterceptedCall(FakeManager fakeObject, ICompletedFakeObjectCall call)
 {
 }
Exemplo n.º 42
0
 protected abstract void OnAddRule(FakeManager fakeObject, CallRuleMetadata rule);
Exemplo n.º 43
0
 /// <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);
 }
Exemplo n.º 44
0
            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);
            }
 public PropertySetterRule(FakeManager fakeManager)
 {
     this.fakeManager = fakeManager;
 }
Exemplo n.º 46
0
 internal override IEnumerable<ICompletedFakeObjectCall> GetCallsWithinScope(FakeManager fakeObject)
 {
     return fakeObject.AllRecordedCalls;
 }
Exemplo n.º 47
0
        private static void TagProxy(object proxy, FakeManager manager)
        {
            var taggable = AsTaggable(proxy);

            taggable.Tag = manager;
        }
Exemplo n.º 48
0
 protected override void OnAddRule(FakeManager fakeObject, CallRuleMetadata rule)
 {
 }
Exemplo n.º 49
0
 public ObjectMemberRule(FakeManager fakeManager)
 {
     this.fakeManager = fakeManager;
 }
Exemplo n.º 50
0
 /// <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 AutoFakePropertyRule(FakeManager fakeManager)
 {
     this.fakeManager = fakeManager;
 }
 public ObjectMemberRule(FakeManager fakeManager, IFakeManagerAccessor fakeManagerAccessor)
 {
     this.fakeManager         = fakeManager;
     this.fakeManagerAccessor = fakeManagerAccessor;
 }
Exemplo n.º 53
0
 protected abstract void OnAddRule(FakeManager fakeObject, CallRuleMetadata rule);