示例#1
0
 /// <summary>
 ///     Calls a method using a method step. If the step is <c>null</c>, uses the strictness of the mock
 ///     to decide whether to throw a <see cref="MockMissingException" /> (VeryStrict) or to return a
 ///     default value (Lenient or Strict).
 /// </summary>
 /// <typeparam name="TParam">The method parameter type.</typeparam>
 /// <typeparam name="TResult">The method return type.</typeparam>
 /// <param name="methodStep">The method step (can be null) through which the method is called.</param>
 /// <param name="mockInfo">Information about the mock through which the method is called.</param>
 /// <param name="param">The parameters used.</param>
 /// <returns>The returned result.</returns>
 /// <seealso cref="IMethodStep{TParam, TResult}" />
 public static TResult CallWithStrictnessCheckIfNull <TParam, TResult>(this IMethodStep <TParam, TResult>?methodStep, IMockInfo mockInfo,
                                                                       TParam param)
 {
     if (methodStep == null)
     {
         if (mockInfo.Strictness != Strictness.VeryStrict)
         {
             return(default !);
示例#2
0
        /// <summary>
        ///     Introduces a step whose only purpose is to be joined to from another step. It forwards all method calls.
        /// </summary>
        /// <typeparam name="TParam">The method parameter type.</typeparam>
        /// <typeparam name="TResult">The method return type.</typeparam>
        /// <param name="caller">The mock or step to which this 'join' step is added.</param>
        /// <param name="joinPoint">A reference to this step that can be used in a Join step.</param>
        /// <returns>An <see cref="ICanHaveNextMethodStep{TParam, TResult}" /> that can be used to add further steps.</returns>
        public static ICanHaveNextMethodStep <TParam, TResult> JoinPoint <TParam, TResult>(
            this ICanHaveNextMethodStep <TParam, TResult> caller,
            out IMethodStep <TParam, TResult> joinPoint)
        {
            var joinStep = new MethodStepWithNext <TParam, TResult>();

            joinPoint = joinStep;
            return(caller.SetNextStep(joinStep));
        }
示例#3
0
            /// <summary>
            ///     Replaces the current 'next' step with a new step.
            /// </summary>
            /// <typeparam name="TStep">The actual type of the new step.</typeparam>
            /// <param name="step">The new step.</param>
            /// <returns>The new step, so that we can add further steps in a fluent fashion.</returns>
            TStep ICanHaveNextMethodStep <TParam, TResult> .SetNextStep <TStep>(TStep step)
            {
                if (step == null)
                {
                    throw new ArgumentNullException(nameof(step));
                }

                _nextStep = step;
                return(step);
            }
示例#4
0
        /// <summary>
        ///     Replaces the current 'next' step with a new step.
        /// </summary>
        /// <typeparam name="TStep">The actual type of the new step.</typeparam>
        /// <param name="step">The new step.</param>
        /// <returns>The new step, so that we can add further steps in a fluent fashion.</returns>
        public TStep SetNextStep <TStep>(TStep step) where TStep : IMethodStep <TParam, TResult>
        {
            if (step == null)
            {
                throw new ArgumentNullException(nameof(step));
            }

            NextStep = step;
            return(step);
        }
示例#5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="IfMethodStepBase{TParam, TResult}" /> class.
        /// </summary>
        /// <param name="branch">
        ///     An action to set up the alternative branch; it also provides a means of re-joining the normal
        ///     branch.
        /// </param>
        protected IfMethodStepBase(Action <IfBranchCaller> branch)
        {
            if (branch == null)
            {
                throw new ArgumentNullException(nameof(branch));
            }

            var ifBranch = new IfBranchCaller(this);

            IfBranch = ifBranch;
            branch.Invoke(ifBranch);
        }
示例#6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="IfBranchCaller" /> class.
 /// </summary>
 /// <param name="ifMethodStep">The if step whose 'default' set of steps will constitute 'else' branch.</param>
 public IfBranchCaller(IfMethodStepBase <TParam, TResult> ifMethodStep)
 {
     ElseBranch = new ElseBranchRejoiner(ifMethodStep);
 }
示例#7
0
 /// <summary>
 ///     Restores the Mock to an unconfigured state.
 /// </summary>
 public override void Clear()
 {
     _nextStep = null;
 }
示例#8
0
 /// <summary>
 ///     Introduces a step that will forward method execution to another step.
 /// </summary>
 /// <typeparam name="TParam">The method parameter type.</typeparam>
 /// <typeparam name="TResult">The method return type.</typeparam>
 /// <param name="caller">The mock or step to which this 'join' step is added.</param>
 /// <param name="joinPoint">The step to which method execution will be forwarded.</param>
 public static void Join <TParam, TResult>(
     this ICanHaveNextMethodStep <TParam, TResult> caller,
     IMethodStep <TParam, TResult> joinPoint)
 {
     caller.SetNextStep(joinPoint);
 }