public async Task GetBoard_Handles304NotModified() { var mockClient = CreateMockClient(HttpStatusCode.NotModified, null); var result = await YotsubaApi.GetBoard("a", mockClient); Assert.IsNotNull(result); Assert.AreEqual(ResponseType.NotModified, result.ResponseType); }
public async Task GetBoard_SetsNotModifiedSinceHeader() { var mockHandler = CreateMockClientHandler(HttpStatusCode.NotModified, null); var client = new HttpClient(mockHandler.Object); var baseDateTimeOffset = DateTimeOffset.Parse("12/3/2007 12:00:00 AM -08:00"); await YotsubaApi.GetBoard("a", client, baseDateTimeOffset); mockHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Headers.IfModifiedSince == baseDateTimeOffset ), ItExpr.IsAny <CancellationToken>() ); }
public async Task GetBoard_CallsCorrectEndpoint() { const string board = "a"; var mockHandler = CreateMockClientHandler(HttpStatusCode.NotFound, null); await YotsubaApi.GetBoard(board, new HttpClient(mockHandler.Object)); mockHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri == new Uri($"https://a.4cdn.org/{board}/threads.json") ), ItExpr.IsAny <CancellationToken>() ); }
public async Task GetBoard_ParsesResponseCorrectly() { const string testResponse = @"[{""page"":1,""threads"":[{""no"":51971506,""last_modified"":1576181967,""replies"":1},{""no"":74912296,""last_modified"":1582802960,""replies"":22}]}]"; var mockClient = CreateMockClient(HttpStatusCode.OK, testResponse); var result = await YotsubaApi.GetBoard("a", mockClient); Assert.AreEqual(ResponseType.Ok, result.ResponseType); Assert.IsNotNull(result.Data); Assert.AreEqual(1, result.Data.Length); var page = result.Data[0]; Assert.AreEqual(1U, page.PageNumber); Assert.AreEqual(2, page.Threads.Length); Assert.AreEqual(51971506UL, page.Threads[0].ThreadNumber); Assert.AreEqual(1576181967UL, page.Threads[0].LastModified); }