/// <summary>
        /// Specifies that the arranged member will return consecutive values from the given array.
        /// If the arranged member is called after it has returned the last value, the behavior depends on the behavior parameter.
        /// </summary>
        /// <typeparam name="TReturn">Type of return value</typeparam>
        /// <param name="func">The arranged member</param>
        /// <param name="values">The list of values that will be returned by the arranged member. The list may be modified after the arrangement is made.</param>
        /// <param name="behavior">The behavior after the last value has been returned.</param>
        /// <returns>Reference to <see cref="IAssertable"/> interface.</returns>
        public static IAssertable ReturnsMany <TReturn>(this IFunc <TReturn> func, IList <TReturn> values, AfterLastValue behavior)
        {
            return(ProfilerInterceptor.GuardInternal(() =>
            {
                if (values == null || values.Count == 0)
                {
                    throw new ArgumentException("Expected at least one value to return", "values");
                }

                Action <ReturnsManyImpl <TReturn> > afterEndAction = null;
                switch (behavior)
                {
                case AfterLastValue.ThrowAssertionFailed:
                    afterEndAction = impl => MockingContext.Fail("List of arranged return values exhausted.");
                    break;

                case AfterLastValue.KeepReturningLastValue:
                    afterEndAction = impl => impl.CurrentIndex = values.Count - 1;
                    break;

                case AfterLastValue.StartFromBeginning:
                    afterEndAction = impl => impl.CurrentIndex = 0;
                    break;

                default:
                    throw new ArgumentException("behavior");
                }

                return func.Returns(new ReturnsManyImpl <TReturn>(values, afterEndAction).GetNext);
            }));
        }
Example #2
0
 public static IAssertable TaskResult <T>(this IFunc <Task <T> > expectation, T result)
 {
     return(ProfilerInterceptor.GuardInternal(() => expectation.Returns(MockingUtil.TaskFromResult(result))));
 }