コード例 #1
0
        /// <summary>
        ///     Adds an event handler using an event 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 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 AddWithStrictnessCheckIfNull <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.EventAdd, mockInfo);
            }

            eventStep.Add(mockInfo, value);
        }
コード例 #2
0
ファイル: EventMock.cs プロジェクト: mocklis/mocklis
        /// <summary>
        ///     Adds an event handler to 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 Add(THandler?value)
        {
            if (_nextStep == null)
            {
                IMockInfo mockInfo = this;

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

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

            _nextStep.Add(this, value);
        }