Skip to content

Commit

Permalink
Add ShouldDownloadPostMedia and ShouldDownloadPostMediaThroughGelboor…
Browse files Browse the repository at this point in the history
…u tests
  • Loading branch information
ImoutoChan committed Jan 4, 2024
1 parent 28a613e commit a7e532d
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions Imouto.BooruParser.Tests/Loaders/DanbooruLoaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
using System.Net;
using FluentAssertions;
using Imouto.BooruParser.Implementations;
using Imouto.BooruParser.Implementations.Danbooru;
using Imouto.BooruParser.Tests.Loaders.Fixtures;
using Xunit;

namespace Imouto.BooruParser.Tests.Loaders;

public class DanbooruLoaderTests : IClassFixture<DanbooruApiLoaderFixture>
public class DanbooruLoaderTests : IClassFixture<DanbooruApiLoaderFixture>, IClassFixture<GelbooruApiLoaderFixture>
{
private readonly DanbooruApiLoaderFixture _loaderFixture;
private readonly GelbooruApiLoaderFixture? _gelbooruApiLoaderFixture;

private DanbooruLoaderTests(DanbooruApiLoaderFixture loaderFixture) => _loaderFixture = loaderFixture;
private DanbooruLoaderTests(
DanbooruApiLoaderFixture loaderFixture,
GelbooruApiLoaderFixture? gelbooruApiLoaderFixture = null)
{
_loaderFixture = loaderFixture;
_gelbooruApiLoaderFixture = gelbooruApiLoaderFixture;
}

public class GetPostAsyncMethod : DanbooruLoaderTests
{
public GetPostAsyncMethod(DanbooruApiLoaderFixture loaderFixture) : base(loaderFixture)
public GetPostAsyncMethod(
DanbooruApiLoaderFixture loaderFixture,
GelbooruApiLoaderFixture gelbooruApiLoaderFixture) : base(loaderFixture, gelbooruApiLoaderFixture)
{
}

[Fact]
public async Task ShouldDownloadPostMedia()
{
var loader = _loaderFixture.GetLoaderWithoutAuth();
var post = await loader.GetPostAsync(5773061);
var mediaUrl = post.OriginalUrl;

var client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "UnitTestBot/1.0");
var result = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, mediaUrl));
result.StatusCode.Should().Be(HttpStatusCode.OK);
}

[Fact]
public async Task ShouldDownloadPostMediaThroughGelbooru()
{
var loader = _loaderFixture.GetLoaderWithoutAuth();
var post = await loader.GetPostAsync(5773061);

var gelbooruLoader = _gelbooruApiLoaderFixture!.GetLoader();
var gelbooruPost = await gelbooruLoader.GetPostByMd5Async(post.Id.Md5Hash);
var mediaUrl = gelbooruPost!.OriginalUrl;

var client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "UnitTestBot/1.0");
var result = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, mediaUrl));
result.StatusCode.Should().Be(HttpStatusCode.OK);
}

[Fact]
public async Task ShouldReturnPostWithoutCredentials()
{
Expand Down

0 comments on commit a7e532d

Please sign in to comment.