public async Task GetThread_Handles304NotModified() { var mockClient = CreateMockClient(HttpStatusCode.NotModified, null); var result = await YotsubaApi.GetThread("a", 1234, mockClient); Assert.IsNotNull(result); Assert.AreEqual(ResponseType.NotModified, result.ResponseType); }
public async Task GetThread_ParsesResponseCorrectly() { const string testResponse = @"{ ""posts"": [ { ""no"": 51971506, ""sticky"": 1, ""closed"": 1, ""now"": ""12/20/15(Sun)20:03:52"", ""name"": ""Anonymous"", ""com"": ""test"", ""filename"": ""RMS"", ""ext"": "".png"", ""w"": 450, ""h"": 399, ""tn_w"": 250, ""tn_h"": 221, ""tim"": 1450659832892, ""time"": 1450659832, ""md5"": ""cEeDnXfLWSsu3+A/HIZkuw=="", ""fsize"": 299699, ""resto"": 0, ""capcode"": ""mod"", ""semantic_url"": ""the-g-wiki"", ""replies"": 1, ""images"": 1, ""unique_ips"": 2 } ] }" ; var mockClient = CreateMockClient(HttpStatusCode.OK, testResponse); var result = await YotsubaApi.GetThread("a", 1234, mockClient); Assert.AreEqual(ResponseType.Ok, result.ResponseType); Assert.IsNotNull(result.Data); Assert.AreEqual(1, result.Data.Posts.Length); var opPost = result.Data.Posts[0]; Assert.AreEqual(51971506UL, opPost.PostNumber); Assert.IsTrue(opPost.Sticky); Assert.IsTrue(opPost.Closed); // put more here. i'm lazy }
public async Task GetThread_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.GetThread("a", 1234, client, baseDateTimeOffset); mockHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Headers.IfModifiedSince == baseDateTimeOffset ), ItExpr.IsAny <CancellationToken>() ); }
public async Task GetThread_CallsCorrectEndpoint() { const string board = "a"; const int threadNumber = 1234; var mockHandler = CreateMockClientHandler(HttpStatusCode.NotFound, null); await YotsubaApi.GetThread(board, threadNumber, 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}/thread/{threadNumber}.json") ), ItExpr.IsAny <CancellationToken>() ); }