public void GetItems_TwoWords_CheckQueueMaxSize() { var item = new Item(); const int operationDuraionMs = 250; config2 = CreateConfig(queueMaxSize2); stackExchange = new FakeStackExchangeHttpClient(async() => { await Task.Delay(operationDuraionMs); return(new List <Item>() { item }); }); service = new ParallelQueueKeywordsSearchService(stackExchange, config2); var words = new[] { "1", "2", "3", "4", "5" }; var timer = Stopwatch.StartNew(); var res = service.GetItems(words); timer.Stop(); var actual = Math.Ceiling(((double)words.Length) / queueMaxSize2) * operationDuraionMs; Assert.IsTrue(timer.ElapsedMilliseconds >= actual); Assert.IsTrue(timer.ElapsedMilliseconds < words.Length * operationDuraionMs); }
public void Init() { var factory = A.Fake <IHttpClientFactory>(); A.CallTo(() => factory.CreateClient(A <string> .Ignored)) .WithAnyArguments() .Returns(client); stackExchange = new StackExchangeHttpClient(factory); service = new ParallelQueueKeywordsSearchService(stackExchange, config2); }
public void GetItems_SimpleCase_Execution() { config2 = CreateConfig(queueMaxSize2); service = new ParallelQueueKeywordsSearchService(FakeStackExchangeHttpClient.CreateBase(), config2); var words = new[] { "1", "2", "3", "4", "5" }; var res = service.GetItems(words); Assert.AreEqual(words.Length * 2, res.Count); }
public void GetItems_Cancelation_CancelAllRequestAfterError() { var item = new Item(); service = new ParallelQueueKeywordsSearchService(stackExchange, config2); A.CallTo(() => stackExchange.GetItemsAsync(A <Keyword> .Ignored, A <CancellationToken> .Ignored)) .Throws <Exception>(); var words = new[] { "1", "2", "3", "4", "5" }; Assert.Throws <KeywordsSearchExecutionException>(() => { var res = service.GetItems(words); }); A.CallTo(() => stackExchange.GetItemsAsync(A <Keyword> .Ignored, A <CancellationToken> .Ignored)) .MustHaveHappenedTwiceOrLess(); }
public void Init() { stackExchange = A.Fake <IStackExchangeHttpClient>(); service = new ParallelQueueKeywordsSearchService(stackExchange, config2); }