Esempio n. 1
0
 public void Add(IMockInfo mockInfo, THandler?value)
 {
     lock (_lockObject)
     {
         AddCount++;
         LastAddMockInfo = mockInfo;
         LastAddValue    = value;
     }
 }
Esempio n. 2
0
 public void Remove(IMockInfo mockInfo, THandler?value)
 {
     lock (_lockObject)
     {
         RemoveCount++;
         LastRemoveMockInfo = mockInfo;
         LastRemoveValue    = value;
     }
 }
Esempio n. 3
0
 /// <summary>
 ///     Called when an event handler is being removed from the mocked event.
 ///     This will chose the alternative branch for a given number of adds or removes (counted together) and the normal
 ///     branch afterwards.
 /// </summary>
 /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
 /// <param name="value">The event handler that is being removed.</param>
 public override void Remove(IMockInfo mockInfo, THandler?value)
 {
     if (ShouldUseBranch())
     {
         _branch.Remove(mockInfo, value);
     }
     else
     {
         base.Remove(mockInfo, value);
     }
 }
Esempio n. 4
0
        /// <summary>
        ///     Removes an event handler from the store.
        /// </summary>
        /// <param name="value">The event handler to remove.</param>
        public void Remove(THandler?value)
        {
            THandler?previousHandler;
            THandler?eventHandler = _eventHandler;

            do
            {
                previousHandler = eventHandler;
                THandler?newHandler = (THandler)Delegate.Remove(previousHandler, value);
                eventHandler = Interlocked.CompareExchange(ref _eventHandler, newHandler, previousHandler);
            }while (eventHandler != previousHandler);
        }
Esempio n. 5
0
        /// <summary>
        ///     Called when an event handler is being removed from the mocked event.
        ///     This implementation logs before and after the event has been removed, along with any exceptions thrown.
        /// </summary>
        /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
        /// <param name="value">The event handler that is being removed.</param>
        public override void Remove(IMockInfo mockInfo, THandler?value)
        {
            _logContext.LogBeforeEventRemove(mockInfo, value);
            try
            {
                base.Remove(mockInfo, value);
            }
            catch (Exception exception)
            {
                _logContext.LogEventRemoveException(mockInfo, exception);
                throw;
            }

            _logContext.LogAfterEventRemove(mockInfo);
        }
Esempio n. 6
0
 /// <summary>
 ///     Called when an event handler is being added to the mocked event.
 ///     This implementation invokes the action with the mocked instance and the event handler.
 /// </summary>
 /// <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 override void Add(IMockInfo mockInfo, THandler?value)
 {
     _action(mockInfo.MockInstance, value);
 }
Esempio n. 7
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);
        }
Esempio n. 8
0
 /// <summary>
 ///     Removes all event handlers from the store.
 /// </summary>
 public void Clear()
 {
     _eventHandler = null;
 }
Esempio n. 9
0
 /// <summary>
 ///     Called when an event handler is being added to the mocked event.
 /// </summary>
 /// <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>
 void IEventStep <THandler> .Add(IMockInfo mockInfo, THandler?value) => Add(value);
Esempio n. 10
0
 /// <summary>
 ///     Called when an event handler is being removed from the mocked event.
 ///     Increases a counter that keeps track of the number of times event handlers have been removed.
 /// </summary>
 /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
 /// <param name="value">The event handler that is being removed.</param>
 public override void Remove(IMockInfo mockInfo, THandler?value)
 {
     Interlocked.Increment(ref _currentNumberOfRemoves);
     base.Remove(mockInfo, value);
 }
Esempio n. 11
0
 /// <summary>
 ///     Called when an event handler is being added to the mocked event.
 ///     Increases a counter that keeps track of the number of times event handlers have been added.
 /// </summary>
 /// <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 override void Add(IMockInfo mockInfo, THandler?value)
 {
     Interlocked.Increment(ref _currentNumberOfAdds);
     base.Add(mockInfo, value);
 }
Esempio n. 12
0
 /// <summary>
 ///     Logs the fact that an event handler is being removed.
 /// </summary>
 /// <typeparam name="THandler">The event handler type for the event.</typeparam>
 /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
 /// <param name="value">The event handler.</param>
 public void LogBeforeEventRemove <THandler>(IMockInfo mockInfo, THandler?value) where THandler : Delegate
 {
     _writeLine($"Removing event handler from '[{mockInfo.MocklisClassName}] {mockInfo.InterfaceName}.{mockInfo.MemberName}'");
 }
Esempio n. 13
0
 /// <summary>
 ///     Called when an event handler is being removed.
 /// </summary>
 /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
 /// <param name="value">The event handler that is being removed.</param>
 void IEventStep <THandler> .Remove(IMockInfo mockInfo, THandler?value)
 {
     _nextStep.RemoveWithStrictnessCheckIfNull(mockInfo, value);
 }
Esempio n. 14
0
 public void Remove(IMockInfo mockInfo, THandler?value)
 {
     // Call directly to next step thus bypassing the condition check.
     _ifEventStep.NextStep.RemoveWithStrictnessCheckIfNull(mockInfo, value);
 }
Esempio n. 15
0
 /// <summary>
 ///     Called when an event handler is being removed from the mocked event.
 ///     This implementation invokes the action with the event handler.
 /// </summary>
 /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
 /// <param name="value">The event handler that is being removed.</param>
 public override void Remove(IMockInfo mockInfo, THandler?value)
 {
     _action(value);
 }
Esempio n. 16
0
 /// <summary>
 ///     Called when an event handler is being removed to the mocked event. This implementation creates and throws an
 ///     exception.
 /// </summary>
 /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
 /// <param name="value">The event handler that is being removed.</param>
 public void Remove(IMockInfo mockInfo, THandler?value)
 {
     throw _exceptionFactory(mockInfo.MockInstance, value);
 }
Esempio n. 17
0
 /// <summary>
 ///     Called when an event handler is being removed to the mocked event.
 /// </summary>
 /// <param name="mockInfo">Information about the mock through which the event handler is being removed.</param>
 /// <param name="value">The event handler that is being removed.</param>
 void IEventStep <THandler> .Remove(IMockInfo mockInfo, THandler?value) => Remove(value);