Skip to content

Commit

Permalink
System.Text.Json migration and .NET 8 update
Browse files Browse the repository at this point in the history
- Replaced Newtonsoft.Json with System.Text.Json
- Added type converters for proper JSON handling
- Updated to .NET 8.0
- Improved async implementation
- Fixed thumbnail/image URLs for load balancing support
  • Loading branch information
SylveonDeko committed Nov 15, 2024
1 parent aeb71eb commit 6a4991d
Show file tree
Hide file tree
Showing 20 changed files with 1,121 additions and 644 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Sylveon
Copyright (c) 2024 SylveonDeko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 16 additions & 17 deletions NHentaiAPI.Tests/BaseUnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NHentaiAPI.Tests
namespace NHentaiAPI.Tests;

public class BaseUnitTest
{
public class BaseUnitTest
{
protected NHentaiClient NHentaiClient { get; private set; }
protected NHentaiClient NHentaiClient { get; private set; }

[TestInitialize]
public void InitializeTest()
{
NHentaiClient = new TestNHentaiClient("a", new Dictionary<string, string>());
}
[TestInitialize]
public void InitializeTest()
{
NHentaiClient = new TestNHentaiClient("a", new Dictionary<string, string>());
}
}

public class TestNHentaiClient : NHentaiClient
public class TestNHentaiClient : NHentaiClient
{
public TestNHentaiClient(string userAgent, Dictionary<string, string> cookies = null) : base(userAgent, cookies)
{
#region Urls
}

//protected override string ApiRootUrl => "https://nhent.ai";
#region Urls

#endregion
//protected override string ApiRootUrl => "https://nhent.ai";

public TestNHentaiClient(string userAgent, Dictionary<string, string> cookies = null) : base(userAgent, cookies)
{
}
}
#endregion
}
30 changes: 15 additions & 15 deletions NHentaiAPI.Tests/NHentaiAPI.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FlareSolverrSharp" Version="2.2.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Refit" Version="6.3.2" />
<PackageReference Include="Refit.Newtonsoft.Json" Version="6.3.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3"/>
<PackageReference Include="MSTest.TestFramework" Version="3.6.3"/>
<PackageReference Include="Refit" Version="8.0.0"/>
<PackageReference Include="Refit.Newtonsoft.Json" Version="8.0.0"/>
<PackageReference Include="System.Text.Json" Version="9.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NHentaiAPI\NHentaiAPI.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NHentaiAPI\NHentaiAPI.csproj"/>
</ItemGroup>

</Project>
76 changes: 38 additions & 38 deletions NHentaiAPI.Tests/NHentaiBookUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NHentaiAPI.Tests
namespace NHentaiAPI.Tests;

/// <summary>
/// see :
/// https://github.com/andy840119/NHentaiSharp/blob/master/NHentaiSharp.UnitTests/Program.cs
/// </summary>
[TestClass]
public class NHentaiBookUnitTest : BaseUnitTest
{
/// <summary>
/// see :
/// https://github.com/andy840119/NHentaiSharp/blob/master/NHentaiSharp.UnitTests/Program.cs
/// Get book detail
/// https://nhentai.net/g/161194/
/// </summary>
[TestClass]
public class NHentaiBookUnitTest : BaseUnitTest
/// <returns></returns>
[TestMethod]
public async Task TestBookResult()
{
/// <summary>
/// Get book detail
/// https://nhentai.net/g/161194/
/// </summary>
/// <returns></returns>
[TestMethod]
public async Task TestBookResult()
{
// https://nhentai.net/api/gallery/161194
var result = await NHentaiClient.GetBookAsync(161194);
// https://nhentai.net/api/gallery/161194
var result = await NHentaiClient.GetBookAsync(161194);

Assert.AreEqual("[ユイザキカズヤ] つなかん。 (COMIC ポプリクラブ 2013年8月号) [英訳]", result.Title.Japanese);
Assert.AreEqual("Tsuna-kan. | Tuna Can", result.Title.Pretty);
Assert.AreEqual("[Yuizaki Kazuya] Tsuna-kan. | Tuna Can (COMIC Potpourri Club 2013-08) [English] [PSYN]", result.Title.English);
Assert.AreEqual("160413", result.UploadDate.ToString("yyMMdd"));
Assert.AreEqual(true, result.Tags.Any(x => x.Id == 19440));
Assert.AreEqual(17, result.NumPages);
Assert.AreEqual(17, result.Images.Pages.Count);
Assert.AreEqual(161194, result.Id);
}
Assert.AreEqual("[ユイザキカズヤ] つなかん。 (COMIC ポプリクラブ 2013年8月号) [英訳]", result.Title.Japanese);
Assert.AreEqual("Tsuna-kan. | Tuna Can", result.Title.Pretty);
Assert.AreEqual("[Yuizaki Kazuya] Tsuna-kan. | Tuna Can (COMIC Potpourri Club 2013-08) [English] [PSYN]",
result.Title.English);
Assert.AreEqual("160413", result.UploadDate.ToString("yyMMdd"));
Assert.AreEqual(true, result.Tags.Any(x => x.Id == 19440));
Assert.AreEqual(17, result.NumPages);
Assert.AreEqual(17, result.Images.Pages.Count);
Assert.AreEqual(161194, result.Id);
}

/// <summary>
/// Get recommend book
/// https://nhentai.net/g/161194/
/// </summary>
/// <returns></returns>
[TestMethod]
public async Task TestBookRecommendResult()
{
// https://nhentai.net/api/gallery/161194/related
var result = await NHentaiClient.GetBookRecommendAsync(161194);
/// <summary>
/// Get recommend book
/// https://nhentai.net/g/161194/
/// </summary>
/// <returns></returns>
[TestMethod]
public async Task TestBookRecommendResult()
{
// https://nhentai.net/api/gallery/161194/related
var result = await NHentaiClient.GetBookRecommendAsync(161194);

// At least one recommend
Assert.AreEqual(true, result.Result.Any());
}
// At least one recommend
Assert.AreEqual(true, result.Result.Any());
}
}
}
Loading

0 comments on commit 6a4991d

Please sign in to comment.