Esempio n. 1
0
        /// <summary>
        /// Создать сервис для публикации сообщений.
        /// </summary>
        public IMessageQueuePublisher CreateMessageQueuePublisher()
        {
            if (_queuePublisher == null)
            {
                // Сессия на поток, чтобы иметь возможность быстрой публикации сообщений
                var sessionManager  = new MessageQueueSessionManagerPerThread(_sessionFactory);
                var commandExecutor = new MessageQueueCommandExecutor(_commandExecutor, sessionManager);

                _queuePublisher = new MessageQueuePublisher(commandExecutor);
            }

            return(_queuePublisher);
        }
        public void ShouldNotDisposeSessionAfterCommand()
        {
            // Given
            var session = new Mock <IMessageQueueSession>();

            session.SetupGet(m => m.IsOpen).Returns(true);
            var sessionFactory = new Mock <IMessageQueueSessionFactory>();

            sessionFactory.Setup(m => m.OpenSession()).Returns(session.Object);

            // When
            var target        = new MessageQueueSessionManagerPerThread(sessionFactory.Object);
            var actualSession = target.OpenSession();

            target.CloseSession(actualSession);

            // Then
            session.Verify(m => m.Dispose(), Times.Never());
        }
        public void ShouldReturnsSameSessionBeforeEachCommand()
        {
            // Given
            var session = new Mock <IMessageQueueSession>();

            session.SetupGet(m => m.IsOpen).Returns(true);
            var sessionFactory = new Mock <IMessageQueueSessionFactory>();

            sessionFactory.Setup(m => m.OpenSession()).Returns(session.Object);

            // When
            var target         = new MessageQueueSessionManagerPerThread(sessionFactory.Object);
            var actualSession1 = target.OpenSession();
            var actualSession2 = target.OpenSession();

            // Then
            Assert.IsNotNull(actualSession1);
            Assert.AreEqual(actualSession1, actualSession2);
        }