public void Listener_ChangeSource_With_Reconnec_True_Connects_New_Provider_Even_If_Not_Originally_Connected()
        {
            var firstProvider = new MockListenerProvider();
            var firstExtractor = new MockMessageBytesExtractor();
            firstProvider.ConfigureForConnect();

            _Listener.ChangeSource(firstProvider.Object, firstExtractor.Object, _RawMessageTranslator.Object, false);

            _Provider.ConfigureForConnect();
            _Listener.ChangeSource(_Provider.Object, _BytesExtractor.Object, _RawMessageTranslator.Object, true);

            _Provider.Verify(p => p.BeginConnect(It.IsAny<AsyncCallback>()), Times.Once());
        }
        public void Listener_ChangeSource_AutoReconnect_Does_Not_Reconnect_If_Clear()
        {
            var firstProvider = new MockListenerProvider();
            var firstExtractor = new MockMessageBytesExtractor();
            firstProvider.ConfigureForConnect();

            _Listener.ChangeSource(firstProvider.Object, firstExtractor.Object, _RawMessageTranslator.Object, false);
            _Listener.Connect(false);

            _Provider.ConfigureForConnect();
            _Listener.ChangeSource(_Provider.Object, _BytesExtractor.Object, _RawMessageTranslator.Object, false);

            firstProvider.Verify(p => p.Close(), Times.Once());
            _Provider.Verify(p => p.BeginConnect(It.IsAny<AsyncCallback>()), Times.Never());
        }
        public void Listener_ChangeSource_Disconnects_Existing_Provider_Even_If_Not_Connected()
        {
            var firstProvider = new MockListenerProvider();
            var firstExtractor = new MockMessageBytesExtractor();
            firstProvider.ConfigureForConnect();

            _Listener.ChangeSource(firstProvider.Object, firstExtractor.Object, _RawMessageTranslator.Object, false);

            _Provider.ConfigureForConnect();
            _Listener.ChangeSource(_Provider.Object, _BytesExtractor.Object, _RawMessageTranslator.Object, false);

            firstProvider.Verify(p => p.Close(), Times.Once());
        }
        public void Listener_ChangeSource_AutoReconnect_Reconnects_If_Set()
        {
            var firstProvider = new MockListenerProvider();
            var firstExtractor = new MockMessageBytesExtractor();
            firstProvider.Setup(p => p.Close()).Callback(() => {
                Assert.AreSame(firstProvider.Object, _Listener.Provider);
                Assert.AreSame(firstExtractor.Object, _Listener.BytesExtractor);
            });
            firstProvider.ConfigureForConnect();

            _Listener.ChangeSource(firstProvider.Object, firstExtractor.Object, _RawMessageTranslator.Object, false);
            _Listener.Connect(false);

            _Provider.ConfigureForConnect();
            _Listener.ChangeSource(_Provider.Object, _BytesExtractor.Object, _RawMessageTranslator.Object, true);

            firstProvider.Verify(p => p.Close(), Times.Once());
            _Provider.Verify(p => p.BeginConnect(It.IsAny<AsyncCallback>()), Times.Once());
        }