Ejemplo n.º 1
0
        public void CheckNextCall(FakeManager fakeManager, Func <IFakeObjectCall, bool> callPredicate, string callDescription, Repeated repeatConstraint)
        {
            Guard.AgainstNull(fakeManager, "fakeManager");
            Guard.AgainstNull(callPredicate, "callPredicate");
            Guard.AgainstNull(callDescription, "callDescription");
            Guard.AgainstNull(repeatConstraint, "repeatConstraint");
            this.fakeManagers.Add(fakeManager);
            this.assertedCalls.Add(new AssertedCall {
                CallDescription = callDescription, RepeatDescription = repeatConstraint.ToString()
            });
            var allCalls = this.fakeManagers.SelectMany(f => f.GetRecordedCalls().Cast <IFakeObjectCall>()).OrderBy(c => c.SequenceNumber).ToList();

            int matchedCallCount = 0;

            foreach (var currentCall in allCalls.SkipWhile(c => c.SequenceNumber <= this.currentSequenceNumber))
            {
                if (repeatConstraint.Matches(matchedCallCount))
                {
                    return;
                }

                if (callPredicate(currentCall))
                {
                    matchedCallCount++;
                    this.currentSequenceNumber = currentCall.SequenceNumber;
                }
            }

            if (!repeatConstraint.Matches(matchedCallCount))
            {
                ThrowExceptionWhenAssertionFailed(this.assertedCalls, this.callWriter, allCalls);
            }
        }
Ejemplo n.º 2
0
        public void CheckNextCall(
            FakeManager fakeManager,
            Func <IFakeObjectCall, bool> callPredicate,
            Action <IOutputWriter> callDescriber,
            Repeated repeatConstraint)
        {
            Guard.AgainstNull(fakeManager, nameof(fakeManager));
            Guard.AgainstNull(callPredicate, nameof(callPredicate));
            Guard.AgainstNull(callDescriber, nameof(callDescriber));
            Guard.AgainstNull(repeatConstraint, nameof(repeatConstraint));
            this.fakeManagers.Add(fakeManager);
            this.assertedCalls.Add(
                new AssertedCall {
                CallDescriber = callDescriber, 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))
            {
                this.ThrowExceptionWhenAssertionFailed(allCalls);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public virtual void AssertWasCalled(
            Func <ICompletedFakeObjectCall, bool> callPredicate, Action <IOutputWriter> callDescriber, Repeated repeatConstraint)
        {
            var lastCall           = this.calls.LastOrDefault();
            int lastSequenceNumber = lastCall != null?SequenceNumberManager.GetSequenceNumber(lastCall) : -1;

            bool IsBeforeAssertionStart(ICompletedFakeObjectCall call) => SequenceNumberManager.GetSequenceNumber(call) <= lastSequenceNumber;

            var matchedCallCount = this.calls.Count(c => IsBeforeAssertionStart(c) && callPredicate(c));

            if (!repeatConstraint.Matches(matchedCallCount))
            {
                var description = this.outputWriterFactory(new StringBuilder());
                callDescriber.Invoke(description);

                var message = this.CreateExceptionMessage(this.calls.Where(IsBeforeAssertionStart), description.Builder.ToString(), repeatConstraint.ToString(), matchedCallCount);
                throw new ExpectationException(message);
            }
        }
Ejemplo n.º 5
0
        public IAfterMustHaveHappenedConfiguration MustHaveHappened(Repeated repeatConstraint)
        {
            Guard.AgainstNull(repeatConstraint, "repeatConstraint");

            this.manager.RemoveRule(this.RuleBeingBuilt);
            var asserter = this.asserterFactory.Invoke(this.Calls.Cast <IFakeObjectCall>());

            var description = new StringBuilderOutputWriter();

            this.RuleBeingBuilt.WriteDescriptionOfValidCall(description);

            asserter.AssertWasCalled(this.Matcher.Matches, description.Builder.ToString(), repeatConstraint.Matches, repeatConstraint.ToString());

            return(new AfterMustHaveHappenedConfiguration(this.manager, this.Matcher, description.Builder.ToString(), repeatConstraint));
        }
Ejemplo n.º 6
0
        public void MustHaveHappened(Repeated repeatConstraint)
        {
            this.manager.RemoveRule(this.RuleBeingBuilt);
            var asserter = this.asserterFactory.Invoke(this.Calls.Cast <IFakeObjectCall>());

            var description = new StringBuilderOutputWriter();

            this.RuleBeingBuilt.WriteDescriptionOfValidCall(description);

            asserter.AssertWasCalled(this.Matcher.Matches, description.Builder.ToString(), repeatConstraint.Matches, repeatConstraint.ToString());
        }
Ejemplo n.º 7
0
        public UnorderedCallAssertion MustHaveHappened(Repeated repeatConstraint)
        {
            Guard.AgainstNull(repeatConstraint, nameof(repeatConstraint));

            var asserter = this.asserterFactory.Invoke(this.Calls);

            var description = new StringBuilderOutputWriter();

            this.RuleBeingBuilt.WriteDescriptionOfValidCall(description);

            asserter.AssertWasCalled(this.Matcher.Matches, description.Builder.ToString(), repeatConstraint.Matches, repeatConstraint.ToString());

            return(new UnorderedCallAssertion(this.manager, this.Matcher, description.Builder.ToString(), repeatConstraint));
        }
Ejemplo n.º 8
0
        public void MustHaveHappened(Repeated repeatConstraint)
        {
            this.fakeObject.RemoveRule(this.RuleBeingBuilt);
            var asserter = this.asserterFactory.Invoke(this.Calls.Cast <IFakeObjectCall>());

            asserter.AssertWasCalled(this.Matcher.Matches, this.RuleBeingBuilt.ToString(), repeatConstraint.Matches, repeatConstraint.ToString());
        }