public void CachedMessageProducer()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = new TestConnection();

            Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once();

            mocks.ReplayAll();


            CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();

            cachingConnectionFactory.TargetConnectionFactory = connectionFactory;
            IConnection con1 = cachingConnectionFactory.CreateConnection();

            ISession            sessionA  = con1.CreateSession(true, SessionMode.SessionTransacted);
            Topic               dest      = new Topic("test.topic");
            IMessageProducer    producerA = sessionA.CreateProducer(dest);
            TestMessageProducer tmpA      = GetTestMessageProducer(producerA);

            sessionA.Close();

            ISession            sessionB  = con1.CreateSession(true, SessionMode.SessionTransacted);
            IMessageProducer    producerB = sessionB.CreateProducer(dest);
            TestMessageProducer tmpB      = GetTestMessageProducer(producerB);

            Assert.AreSame(tmpA, tmpB);

            mocks.VerifyAll();
        }
        private static TestMessageProducer GetTestMessageProducer(IMessageProducer producer1)
        {
            CachedMessageProducer cmp1 = producer1 as CachedMessageProducer;

            Assert.IsNotNull(cmp1);
            TestMessageProducer tmp1 = cmp1.Target as TestMessageProducer;

            Assert.IsNotNull(tmp1);
            return(tmp1);
        }