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 Get_should_throw_if_argument_null()
        {
            var connection = NSubstitute.Substitute.For <IBusConnection>();
            var sut        = new PublisherChannelContextPool(connection);

            Assert.Throws <ArgumentNullException>(() => sut.Get(null));
        }
        public void Get_should_return_valid_channel()
        {
            var expectedChannel = NSubstitute.Substitute.For <IModel>();
            var connection      = NSubstitute.Substitute.For <IBusConnection>();

            connection.CreateChannel()
            .Returns(expectedChannel);

            var sut = new PublisherChannelContextPool(connection);

            var references = new QueueReferences("lorem", "ipsum", "dolor", "amet", "sic");
            var result     = sut.Get(references);

            result.Should().NotBeNull();
            result.QueueReferences.Should().Be(references);
            result.Channel.Should().Be(expectedChannel);

            expectedChannel.Received(1)
            .ExchangeDeclare(references.ExchangeName, type: ExchangeType.Topic);
        }