public void Return_should_not_return_channel_to_the_pool_if_closed() { var channel = NSubstitute.Substitute.For <IModel>(); channel.IsClosed.Returns(true); var references = new QueueReferences("lorem", "ipsum", "dolor", "amet", "sic"); var connection = NSubstitute.Substitute.For <IBusConnection>(); connection.CreateChannel() .Returns(channel); var sut = new PublisherChannelContextPool(connection); var ctx = new PublisherChannelContext(channel, references, sut); sut.Get(references); channel.Received(1) .ExchangeDeclare(references.ExchangeName, type: ExchangeType.Topic); channel.ClearReceivedCalls(); sut.Return(ctx); sut.GetAvailableCount().Should().Be(0); }
public void Return_should_throw_if_arguments_null() { var connection = NSubstitute.Substitute.For <IBusConnection>(); var sut = new PublisherChannelContextPool(connection); Assert.Throws <ArgumentNullException>(() => sut.Return(null)); }
public void Dispose_should_dispose_channels() { var openChannel = NSubstitute.Substitute.For <IModel>(); var references = new QueueReferences("lorem", "ipsum", "dolor", "amet", "sic"); var connection = NSubstitute.Substitute.For <IBusConnection>(); var sut = new PublisherChannelContextPool(connection); var ctx = new PublisherChannelContext(openChannel, references, sut); sut.Return(ctx); sut.Dispose(); openChannel.Received(1) .Dispose(); }