Missing interfaces for listeners

Nov 8, 2012 at 1:46 PM
Edited Nov 8, 2012 at 1:47 PM

If you use interfaces (especially for the listeners) it is much easier for other people to create mocks for unit tests. As a plus the tight coupling to a concrete implementation can be removed (partly).

e.g.:

     /// <summary>
    /// Common interface for handling hooks.
    /// </summary>
    public interface IHookListener
    {
        /// <summary>
        /// Gets or Sets the enabled status of the Hook.
        /// </summary>
        /// <value>
        ///  <c>true</c> if the Hook is presently installed, activated, and will fire events; otherwise, <c>false</c> if the Hook is not part of the hook chain, and will not fire events.
        /// </value>
        bool Enabled { get; set; }
    }

 


    /// <summary>
    /// This is an interface of monitoring keyboard activities.
    /// </summary>
    public interface IKeyboardHookListener : IHookListener
    {
        #region Public Events

        /// <summary>
        /// Occurs when a key is pressed.
        /// </summary>
        event KeyEventHandler KeyDown;

        /// <summary>
        /// Occurs when a key is pressed.
        /// </summary>
        /// <remarks>
        /// Key events occur in the following order:
        /// <list type="number">
        ///   <item>KeyDown</item>
        ///   <item>KeyPress</item>
        ///   <item>KeyUp</item>
        /// </list>
        /// The KeyPress event is not raised by non-character keys; however, the non-character keys do raise the KeyDown and KeyUp events.
        /// Use the KeyChar property to sample keystrokes at run time and to consume or modify a subset of common keystrokes.
        /// To handle keyboard events only in your application and not enable other applications to receive keyboard events,
        /// set the <see cref="KeyPressEventArgs.Handled"/> property in your form's KeyPress event-handling method to <b>true</b>.
        /// </remarks>
        event KeyPressEventHandler KeyPress;

        /// <summary>
        /// Occurs when a key is released.
        /// </summary>
        event KeyEventHandler KeyUp;

        #endregion
    }

 

   /// <summary>
    /// This is an interface of monitoring all mouse activities.
    /// </summary>
    public interface IMouseHookListener : IHookListener
    {
        #region Public Events

        /// <summary>
        /// Occurs when a click was performed by the mouse.
        /// </summary>
        event MouseEventHandler MouseClick;

        /// <summary>
        /// Occurs when a mouse button is double-clicked.
        /// </summary>
        event MouseEventHandler MouseDoubleClick;

        /// <summary>
        /// Occurs when the mouse a mouse button is pressed.
        /// </summary>
        event MouseEventHandler MouseDown;

        /// <summary>
        /// Occurs when the mouse pointer is moved.
        /// </summary>
        event MouseEventHandler MouseMove;

        /// <summary>
        /// Occurs when a mouse button is released.
        /// </summary>
        event MouseEventHandler MouseUp;

        /// <summary>
        /// Occurs when the mouse wheel moves.
        /// </summary>
        event MouseEventHandler MouseWheel;

        #endregion
    }