コード例 #1
0
        public void BasicPublishReturnsWhenBasicAcksReceivedTest()
        {
            var connFactory = Substitute.For<IConnectionFactory>();
            var mockConn = Substitute.For<IConnection>();
            var model = Substitute.For<IModel>();
            model.WhenForAnyArgs(x => x.BasicPublish(null, null, false, null, null)).Do(c => model.BasicAcks += Raise.EventWith<BasicAckEventArgs>());
            connFactory.CreateConnection().Returns(mockConn);
            connFactory.CreateConnection(string.Empty).ReturnsForAnyArgs(mockConn);
            mockConn.CreateModel().Returns(model);

            var queueName = Guid.NewGuid().ToString();

            var conn = new RabbitMQQueueConnection(connFactory, queueName, false);
            conn.BasicPublish(Constants.DefaultExchange, queueName, null, new MemoryStream(), TimeSpan.FromSeconds(5), CancellationToken.None);
        }
コード例 #2
0
        public void BasicPublishThrowsWhenBasicAcksNotReceivedTest()
        {
            var connFactory = Substitute.For<IConnectionFactory>();
            var mockConn = Substitute.For<IConnection>();
            var model = Substitute.For<IModel>();
            connFactory.CreateConnection().Returns(mockConn);
            connFactory.CreateConnection(string.Empty).ReturnsForAnyArgs(mockConn);
            mockConn.CreateModel().Returns(model);

            var queueName = Guid.NewGuid().ToString();

            var conn = new RabbitMQQueueConnection(connFactory, queueName, false);
            Exception error = null;
            try
            {
                conn.BasicPublish(Constants.DefaultExchange, queueName, null, new MemoryStream(), TimeSpan.FromSeconds(5), CancellationToken.None);
            }
            catch(TimeoutException e)
            {
                error = e;
            }
            Assert.NotNull(error);
        }
コード例 #3
0
        public void BasicPublishThrowsWhenBasicNacksEventRaisedTest()
        {
            var connFactory = Substitute.For<IConnectionFactory>();
            var mockConn = Substitute.For<IConnection>();
            var model = Substitute.For<IModel>();
            model.WhenForAnyArgs(x => x.BasicPublish(null, null, false, null, null)).Do(c => model.BasicNacks += Raise.EventWith<BasicNackEventArgs>());
            connFactory.CreateConnection().Returns(mockConn);
            connFactory.CreateConnection(string.Empty).ReturnsForAnyArgs(mockConn);
            mockConn.CreateModel().Returns(model);

            var queueName = Guid.NewGuid().ToString();

            var conn = new RabbitMQQueueConnection(connFactory, queueName, false);
            Exception error = null;
            try
            {
                conn.BasicPublish(Constants.DefaultExchange, queueName, null, new MemoryStream(), TimeSpan.FromSeconds(5), CancellationToken.None);
            }
            catch (MessageNotAcknowledgedByBrokerException e)
            {
                error = e;
            }
            Assert.NotNull(error);
        }