/// <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 !);
/// <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)); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Restores the Mock to an unconfigured state. /// </summary> public override void Clear() { _nextStep = null; }
/// <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); }