Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Removes an event handler from the mocked event.
        /// </summary>
        /// <remarks>
        ///     This method is called when the event is called through a mocked interface, but can also be used to interact with
        ///     the mock directly.
        /// </remarks>
        /// <param name="value">The event handler.</param>
        public void Remove(THandler?value)
        {
            if (_nextStep == null)
            {
                IMockInfo mockInfo = this;

                if (mockInfo.Strictness == Strictness.Lenient)
                {
                    return;
                }

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

            _nextStep.Remove(this, value);
        }