using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
+using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
+using Moq;
+using OpenTween.Models;
using Xunit;
using Xunit.Extensions;
{
class TestTinami : Tinami
{
- public string FakeXml { get; set; }
+ public string FakeXml { get; set; } = "";
- public TestTinami(string pattern, string replacement)
- : base(pattern, replacement)
+ public TestTinami()
+ : base(null)
{
}
- protected override XDocument FetchContentInfoApi(string url)
- {
- Assert.True(Regex.IsMatch(url, @"http://api\.tinami\.com/content/info\?cont_id=.+&api_key=.+"));
-
- return XDocument.Parse(this.FakeXml);
- }
+ protected override Task<XDocument> FetchContentInfoApiAsync(string contentId, CancellationToken token)
+ => Task.FromResult(XDocument.Parse(this.FakeXml));
}
[Fact]
public async Task ApiTest()
{
- var service = new TestTinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$",
- "http://api.tinami.com/content/info?cont_id=${ContentId}&api_key=" + ApplicationSettings.TINAMIApiKey);
+ var service = new TestTinami();
service.FakeXml = @"<?xml version='1.0' encoding='utf-8' ?>
<rsp stat='ok'>
</image>
</content>
</rsp>";
- var thumbinfo = await service.GetThumbnailInfoAsync("http://www.tinami.com/view/12345", null, CancellationToken.None);
+ var thumbinfo = await service.GetThumbnailInfoAsync("http://www.tinami.com/view/12345", new PostClass(), CancellationToken.None);
Assert.NotNull(thumbinfo);
- Assert.Equal("http://www.tinami.com/view/12345", thumbinfo.ImageUrl);
- Assert.Equal("http://img.tinami.com/hogehoge_150.gif", thumbinfo.ThumbnailUrl);
+ Assert.Equal("http://www.tinami.com/view/12345", thumbinfo!.MediaPageUrl);
+ Assert.Equal("http://img.tinami.com/hogehoge_150.gif", thumbinfo.ThumbnailImageUrl);
Assert.Equal("説明", thumbinfo.TooltipText);
}
[Fact]
public async Task ApiErrorTest()
{
- var service = new TestTinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$",
- "http://api.tinami.com/content/info?cont_id=${ContentId}&api_key=" + ApplicationSettings.TINAMIApiKey);
+ var service = new TestTinami();
service.FakeXml = @"<?xml version='1.0' encoding='utf-8'?>
<rsp stat='user_only'>
<err msg='この作品は登録ユーザー限定の作品です。'/>
</rsp>";
- var thumbinfo = await service.GetThumbnailInfoAsync("http://www.tinami.com/view/12345", null, CancellationToken.None);
+ var thumbinfo = await service.GetThumbnailInfoAsync("http://www.tinami.com/view/12345", new PostClass(), CancellationToken.None);
Assert.Null(thumbinfo);
}