Skip to content

Commit

Permalink
Merge pull request #148 from vosmiic/extend-unit-tests
Browse files Browse the repository at this point in the history
Extend unit tests
  • Loading branch information
vosmiic committed Aug 19, 2024
2 parents c25d680 + c29a226 commit ce63a3e
Show file tree
Hide file tree
Showing 14 changed files with 1,181 additions and 305 deletions.
351 changes: 351 additions & 0 deletions jellyfin-ani-sync-unit-tests/GeneralFlowTests.cs

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions jellyfin-ani-sync-unit-tests/HelperTests/AnimeListHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using jellyfin_ani_sync.Helpers;
using NUnit.Framework;

namespace jellyfin_ani_sync_unit_tests.HelperTests;

public class AnimeListHelperTests {
[Test]
public void GetCorrectAniDbSeasonCount() {
int aniDbId = 1;
string tvdbId = "abc123";
AnimeListHelpers.AnimeListXml animeListXml = new AnimeListHelpers.AnimeListXml {
Anime = new List<AnimeListHelpers.AnimeListAnime> {
new() {
Anidbid = aniDbId.ToString(),
Tvdbid = tvdbId
},
new() {
Anidbid = aniDbId.ToString(),
Tvdbid = tvdbId
},
new() {
Anidbid = aniDbId.ToString(),
Tvdbid = String.Empty
}
}
};
var returned = AnimeListHelpers.ListAllSeasonOfAniDbSeries(aniDbId, animeListXml);
Assert.IsTrue(returned != null);
Assert.IsTrue(returned.Count() == 2);
}

[Test]
public void GetCorrectAniDbSeason() {
int aniDbId = 1;
string tvdbId = "abc123";
AnimeListHelpers.AnimeListXml animeListXml = new AnimeListHelpers.AnimeListXml {
Anime = new List<AnimeListHelpers.AnimeListAnime> {
new() {
Anidbid = aniDbId.ToString(),
Tvdbid = tvdbId
},
new() {
Anidbid = aniDbId.ToString(),
Tvdbid = tvdbId
},
new() {
Anidbid = aniDbId.ToString(),
Tvdbid = String.Empty
}
}
};
var returned = AnimeListHelpers.GetAniDbSeason(aniDbId, animeListXml);
Assert.IsTrue(returned != null);
Assert.IsTrue(returned.Anidbid == aniDbId.ToString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using jellyfin_ani_sync.Helpers;
using NUnit.Framework;

namespace jellyfin_ani_sync_unit_tests.HelperTests;

public class AnimeOfflineDatabaseHelperTests {
private HttpClient _httpClient;

private void Setup(List<Helpers.HttpCall> httpCalls) {
Helpers.MockHttpCalls(httpCalls, ref _httpClient);
}

[Test]
public async Task DeserializeMetadataCall() {
Setup(new List<Helpers.HttpCall> {
new() {
RequestMethod = HttpMethod.Get,
RequestUrlMatch = url => url.EndsWith("ids"),
ResponseCode = HttpStatusCode.OK,
ResponseContent = JsonSerializer.Serialize(new AnimeOfflineDatabaseHelpers.OfflineDatabaseResponse {
AniDb = 1,
Anilist = 1,
Kitsu = 1,
MyAnimeList = 1
})
}
});

AnimeOfflineDatabaseHelpers.OfflineDatabaseResponse? result = await AnimeOfflineDatabaseHelpers.GetProviderIdsFromMetadataProvider(_httpClient, 1, AnimeOfflineDatabaseHelpers.Source.Myanimelist);
Assert.IsTrue(result != null);
Assert.IsTrue(result.AniDb == 1);
Assert.IsTrue(result.Anilist == 1);
Assert.IsTrue(result.Kitsu == 1);
Assert.IsTrue(result.MyAnimeList == 1);
}
}
Loading

0 comments on commit ce63a3e

Please sign in to comment.