public async Task Get(long unixEpoch, int page = 1) { var throttleException = _throttle.IfICanNotMakeRequestsWhy(); if (throttleException.HasValue) { Console.WriteLine(throttleException.Value); } else { WriteQuestions(await _questions.GetSince(unixEpoch, page)); } }
public async Task WhenBackoffPeriodIsSetItIsRespected() { var jsonQuestions = CreateJsonizedEmptyStackexchangeWrapper(300, 250, 2); var web = new FakeWebRequester(CreateGzippedStringResponse(jsonQuestions), CreateGzippedStringResponse("This Shouldn't be reached", 500)); var getter = new RecentQuestionsGetter(new JsonStore(new DictionaryStore()), web); await getter.GetSince(0); var noValue = await getter.GetSince(0); Assert.IsFalse(noValue.HasValue); Assert.AreEqual(1, web.NextResponses.Count); }
public async Task WhenThrottleViolationRecentQuestionGetterReturnsNoValueAndPreventsRetrying() { var throttleViolation = CreateJsonizedEmptyStackexchangeWrapper(300, 250); var web = new FakeWebRequester(CreateGzippedStringResponse(throttleViolation, 400), CreateGzippedStringResponse("This Shouldn't be reached", 500)); var getter = new RecentQuestionsGetter(new JsonStore(new DictionaryStore()), web); var noValue = await getter.GetSince(0); var noValueToo = await getter.GetSince(0); Assert.IsFalse(noValue.HasValue); Assert.IsFalse(noValueToo.HasValue); Assert.AreEqual(1, web.NextResponses.Count); }
public async Task AggregateIntegrationTest() { var store = new JsonStore( new HardDrive(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\StackoverflowRecentQuestions")); var web = new WebRequester(); var getter = new RecentQuestionsGetter(store, web); QuestionsWhenUnrestricted = await HandleStackexchangeThrottle(async() => await getter.GetSince(0), store); QuestionsWhenUnrestrictedPage2 = await HandleStackexchangeThrottle(async() => await getter.GetSince(0, 2), store); QuestionsWithEitherJavaOrCSharpSince2017 = await HandleStackexchangeThrottle( async() => await getter.GetSince(Year2017, 1, "stackoverflow", new[] { "c#", "java" }), store); TestsPassed = true; var methods = GetType().GetMethods(); foreach (var method in methods) { if (method.Name.IndexOf("Test") == 0) { await AggregateResult(method.Name.Substring(4), web); } } if (!TestsPassed) { Assert.Fail(TestsFailedString); } }
public async Task WhenTheFirstApiCallIsMadeTheQueryResetTimeIsSetAndEnforced() { var jsonQuestions = CreateJsonizedEmptyStackexchangeWrapper(300, 299); var jsonQuestions2 = CreateJsonizedEmptyStackexchangeWrapper(300, 0); var web = new FakeWebRequester(CreateGzippedStringResponse(jsonQuestions), CreateGzippedStringResponse(jsonQuestions2), CreateGzippedStringResponse("This Shouldn't be reached", 500)); var getter = new RecentQuestionsGetter(new JsonStore(new DictionaryStore()), web); await getter.GetSince(0); var questions = await getter.GetSince(0); var noValue = await getter.GetSince(0); Assert.IsTrue(questions.HasValue); Assert.IsFalse(noValue.HasValue); Assert.AreEqual(1, web.NextResponses.Count); }
public async Task WhenUnthrottledRecentQuestionGetterReturnsQuestions() { var jsonQuestions = CreateJsonizedEmptyStackexchangeWrapper(300, 250); var web = new FakeWebRequester(CreateGzippedStringResponse(jsonQuestions)); var getter = new RecentQuestionsGetter(new JsonStore(new DictionaryStore()), web); var questions = await getter.GetSince(0); Assert.IsTrue(questions.HasValue); }