public void GivenAQueueBalancer()
        {
            var channelEvents = new ChannelEvents();
            this.eventsProxy = new ChannelEvents();
            this.eventsProxy.OnChannelCreated += this.eventsProxyOnChannelCreated;

            var channelFactory = Substitute.For<ChannelFactory>();
            var channel = Substitute.For<PushChannel>();
            channel.Events.Returns(channelEvents);
            channelFactory.Create().Returns(channel);

            this.balancer = new QueueLengthLoadBalancer(channelFactory, this.eventsProxy, PlatformType.None);

            this.balancer.AddChannels(5);
        }
        public void WhenBalancerIsShutdown()
        {
            var channelEvents = new ChannelEvents();
            this.eventsProxy = new ChannelEvents();

            var channelFactory = Substitute.For<ChannelFactory>();
            this.theChannel = Substitute.For<PushChannel>();
            this.theChannel.Events.Returns(channelEvents);
            channelFactory.Create().Returns(this.theChannel);

            this.balancer = new QueueLengthLoadBalancer(channelFactory, this.eventsProxy, PlatformType.None);

            this.balancer.AddChannels(1);
            this.balancer.ShutdownAll(true);
        }
        public void WhenTwoChannelsAreRemoved()
        {
            var channelEvents = new ChannelEvents();
            this.eventsProxy = new ChannelEvents();
            this.eventsProxy.OnChannelDestroyed += this.EventsProxyOnChannelDestroyed;

            var channelFactory = Substitute.For<ChannelFactory>();
            var channel = Substitute.For<PushChannel>();
            channel.Events.Returns(channelEvents);
            channelFactory.Create().Returns(channel);

            this.balancer = new QueueLengthLoadBalancer(channelFactory, this.eventsProxy, PlatformType.None);

            this.balancer.AddChannels(3);
            this.balancer.RemoveChannels(5);
        }
        public void WhenBalancerIsShutdown()
        {
            this.eventsProxy = new ChannelEvents();

            var channelFactory = Substitute.For<ChannelFactory>();

            this.GivenAnEmptyChannel();
            this.GivenABusyChannel();

            channelFactory.Create().Returns(this.theEmptyChannel, theBusyChannel);

            this.balancer = new QueueLengthLoadBalancer(channelFactory, this.eventsProxy, PlatformType.None);

            this.theNotification = Substitute.For<Notification>();

            this.balancer.AddChannels(2);
            this.balancer.Distribute(this.theNotification);
        }