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); }
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); }
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); }