コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #4
0
ファイル: FakeAsserter.cs プロジェクト: kassadube/FakeItEasy
        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);
            }
        }