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);
        }
Example #2
0
 /*
  * Method: Call
  * Get the method options for the last method call, which usually will be a method call
  * or property that is located inside the <Call>.
  * See Expected Usage.
  *
  * Expected usage:
  * (start code)
  * Expect.Call(mockObject.SomeCall()).Return(new Something());
  * Expect.Call(mockList.Count).Return(50);
  * (end)
  *
  * Thread safety:
  * This method is *not* safe for multi threading scenarios!
  * If you need to record in a multi threading environment, use the <On> method, which _can_
  * handle multi threading scenarios.
  */
 /// <summary>
 /// The method options for the last call on /any/ proxy on /any/ repository on the current thread.
 /// This method if not safe for multi threading scenarios, use <see cref="On"/>.
 /// </summary>
 public static IMethodOptions <T> Call <T>(T ignored)
 {
     return(LastCall.GetOptions <T>());
 }
Example #3
0
 /*
  * Method: For
  * Sets the last method call to repeat any number of times and return the method options
  * for the last method call, which usually will be a method call
  * or property that is located inside the <For>.
  * See Expected Usage.
  *
  * Expected usage:
  * (start code)
  * SetupResult.For(mockObject.SomeCall()).Return(new Something());
  * SetupResult.For(mockList.Count).Return(50);
  * (end)
  *
  * Thread safety:
  * This method is *not* safe for multi threading scenarios!
  * If you need to record in a multi threading environment, use the <On> method, which _can_
  * handle multi threading scenarios.
  *
  */
 /// <summary>
 /// Get the method options and set the last method call to repeat
 /// any number of times.
 /// This also means that the method would transcend ordering
 /// </summary>
 public static IMethodOptions <T> For <T>(T ignored)
 {
     return(LastCall.GetOptions <T>().Repeat.Any());
 }