using System.Threading;
using System.Threading.Tasks;
using System.Web;
+using OpenTween.Models;
using Xunit;
namespace OpenTween.Thumbnail.Services
[Fact]
public void ParsePostJson_Test()
{
- var json = @"{
- ""meta"": { ""status"": 200, ""msg"": ""OK"" },
- ""response"": {
- ""blog"": { },
- ""posts"": [
- {
- ""id"": 1234567,
- ""post_url"": ""http://example.com/post/1234567"",
- ""type"": ""photo"",
- ""photos"": [
- {
- ""caption"": """",
- ""alt_sizes"": [
- {
- ""width"": 1280,
- ""height"": 722,
- ""url"": ""http://example.com/photo/1280/1234567/1/tumblr_hogehoge""
- }
- ]
- }
- ]
- }
- ]
- }
-}";
+ var json = """
+ {
+ "meta": { "status": 200, "msg": "OK" },
+ "response": {
+ "blog": { },
+ "posts": [
+ {
+ "id": 1234567,
+ "post_url": "http://example.com/post/1234567",
+ "type": "photo",
+ "photos": [
+ {
+ "caption": "",
+ "alt_sizes": [
+ {
+ "width": 1280,
+ "height": 722,
+ "url": "http://example.com/photo/1280/1234567/1/tumblr_hogehoge"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ }
+ """;
var jsonBytes = Encoding.UTF8.GetBytes(json);
var thumbs = Tumblr.ParsePhotoPostJson(jsonBytes);
{
new ThumbnailInfo
{
- ImageUrl = "http://example.com/post/1234567",
- ThumbnailUrl = "http://example.com/photo/1280/1234567/1/tumblr_hogehoge",
+ MediaPageUrl = "http://example.com/post/1234567",
+ ThumbnailImageUrl = "http://example.com/photo/1280/1234567/1/tumblr_hogehoge",
TooltipText = null,
},
};
var query = HttpUtility.ParseQueryString(x.RequestUri.Query);
- Assert.Equal(ApplicationSettings.TumblrConsumerKey, query["api_key"]);
+ Assert.Equal("fake_api_key", query["api_key"]);
Assert.Equal("1234567", query["id"]);
return new HttpResponseMessage(HttpStatusCode.OK)
{
- Content = new StringContent(@"{
- ""meta"": { ""status"": 200, ""msg"": ""OK"" },
- ""response"": { ""blog"": { }, ""posts"": { } }
-}"),
+ Content = new StringContent("""
+ {
+ "meta": { "status": 200, "msg": "OK" },
+ "response": { "blog": { }, "posts": { } }
+ }
+ """),
};
});
using (var http = new HttpClient(handler))
{
- var service = new Tumblr(http);
+ var service = new Tumblr(ApiKey.Create("fake_api_key"), http);
var url = "http://hoge.tumblr.com/post/1234567/tetetete";
- var thumb = await service.GetThumbnailInfoAsync(url, null, CancellationToken.None)
- .ConfigureAwait(false);
+ await service.GetThumbnailInfoAsync(url, new PostClass(), CancellationToken.None);
}
Assert.Equal(0, handler.QueueCount);
var query = HttpUtility.ParseQueryString(x.RequestUri.Query);
- Assert.Equal(ApplicationSettings.TumblrConsumerKey, query["api_key"]);
+ Assert.Equal("fake_api_key", query["api_key"]);
Assert.Equal("1234567", query["id"]);
return new HttpResponseMessage(HttpStatusCode.OK)
{
- Content = new StringContent(@"{
- ""meta"": { ""status"": 200, ""msg"": ""OK"" },
- ""response"": { ""blog"": { }, ""posts"": { } }
-}"),
+ Content = new StringContent("""
+ {
+ "meta": { "status": 200, "msg": "OK" },
+ "response": { "blog": { }, "posts": { } }
+ }
+ """),
};
});
using (var http = new HttpClient(handler))
{
- var service = new Tumblr(http);
+ var service = new Tumblr(ApiKey.Create("fake_api_key"), http);
// Tumblrのカスタムドメイン名を使ってるっぽいURL
var url = "http://tumblr.example.com/post/1234567/tetetete";
- var thumb = await service.GetThumbnailInfoAsync(url, null, CancellationToken.None)
- .ConfigureAwait(false);
+ await service.GetThumbnailInfoAsync(url, new PostClass(), CancellationToken.None);
}
Assert.Equal(0, handler.QueueCount);
}
+
+ [Fact]
+ public async Task GetThumbnailInfoAsync_ApiKeyErrorTest()
+ {
+ var handler = new HttpMessageHandlerMock();
+
+ using var http = new HttpClient(handler);
+ var service = new Tumblr(ApiKey.Create("%e%INVALID_API_KEY"), http);
+
+ var url = "http://hoge.tumblr.com/post/1234567/tetetete";
+ var thumb = await service.GetThumbnailInfoAsync(url, new PostClass(), CancellationToken.None);
+ Assert.Null(thumb);
+ }
}
}