コード例 #1
0
        public void CheckNextCall(
            FakeManager fakeManager,
            Func <IFakeObjectCall, bool> callPredicate,
            Action <IOutputWriter> callDescriber,
            CallCountConstraint callCountConstraint)
        {
            Guard.AgainstNull(fakeManager, nameof(fakeManager));
            Guard.AgainstNull(callPredicate, nameof(callPredicate));
            Guard.AgainstNull(callDescriber, nameof(callDescriber));
            Guard.AgainstNull(callCountConstraint, nameof(callCountConstraint));
            this.fakeManagers.Add(fakeManager);
            this.assertedCalls.Add(
                new AssertedCall {
                CallDescriber = callDescriber, MatchingCountDescription = callCountConstraint.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 (callCountConstraint.Matches(matchedCallCount))
                {
                    return;
                }

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

            if (!callCountConstraint.Matches(matchedCallCount))
            {
                this.ThrowExceptionWhenAssertionFailed(allCalls);
            }
        }
コード例 #2
0
        public virtual void AssertWasCalled(
            Func<ICompletedFakeObjectCall, bool> callPredicate, Action<IOutputWriter> callDescriber, CallCountConstraint callCountConstraint)
        {
            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 (!callCountConstraint.Matches(matchedCallCount))
            {
                var description = this.outputWriterFactory(new StringBuilder());
                callDescriber.Invoke(description);

                var message = this.CreateExceptionMessage(this.calls.Where(IsBeforeAssertionStart), description.Builder.ToString(), callCountConstraint.ToString(), matchedCallCount);
                throw new ExpectationException(message);
            }
        }
コード例 #3
0
        public virtual void AssertWasCalled(
            Func <ICompletedFakeObjectCall, bool> callPredicate, Action <IOutputWriter> callDescriber, CallCountConstraint callCountConstraint)
        {
            bool IsBeforeAssertionStart(CompletedFakeObjectCall call) => call.SequenceNumber <= this.lastSequenceNumber;

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

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

                var message = this.CreateExceptionMessage(this.calls.Where(IsBeforeAssertionStart), description.Builder.ToString(), callCountConstraint.ToString(), matchedCallCount);
                throw new ExpectationException(message);
            }
        }