/// <summary> /// Reads a value using a property 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="TValue">The type of the value.</typeparam> /// <param name="propertyStep">The property step (can be null) through which the value is read.</param> /// <param name="mockInfo">Information about the mock through which the value is read.</param> /// <returns>The value being read.</returns> /// <seealso cref="IPropertyStep{TValue}" /> public static TValue GetWithStrictnessCheckIfNull <TValue>(this IPropertyStep <TValue>?propertyStep, IMockInfo mockInfo) { if (propertyStep == 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 property reads and /// writes. /// </summary> /// <typeparam name="TValue">The type of the property.</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="ICanHaveNextPropertyStep{TValue}" /> that can be used to add further steps.</returns> public static ICanHaveNextPropertyStep <TValue> JoinPoint <TValue>( this ICanHaveNextPropertyStep <TValue> caller, out IPropertyStep <TValue> joinPoint) { var joinStep = new PropertyStepWithNext <TValue>(); 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> /// <exception cref="ArgumentNullException">step</exception> TStep ICanHaveNextPropertyStep <TValue> .SetNextStep <TStep>(TStep step) { if (step == null) { throw new ArgumentNullException(nameof(step)); } _nextStep = step; return(step); }
/// <summary> /// Initializes a new instance of the <see cref="IfPropertyStepBase{TValue}" /> 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 IfPropertyStepBase(Action <IfBranchCaller> branch) { if (branch == null) { throw new ArgumentNullException(nameof(branch)); } var ifBranch = new IfBranchCaller(this); IfBranch = ifBranch; branch.Invoke(ifBranch); }
/// <summary> /// Restores the Mock to an unconfigured state. /// </summary> public override void Clear() { _nextStep = null; }
/// <summary> /// Initializes a new instance of the <see cref="IfBranchCaller" /> class. /// </summary> /// <param name="ifPropertyStep">The if step whose 'default' set of steps will constitute 'else' branch.</param> public IfBranchCaller(IfPropertyStepBase <TValue> ifPropertyStep) { ElseBranch = new ElseBranchRejoiner(ifPropertyStep); }
/// <summary> /// Introduces a step that will forward getting and setting property values to another step. /// </summary> /// <typeparam name="TValue">The type of the property.</typeparam> /// <param name="caller">The mock or step to which this 'join' step is added.</param> /// <param name="joinPoint">The step to which getting and setting property values will be forwarded.</param> public static void Join <TValue>( this ICanHaveNextPropertyStep <TValue> caller, IPropertyStep <TValue> joinPoint) { caller.SetNextStep(joinPoint); }