Example #1
0
        /// <summary>
        /// Create an expectation on this mock for this action to occur
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="R"></typeparam>
        /// <param name="mock">The mock.</param>
        /// <param name="action">The action.</param>
        /// <returns></returns>
        public static IMethodOptions <R> Expect <T, R>(this T mock, Function <T, R> action)
            where T : class
        {
            if (mock == null)
            {
                throw new ArgumentNullException("mock", "You cannot mock a null instance");
            }

            IMockedObject  mockedObject   = MockRepository.GetMockedObject(mock);
            MockRepository mocks          = mockedObject.Repository;
            var            isInReplayMode = mocks.IsInReplayMode(mock);

            mocks.BackToRecord(mock, BackToRecordOptions.None);
            action(mock);
            IMethodOptions <R> options = LastCall.GetOptions <R>();

            options.TentativeReturn();
            if (isInReplayMode)
            {
                mocks.ReplayCore(mock, false);
            }
            return(options);
        }