Exemplo n.º 1
0
        public void RemoveProxiesThatHaveBeenUsedManyTimes()
        {
            SeedFailThreshold(200);
            SeedProxyMaxCount(2);

            _proxyListReader.Read().Returns(new ProxyInfo[]
            {
                "192.168.1.1:8080",
                "192.168.1.2:8080",
                "192.168.1.3:8080"
            });

            var roundRobin = new ProxyReadingStrategyRoundRobin();

            _proxyReadingStrategy.Read(Arg.Any <IEnumerable <ProxyStatistics> >())
            .Returns(s => roundRobin.Read(s.Arg <IEnumerable <ProxyStatistics> >()));

            _repository.Read().Should().Be((ProxyInfo)"192.168.1.1:8080");
            _repository.Read().Should().Be((ProxyInfo)"192.168.1.2:8080");
            _repository.Read().Should().Be((ProxyInfo)"192.168.1.3:8080");

            _repository.CountSuccessRequest("192.168.1.2:8080");

            _repository.Read().Should().Be((ProxyInfo)"192.168.1.1:8080");
            _repository.Read().Should().Be((ProxyInfo)"192.168.1.2:8080");
            _repository.Read().Should().Be((ProxyInfo)"192.168.1.3:8080");

            _repository.CountSuccessRequest("192.168.1.2:8080");

            _repository.Read().Should().Be((ProxyInfo)"192.168.1.1:8080");
            _repository.Read().Should().Be((ProxyInfo)"192.168.1.3:8080");
        }
Exemplo n.º 2
0
        public void RetrievesTheProxyListOnceAllProxiesAreRemoved()
        {
            SeedFailThreshold(1);
            SeedProxyMaxCount(1);

            IEnumerable <ProxyInfo> proxyList1 = new ProxyInfo[]
            {
                "192.168.1.1:8080",
                "192.168.1.2:8080",
                "192.168.1.3:8080"
            };
            IEnumerable <ProxyInfo> proxyList2 = new ProxyInfo[]
            {
                "10.0.0.1:9000",
                "10.0.0.2:9000",
                "10.0.0.3:9000",
                "10.0.0.4:9000"
            };

            _proxyListReader.Read().Returns(proxyList1, proxyList2);

            var roundRobin = new ProxyReadingStrategyRoundRobin();

            _proxyReadingStrategy.Read(Arg.Any <IEnumerable <ProxyStatistics> >())
            .Returns(s => roundRobin.Read(s.Arg <IEnumerable <ProxyStatistics> >()));

            _repository.Read().Should().Be((ProxyInfo)"192.168.1.1:8080");
            _repository.Read().Should().Be((ProxyInfo)"192.168.1.2:8080");
            _repository.Read().Should().Be((ProxyInfo)"192.168.1.3:8080");

            _repository.CountSuccessRequest("192.168.1.1:8080");
            _repository.CountSuccessRequest("192.168.1.2:8080");
            _repository.CountSuccessRequest("192.168.1.3:8080");

            _repository.Read();

            _proxyReadingStrategy.Received(2).Reset();
            _proxyListReader.Received(2).Read();
        }