public static IMethodOptions <T> WhenCalledWithCurrentTransaction <T> ( this IMethodOptions <T> options, ClientTransaction expectedTransaction, Action <MethodInvocation> whenCalledAction) { return(options.WhenCalled( mi => { Assert.That(ClientTransaction.Current, Is.SameAs(expectedTransaction)); whenCalledAction(mi); })); }
/// <summary> /// Executes the async callback when the method is called. Use this in conjunction with the TestAsyncTaskManager. /// </summary> public static IMethodOptions <IAsyncResult> ExecuteAsyncCallback(this IMethodOptions <IAsyncResult> methodOptions) { if (methodOptions == null) { throw new ArgumentNullException("methodOptions"); } methodOptions .WhenCalled(m => new Action(() => { }) .BeginInvoke(m.Arguments[1] as AsyncCallback, m.Arguments[2])); return(methodOptions); }
/// <summary> /// Provides support for ordered Rhino.Mocks expectations without dedicated <see cref="MockRepository"/> instance. Create an /// <see cref="OrderedExpectationCounter"/>, then call this method with that counter for all expectations that should occur /// in the same order as declared. /// Use this method rather then <see cref="Ordered{T}"/> when you need to specify your own <see cref="IMethodOptions{T}.WhenCalled"/> handler. /// </summary> public static IMethodOptions <T> WhenCalledOrdered <T> ( this IMethodOptions <T> options, OrderedExpectationCounter counter, Action <MethodInvocation> whenCalledAction, string message = null) { var expectedPosition = counter.GetNextExpectedPosition(); return(options.WhenCalled( mi => { counter.CheckPosition(mi.Method.ToString(), expectedPosition, message); whenCalledAction(mi); })); }
public static IMethodOptions <T> Return <T>(this IMethodOptions <T> opts, Func <T> factory) { opts.Return(default(T)); // required for Rhino.Mocks on non-void methods opts.WhenCalled(mi => mi.ReturnValue = factory()); return(opts); }
public static IMethodOptions <T> WithCurrentTransaction <T> (this IMethodOptions <T> options, ClientTransaction expectedTransaction) { return(options.WhenCalled(mi => Assert.That(ClientTransaction.Current, Is.SameAs(expectedTransaction)))); }
/// <summary> /// Assigns the argument found at the specified <paramref name="index"/> of the stub (or expected) call /// through the <paramref name="assign"/> lambda received. /// <para> An exception is thrown if the method doesn't have the specified argument or he is not of the expected type. </para> /// </summary> /// /// <typeparam name="T"> Type of the mocked object </typeparam> /// <typeparam name="TArgument"> Type of the argument.</typeparam> /// <param name="options"></param> /// <param name="index">The index of the argument we are looking for</param> /// <param name="assign">The lambda that will be called with the argument value (C#: x => ... / VB: Sub(x) ...) </param> public static IMethodOptions <T> AssignArgument <T, TArgument>(this IMethodOptions <T> options, int index, Action <TArgument> assign) { return(options.WhenCalled(i => assign(GetArgument <TArgument>(i, index)))); }
private void RepeatAny(Action <MethodInvocation> invocationConfig) { _methodOptions.WhenCalled(invocationConfig).Return(default(TReturnValue)).Repeat.Any(); }