public async Task GetArchive_Handles304NotModified() { var mockClient = CreateMockClient(HttpStatusCode.NotModified, null); var result = await YotsubaApi.GetArchive("a", mockClient); Assert.IsNotNull(result); Assert.AreEqual(ResponseType.NotModified, result.ResponseType); }
public async Task GetArchive_ParsesResponseCorrectly() { const string testResponse = @"[74737273,74743759,74747358]"; var mockClient = CreateMockClient(HttpStatusCode.OK, testResponse); var result = await YotsubaApi.GetArchive("a", mockClient); Assert.AreEqual(ResponseType.Ok, result.ResponseType); Assert.IsNotNull(result.Data); Assert.AreEqual(3, result.Data.Length); Assert.AreEqual(74737273UL, result.Data[0]); Assert.AreEqual(74743759UL, result.Data[1]); Assert.AreEqual(74747358UL, result.Data[2]); }
public async Task GetArchive_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.GetArchive("a", client, baseDateTimeOffset); mockHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Headers.IfModifiedSince == baseDateTimeOffset ), ItExpr.IsAny <CancellationToken>() ); }
public async Task GetArchive_CallsCorrectEndpoint() { const string board = "a"; var mockHandler = CreateMockClientHandler(HttpStatusCode.NotFound, null); await YotsubaApi.GetArchive(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}/archive.json") ), ItExpr.IsAny <CancellationToken>() ); }