public ShortenUrlAsync ( MyCommon shortenerType, |
||
shortenerType | MyCommon | 使用する短縮URLサービス |
srcUri | 短縮するURL | |
return | Task |
public async Task ShortenUrlAsync_UxnuUrlTest() { var handler = new HttpMessageHandlerMock(); using (var http = new HttpClient(handler)) { var shortUrl = new ShortUrl(http); handler.Enqueue(x => { Assert.Equal(HttpMethod.Get, x.Method); Assert.Equal("https://ux.nu/api/short?format=plain&url=http:%2F%2Fexample.com%2Fhogehoge", x.RequestUri.AbsoluteUri); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(Encoding.UTF8.GetBytes("https://ux.nu/hoge")), }); }); Assert.Equal(new Uri("https://ux.nu/hoge"), await shortUrl.ShortenUrlAsync(MyCommon.UrlConverter.Uxnu, new Uri("http://example.com/hogehoge"))); Assert.Equal(0, handler.QueueCount); } }
public async Task ShortenUrlAsync_TinyUrlTest() { var handler = new HttpMessageHandlerMock(); using (var http = new HttpClient(handler)) { var shortUrl = new ShortUrl(http); handler.Enqueue(async x => { Assert.Equal(HttpMethod.Post, x.Method); Assert.Equal(new Uri("https://tinyurl.com/api-create.php"), x.RequestUri); Assert.Equal("url=http%3A%2F%2Fexample.com%2Fhogehogehoge", await x.Content.ReadAsStringAsync()); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(Encoding.UTF8.GetBytes("http://tinyurl.com/hoge")), }); }); Assert.Equal(new Uri("https://tinyurl.com/hoge"), await shortUrl.ShortenUrlAsync(MyCommon.UrlConverter.TinyUrl, new Uri("http://example.com/hogehogehoge"))); Assert.Equal(0, handler.QueueCount); } }
public async Task ShortenUrlAsync_UxnuUrlTest() { var handler = new HttpMessageHandlerMock(); using (var http = new HttpClient(handler)) { var shortUrl = new ShortUrl(http); handler.Enqueue(x => { Assert.Equal(HttpMethod.Get, x.Method); Assert.Equal("http://ux.nu/api/short?format=plain&url=http://example.com/hogehoge", x.RequestUri.ToString()); return new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(Encoding.UTF8.GetBytes("http://ux.nu/hoge")), }; }); Assert.Equal(new Uri("http://ux.nu/hoge"), await shortUrl.ShortenUrlAsync(MyCommon.UrlConverter.Uxnu, new Uri("http://example.com/hogehoge"))); Assert.Equal(0, handler.QueueCount); } }
public async Task ShortenUrlAsync_TinyUrlTest() { var handler = new HttpMessageHandlerMock(); using (var http = new HttpClient(handler)) { var shortUrl = new ShortUrl(http); handler.Enqueue(async x => { Assert.Equal(HttpMethod.Post, x.Method); Assert.Equal(new Uri("http://tinyurl.com/api-create.php"), x.RequestUri); Assert.Equal("url=http%3A%2F%2Fexample.com%2Fhogehoge", await x.Content.ReadAsStringAsync()); return new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(Encoding.UTF8.GetBytes("http://tinyurl.com/hoge")), }; }); Assert.Equal(new Uri("http://tinyurl.com/hoge"), await shortUrl.ShortenUrlAsync(MyCommon.UrlConverter.TinyUrl, new Uri("http://example.com/hogehoge"))); Assert.Equal(0, handler.QueueCount); } }