コード例 #1
0
ファイル: JoinStepExtensions.cs プロジェクト: mocklis/mocklis
        /// <summary>
        ///     Introduces a step whose only purpose is to be joined to from another step. It forwards all event handler adds and
        ///     removes.
        /// </summary>
        /// <typeparam name="THandler">The event handler type for the event.</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="ICanHaveNextEventStep{THandler}" /> that can be used to add further steps.</returns>
        public static ICanHaveNextEventStep <THandler> JoinPoint <THandler>(
            this ICanHaveNextEventStep <THandler> caller,
            out IEventStep <THandler> joinPoint)
            where THandler : Delegate
        {
            var joinStep = new EventStepWithNext <THandler>();

            joinPoint = joinStep;
            return(caller.SetNextStep(joinStep));
        }
コード例 #2
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 ICanHaveNextEventStep <THandler> .SetNextStep <TStep>(TStep step)
        {
            if (step == null)
            {
                throw new ArgumentNullException(nameof(step));
            }

            NextStep = step;
            return(step);
        }
コード例 #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="IfEventStepBase{THandler}" /> 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 IfEventStepBase(Action <IfBranchCaller> branch)
        {
            if (branch == null)
            {
                throw new ArgumentNullException(nameof(branch));
            }

            var ifBranch = new IfBranchCaller(this);

            IfBranch = ifBranch;
            branch.Invoke(ifBranch);
        }
コード例 #4
0
        /// <summary>
        ///     Removes an event handler using an event step. If the step is <c>null</c>, use the strictness of the mock
        ///     to decide whether to throw a <see cref="MockMissingException" /> (VeryStrict) or to do nothing
        ///     (Lenient or Strict).
        /// </summary>
        /// <typeparam name="THandler">The event handler type for the event.</typeparam>
        /// <param name="eventStep">The event step (can be null) through which the event handler is being added.</param>
        /// <param name="mockInfo">Information about the mock through which the event handler is being added.</param>
        /// <param name="value">The event handler that is being added.</param>
        public static void RemoveWithStrictnessCheckIfNull <THandler>(this IEventStep <THandler>?eventStep, IMockInfo mockInfo, THandler?value)
            where THandler : Delegate
        {
            if (eventStep == null)
            {
                if (mockInfo.Strictness != Strictness.VeryStrict)
                {
                    return;
                }

                throw new MockMissingException(MockType.EventRemove, mockInfo);
            }

            eventStep.Remove(mockInfo, value);
        }
コード例 #5
0
ファイル: EventMock.cs プロジェクト: mocklis/mocklis
 /// <summary>
 ///     Restores the Mock to an unconfigured state.
 /// </summary>
 public override void Clear()
 {
     _nextStep = null;
 }
コード例 #6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="IfBranchCaller" /> class.
 /// </summary>
 /// <param name="ifEventStep">The if step whose 'default' set of steps will constitute 'else' branch.</param>
 public IfBranchCaller(IfEventStepBase <THandler> ifEventStep)
 {
     ElseBranch = new ElseBranchRejoiner(ifEventStep);
 }
コード例 #7
0
ファイル: JoinStepExtensions.cs プロジェクト: mocklis/mocklis
 /// <summary>
 ///     Introduces a step that will forward adding and removing of event handlers to another step.
 /// </summary>
 /// <typeparam name="THandler">The event handler type for the event.</typeparam>
 /// <param name="caller">The mock or step to which this 'join' step is added.</param>
 /// <param name="joinPoint">The step to which adding and removing of event handlers will be forwarded.</param>
 public static void Join <THandler>(
     this ICanHaveNextEventStep <THandler> caller,
     IEventStep <THandler> joinPoint) where THandler : Delegate
 {
     caller.SetNextStep(joinPoint);
 }