示例#1
0
        public async Task GetThread_Handles404NotFound()
        {
            var mockClient = CreateMockClient(HttpStatusCode.NotFound, null);

            var result = await YotsubaApi.GetThread("a", 1234, mockClient);

            Assert.IsNotNull(result);
            Assert.AreEqual(ResponseType.NotFound, result.ResponseType);
        }
示例#2
0
        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);
        }
示例#3
0
        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
        }
示例#4
0
        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]);
        }
示例#5
0
        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>()
                );
        }
示例#6
0
        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>()
                );
        }
示例#7
0
        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);
        }