Esempio n. 1
0
        private IEnumerable <string> ProcessUrlBatch(ResourceBatch batch)
        {
            var urlData = new List <string>();

            foreach (var url in batch.Resources)
            {
                var dataTask = _webClient.GetWebData(url);
                //we could read the url ASYNChronously. But we already have a backing queue, so we'll process them in sequence
                urlData.Add(dataTask.Result);
            }
            return(urlData);
        }
Esempio n. 2
0
        public void Should_process_resources_on_Trigger()
        {
            var resourceBatch = new ResourceBatch {
                BatchId = 15, Resources = new[] { "url1", "url2" }
            };

            _queueMock.SetupSequence(m => m.Dequeue())
            .Returns(resourceBatch)
            .Returns((ResourceBatch)null);

            Task <string> stringTask = Task.Run(() => { Task.Delay(100); return("web data"); });

            _webClientMock.Setup(m => m.GetWebData(It.IsAny <string>())).Returns(stringTask);

            _app.Trigger();
            Thread.Sleep(1000); //wait for a second to allow the process to run

            _queueMock.Verify(m => m.Dequeue(), Times.Exactly(2));
            _webClientMock.Verify(m => m.GetWebData(It.IsAny <string>()), Times.Exactly(2));
        }