public void CachedMessageConsumer() { 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); Destination destination = new Topic("test.dest"); IMessageConsumer consumerA = sessionA.CreateConsumer(destination); TestMessageConsumer tmpA = GetTestMessageConsumer(consumerA); sessionA.Close(); ISession sessionB = con1.CreateSession(true, SessionMode.SessionTransacted); IMessageConsumer consumerB = sessionB.CreateConsumer(destination); TestMessageConsumer tmpB = GetTestMessageConsumer(consumerB); Assert.AreSame(tmpA, tmpB); mocks.VerifyAll(); }
private static TestMessageConsumer GetTestMessageConsumer(IMessageConsumer consumer) { CachedMessageConsumer cmp1 = consumer as CachedMessageConsumer; Assert.IsNotNull(cmp1); TestMessageConsumer tmp1 = cmp1.Target as TestMessageConsumer; Assert.IsNotNull(tmp1); return(tmp1); }