Esempio n. 1
0
        /// <summary>
        /// This check the methods that were setup using the SetupResult.For()
        /// or LastCall.Repeat.Any() and that bypass the whole expectation model.
        /// </summary>
        public IExpectation GetRepeatableExpectation(object proxy, MethodInfo method, object[] args)
        {
            ProxyMethodPair pair = new ProxyMethodPair(proxy, method);

            if (repeatableMethods.ContainsKey(pair) == false)
            {
                return(null);
            }
            ExpectationsList list = repeatableMethods[pair];

            foreach (IExpectation expectation in list)
            {
                if (expectation.IsExpected(args))
                {
                    expectation.AddActualCall();
                    if (expectation.RepeatableOption == RepeatableOption.Never)
                    {
                        string errMsg = string.Format("{0} Expected #{1}, Actual #{2}.", expectation.ErrorMessage, expectation.Expected, expectation.ActualCallsCount);
                        ExpectationViolationException exception = new ExpectationViolationException(errMsg);
                        MockRepository.SetExceptionToBeThrownOnVerify(proxy, exception);
                        throw exception;
                    }
                    return(expectation);
                }
            }
            return(null);
        }
        /// <summary>
        /// Get the expectation for this method on this object with this arguments
        /// </summary>
        /// <param name="invocation">Invocation for this method</param>
        /// <param name="proxy">Mocked object.</param>
        /// <param name="method">Method.</param>
        /// <param name="args">Args.</param>
        /// <returns>True is the call was recorded, false otherwise</returns>
        protected override IExpectation DoGetRecordedExpectation(IInvocation invocation, object proxy, MethodInfo method, object[] args)
        {
            IExpectation expectation = GetRecordedExpectationOrNull(proxy, method, args);

            if (expectation == null)
            {
                RhinoMocks.Logger.LogUnexpectedMethodCall(invocation, "Unexpected method call error");
                ExpectationViolationException expectationViolationException = UnexpectedMethodCall(invocation, proxy, method, args);
                MockRepository.SetExceptionToBeThrownOnVerify(proxy, expectationViolationException);
                throw expectationViolationException;
            }
            return(expectation);
        }
Esempio n. 3
0
 internal Activities(ExpectationViolationException exception)
 {
     _exception = exception;
 }