public void ReturnsBasedOnRequests()
        {
            var balancer = new UpdateableAdaptiveLoadBalancer <Scoreable>(s => (int)(s.PercentMemoryUsec * 100));

            balancer.Resources.Add(new Scoreable(new Uri("http://base.one"))
            {
                PercentMemoryUsec = .25
            });
            balancer.Resources.Add(new Scoreable(new Uri("http://base.two"))
            {
                PercentMemoryUsec = .25
            });
            balancer.Resources.Add(new Scoreable(new Uri("http://base.three"))
            {
                PercentMemoryUsec = .5
            });

            var item = balancer.GetResource();

            item.Uri.Should().Be(new Uri("http://base.one"));

            item = balancer.GetResource();
            item.Uri.Should().Be(new Uri("http://base.two"));

            item = balancer.GetResource();
            item.Uri.Should().Be(new Uri("http://base.one"));

            balancer.Update(item);
            balancer.GetResource().Should().BeSameAs(item);
        }
        public void ReturnsBasedOnScoringFunction()
        {
            var balancer = new UpdateableAdaptiveLoadBalancer <Scoreable>(s => (int)(s.PercentMemoryUsec * 100),
                                                                          new List <Scoreable>
            {
                new Scoreable(new Uri("http://base.one"))
                {
                    PercentMemoryUsec = .25
                },
                new Scoreable(new Uri("http://base.two"))
                {
                    PercentMemoryUsec = .75
                },
                new Scoreable(new Uri("http://base.three"))
                {
                    PercentMemoryUsec = .5
                }
            });

            var item = balancer.GetResource();

            item.Uri.Should().Be(new Uri("http://base.one"));
            item.PercentMemoryUsec = .8;

            item = balancer.GetResource();
            item.Uri.Should().Be(new Uri("http://base.three"));

            balancer.GetResource().Should().BeSameAs(item);
        }
        public void OnlyItemReturnedEveryTime()
        {
            var balancer = new UpdateableAdaptiveLoadBalancer <Scoreable>(s => (int)(s.PercentMemoryUsec * 100));

            balancer.Resources.Add(new Scoreable(new Uri("http://only.one"))
            {
                PercentMemoryUsec = .75
            });

            var sameAsFirst = balancer.GetResource();

            sameAsFirst.Should().NotBeNull();

            foreach (var _ in Enumerable.Range(1, 100))
            {
                balancer.GetResource().Should().Be(sameAsFirst);
            }
        }
        public void NothingReturnedWhenNoEntries()
        {
            var balancer = new UpdateableAdaptiveLoadBalancer <Scoreable>(s => (int)(s.PercentMemoryUsec * 100));

            balancer.GetResource().Should().BeNull();
        }