public static void InterceptAllOpenMethods(IMockCommunicationObject mco, List <string> methodsCalled)
    {
        mco.OnOpeningOverride = () =>
        {
            methodsCalled.Add("OnOpening");
            mco.DefaultOnOpening();
        };

        mco.OnOpenOverride = (TimeSpan t) =>
        {
            methodsCalled.Add("OnOpen");
            mco.DefaultOnOpen(t);
        };

        mco.OnBeginOpenOverride = (TimeSpan t, AsyncCallback c, object s) =>
        {
            methodsCalled.Add("OnBeginOpen");
            return(mco.DefaultOnBeginOpen(t, c, s));
        };

        mco.OnOpenedOverride = () =>
        {
            methodsCalled.Add("OnOpened");
            mco.DefaultOnOpened();
        };
    }
    // Intercepts all the open and close methods in MockCommunicationObject
    // and records the CommunicationState before and after the default code executes,
    public static void InterceptAllStateChanges(IMockCommunicationObject mco, CommunicationStateData data)
    {
        // Immediately capture the current state after initial creation
        data.StateAfterCreate = mco.State;

        mco.OnOpeningOverride = () =>
        {
            data.StateEnterOnOpening = mco.State;
            mco.DefaultOnOpening();
            data.StateLeaveOnOpening = mco.State;
        };

        mco.OnOpenOverride = (TimeSpan t) =>
        {
            data.StateEnterOnOpen = mco.State;
            mco.DefaultOnOpen(t);
            data.StateLeaveOnOpen = mco.State;
        };

        mco.OnBeginOpenOverride = (TimeSpan t, AsyncCallback c, object s) =>
        {
            data.StateEnterOnBeginOpen = mco.State;
            IAsyncResult result = mco.DefaultOnBeginOpen(t, c, s);
            data.StateLeaveOnBeginOpen = mco.State;
            return(result);
        };

        mco.OnOpenedOverride = () =>
        {
            data.StateEnterOnOpened = mco.State;
            mco.DefaultOnOpened();
            data.StateLeaveOnOpened = mco.State;
        };

        mco.OnClosingOverride = () =>
        {
            data.StateEnterOnClosing = mco.State;
            mco.DefaultOnClosing();
            data.StateLeaveOnClosing = mco.State;
        };

        mco.OnCloseOverride = (TimeSpan t) =>
        {
            data.StateEnterOnClose = mco.State;
            mco.DefaultOnClose(t);
            data.StateLeaveOnClose = mco.State;
        };

        mco.OnBeginCloseOverride = (TimeSpan t, AsyncCallback c, object s) =>
        {
            data.StateEnterOnBeginClose = mco.State;
            IAsyncResult result = mco.DefaultOnBeginClose(t, c, s);
            data.StateLeaveOnBeginClose = mco.State;
            return(result);
        };

        mco.OnClosedOverride = () =>
        {
            data.StateEnterOnClosed = mco.State;
            mco.DefaultOnClosed();
            data.StateLeaveOnClosed = mco.State;
        };

        #endregion helpers
    }
    // Intercepts all the open and close methods in MockCommunicationObject
    // and records the CommunicationState before and after the default code executes,
    public static void InterceptAllStateChanges(IMockCommunicationObject mco, CommunicationStateData data)
    {
        // Immediately capture the current state after initial creation
        data.StateAfterCreate = mco.State;

        mco.OnOpeningOverride = () =>
        {
            data.StateEnterOnOpening = mco.State;
            mco.DefaultOnOpening();
            data.StateLeaveOnOpening = mco.State;
        };

        mco.OnOpenOverride = (TimeSpan t) =>
        {
            data.StateEnterOnOpen = mco.State;
            mco.DefaultOnOpen(t);
            data.StateLeaveOnOpen = mco.State;
        };

        mco.OnBeginOpenOverride = (TimeSpan t, AsyncCallback c, object s) =>
        {
            data.StateEnterOnBeginOpen = mco.State;
            IAsyncResult result = mco.DefaultOnBeginOpen(t, c, s);
            data.StateLeaveOnBeginOpen = mco.State;
            return result;
        };

        mco.OnOpenedOverride = () =>
        {
            data.StateEnterOnOpened = mco.State;
            mco.DefaultOnOpened();
            data.StateLeaveOnOpened = mco.State;
        };

        mco.OnClosingOverride = () =>
        {
            data.StateEnterOnClosing = mco.State;
            mco.DefaultOnClosing();
            data.StateLeaveOnClosing = mco.State;
        };

        mco.OnCloseOverride = (TimeSpan t) =>
        {
            data.StateEnterOnClose = mco.State;
            mco.DefaultOnClose(t);
            data.StateLeaveOnClose = mco.State;
        };

        mco.OnBeginCloseOverride = (TimeSpan t, AsyncCallback c, object s) =>
        {
            data.StateEnterOnBeginClose = mco.State;
            IAsyncResult result = mco.DefaultOnBeginClose(t, c, s);
            data.StateLeaveOnBeginClose = mco.State;
            return result;
        };

        mco.OnClosedOverride = () =>
        {
            data.StateEnterOnClosed = mco.State;
            mco.DefaultOnClosed();
            data.StateLeaveOnClosed = mco.State;
        };

        #endregion helpers
    }
    public static void InterceptAllOpenMethods(IMockCommunicationObject mco, List<string> methodsCalled)
    {
        mco.OnOpeningOverride = () =>
        {
            methodsCalled.Add("OnOpening");
            mco.DefaultOnOpening();
        };

        mco.OnOpenOverride = (TimeSpan t) =>
        {
            methodsCalled.Add("OnOpen");
            mco.DefaultOnOpen(t);
        };

        mco.OnBeginOpenOverride = (TimeSpan t, AsyncCallback c, object s) =>
        {
            methodsCalled.Add("OnBeginOpen");
            return mco.DefaultOnBeginOpen(t, c, s);
        };

        mco.OnOpenedOverride = () =>
        {
            methodsCalled.Add("OnOpened");
            mco.DefaultOnOpened();
        };
    }