Пример #1
0
 /// <summary>
 ///     Reads a value using an indexer 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="TKey">The type of the indexer key.</typeparam>
 /// <typeparam name="TValue">The type of the indexer value.</typeparam>
 /// <param name="indexerStep">The indexer 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>
 /// <param name="key">The indexer key used.</param>
 /// <returns>The value being read.</returns>
 /// <seealso cref="IIndexerStep{TKey, TValue}" />
 public static TValue GetWithStrictnessCheckIfNull <TKey, TValue>(this IIndexerStep <TKey, TValue>?indexerStep, IMockInfo mockInfo, TKey key)
 {
     if (indexerStep == 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 indexer reads and
        ///     writes.
        /// </summary>
        /// <typeparam name="TKey">The type of the indexer key.</typeparam>
        /// <typeparam name="TValue">The type of the indexer value.</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="ICanHaveNextIndexerStep{TKey, TValue}" /> that can be used to add further steps.</returns>
        public static ICanHaveNextIndexerStep <TKey, TValue> JoinPoint <TKey, TValue>(
            this ICanHaveNextIndexerStep <TKey, TValue> caller,
            out IIndexerStep <TKey, TValue> joinPoint)
        {
            var joinStep = new IndexerStepWithNext <TKey, TValue>();

            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 ICanHaveNextIndexerStep <TKey, TValue> .SetNextStep <TStep>(TStep step)
            {
                if (step == null)
                {
                    throw new ArgumentNullException(nameof(step));
                }

                _nextStep = step;
                return(step);
            }
Пример #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="IfIndexerStepBase{TKey, 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 IfIndexerStepBase(Action <IfBranchCaller> branch)
        {
            if (branch == null)
            {
                throw new ArgumentNullException(nameof(branch));
            }

            var ifBranch = new IfBranchCaller(this);

            IfBranch = ifBranch;
            branch.Invoke(ifBranch);
        }
Пример #5
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="IfBranchCaller" /> class.
 /// </summary>
 /// <param name="ifIndexerStep">The if step whose 'default' set of steps will constitute 'else' branch.</param>
 public IfBranchCaller(IfIndexerStepBase <TKey, TValue> ifIndexerStep)
 {
     ElseBranch = new ElseBranchRejoiner(ifIndexerStep);
 }
Пример #6
0
 /// <summary>
 ///     Restores the Mock to an unconfigured state.
 /// </summary>
 public override void Clear()
 {
     _nextStep = null;
 }
Пример #7
0
 /// <summary>
 ///     Introduces a step that will forward getting and setting indexer values to another step.
 /// </summary>
 /// <typeparam name="TKey">The type of the indexer key.</typeparam>
 /// <typeparam name="TValue">The type of the indexer value.</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 indexer values will be forwarded.</param>
 public static void Join <TKey, TValue>(
     this ICanHaveNextIndexerStep <TKey, TValue> caller,
     IIndexerStep <TKey, TValue> joinPoint)
 {
     caller.SetNextStep(joinPoint);
 }