-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b180b1
commit 40ebde0
Showing
19 changed files
with
425 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json; | ||
using Xunit.Abstractions; | ||
|
||
namespace Totoro.Plugins.Anime.AnimeSaturn.Tests; | ||
|
||
[ExcludeFromCodeCoverage] | ||
public class CatalogTests | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
private readonly JsonSerializerOptions _searializerOption = new() { WriteIndented = true }; | ||
|
||
public CatalogTests(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Theory] | ||
[InlineData("hyouka")] | ||
public async Task Search(string query) | ||
{ | ||
// arrange | ||
var sut = new Catalog(); | ||
|
||
// act | ||
var result = await sut.Search(query).ToListAsync(); | ||
|
||
Assert.NotEmpty(result); | ||
foreach (var item in result) | ||
{ | ||
_output.WriteLine(JsonSerializer.Serialize(item, item.GetType(), _searializerOption)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
58 changes: 58 additions & 0 deletions
58
Totoro.Plugins.Anime.AnimeSaturn.Tests/StreamProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json; | ||
using Flurl; | ||
using Xunit.Abstractions; | ||
|
||
namespace Totoro.Plugins.Anime.AnimeSaturn.Tests; | ||
|
||
[ExcludeFromCodeCoverage] | ||
public class StreamProviderTests | ||
{ | ||
public const string Hyouka = "hyouka"; | ||
|
||
private readonly ITestOutputHelper _output; | ||
private readonly JsonSerializerOptions _searializerOption = new() { WriteIndented = true }; | ||
private readonly Dictionary<string, string> _urlMap = new() | ||
{ | ||
{ Hyouka, Url.Combine(Config.Url, "/anime/Hyouka-aaaaaa") } | ||
}; | ||
private readonly bool _allEpisodes = false; | ||
|
||
public StreamProviderTests(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Theory] | ||
[InlineData(Hyouka, 22)] | ||
public async Task GetNumberOfEpisodes(string key, int expected) | ||
{ | ||
// arrange | ||
var url = _urlMap[key]; | ||
var sut = new StreamProvider(); | ||
|
||
// act | ||
var actual = await sut.GetNumberOfStreams(url); | ||
|
||
// assert | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData(Hyouka)] | ||
public async Task GetStreams(string key) | ||
{ | ||
// arrange | ||
var url = _urlMap[key]; | ||
var sut = new StreamProvider(); | ||
|
||
// act | ||
var result = await sut.GetStreams(url, _allEpisodes ? Range.All : 1..1).ToListAsync(); | ||
|
||
Assert.NotEmpty(result); | ||
foreach (var item in result) | ||
{ | ||
_output.WriteLine(JsonSerializer.Serialize(item, item.GetType(), _searializerOption)); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Totoro.Plugins.Anime.AnimeSaturn.Tests/Totoro.Plugins.Anime.AnimeSaturn.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Platforms>x64</Platforms> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" /> | ||
<PackageReference Include="xunit" Version="2.5.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Totoro.Plugins.Anime.AnimeSaturn\Totoro.Plugins.Anime.AnimeSaturn.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json.Nodes; | ||
using System.Threading.Tasks; | ||
using Flurl; | ||
using Flurl.Http; | ||
using Totoro.Plugins.Anime.Contracts; | ||
using Totoro.Plugins.Contracts.Optional; | ||
|
||
namespace Totoro.Plugins.Anime.AnimeSaturn; | ||
|
||
internal class Catalog : IAnimeCatalog | ||
{ | ||
class SearchResult : ICatalogItem, IHaveImage | ||
{ | ||
required public string Title { get; init; } | ||
required public string Url { get; init; } | ||
required public string Image { get; init; } | ||
} | ||
|
||
public async IAsyncEnumerable<ICatalogItem> Search(string query) | ||
{ | ||
var response = await Config.Url | ||
.AppendPathSegment("/index.php") | ||
.SetQueryParams(new | ||
{ | ||
search = 1, | ||
key = query | ||
}) | ||
.GetStringAsync(); | ||
|
||
foreach (var item in JsonNode.Parse(response)?.AsArray() ?? new JsonArray()) | ||
{ | ||
var title = item!["name"]!.ToString(); | ||
var image = item!["image"]!.ToString(); | ||
var link = Url.Combine(Config.Url, "anime", item!["link"]!.ToString()); | ||
|
||
yield return new SearchResult | ||
{ | ||
Title = title, | ||
Image = image, | ||
Url = link | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Totoro.Plugins.Anime.AnimeSaturn; | ||
|
||
internal class Config | ||
{ | ||
internal static string Url { get; set; } = "https://www.animesaturn.tv/"; | ||
} |
Oops, something went wrong.