Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PCL.Core.Test/IO/Storage/Cache/CacheServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task Cleanup()
{
if (_cache != null)
{
await _cache.StopAsync().ConfigureAwait(false);
await _cache.DisposeAsync().ConfigureAwait(false);
}

// Clean up the test directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task Cleanup()
{
if (_cache != null)
{
await _cache.StopAsync();
await _cache.DisposeAsync().ConfigureAwait(false);
}

if (Directory.Exists(_testCacheDir))
Expand Down
156 changes: 156 additions & 0 deletions PCL.Core.Test/Minecraft/ResourceProject/Comp/CompClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PCL.Core.Minecraft.ResourceProject.Comp.Clients;
using PCL.Core.Minecraft.ResourceProject.Comp.Models;
using PCL.Core.Minecraft.ResourceProject.Comp.Models.Enums;

namespace PCL.Core.Test.Minecraft.ResourceProject.Comp;

[TestClass]
public class CompClientTest
{
private static CurseForgeClient? _cf;
private static ModrinthClient? _mr;
private static bool _hasCfKey;
private static HttpClient _httpClient = null!;

[ClassInitialize]
public static void ClassInit(TestContext _)
{
_httpClient = new HttpClient();
var key = Environment.GetEnvironmentVariable("PCL_CURSEFORGE_API_KEY");
_hasCfKey = !string.IsNullOrEmpty(key);
if (_hasCfKey)
_cf = new CurseForgeClient(key!, _httpClient);
_mr = new ModrinthClient(httpClient: _httpClient);
}

[ClassCleanup]
public static void ClassCleanup()
{
_httpClient.Dispose();
}

// ===== CurseForge =====

[TestMethod]
public async Task CurseForge_SearchProjects_ReturnsResults()
{
if (!_hasCfKey) Assert.Inconclusive("PCL_CURSEFORGE_API_KEY not set");
var filter = new CompSearchFilter { Query = "sodium", Limit = 5 };
var result = await _cf!.SearchProjects(filter);
Assert.IsTrue(result.Hits.Count > 0);
Assert.IsTrue(result.TotalCount > 0);
Assert.IsFalse(string.IsNullOrEmpty(result.Hits[0].Name));
}

[TestMethod]
public async Task CurseForge_GetProject_ReturnsProject()
{
if (!_hasCfKey) Assert.Inconclusive("PCL_CURSEFORGE_API_KEY not set");
var project = await _cf!.GetProject("394468");
Assert.AreEqual("394468", project.Id);
Assert.AreEqual("CurseForge", project.Provider);
Assert.IsFalse(string.IsNullOrEmpty(project.Name));
Assert.IsFalse(string.IsNullOrEmpty(project.Summary));
}

[TestMethod]
public async Task CurseForge_GetProjectFiles_ReturnsFiles()
{
if (!_hasCfKey) Assert.Inconclusive("PCL_CURSEFORGE_API_KEY not set");
var files = await _cf!.GetProjectFiles("394468");
Assert.IsTrue(files.Count > 0);
Assert.IsFalse(string.IsNullOrEmpty(files[0].Id));
Assert.IsFalse(string.IsNullOrEmpty(files[0].DisplayName));
}

[TestMethod]
public async Task CurseForge_GetGameVersions_ReturnsVersions()
{
if (!_hasCfKey) Assert.Inconclusive("PCL_CURSEFORGE_API_KEY not set");
var versions = await _cf!.GetGameVersions();
Assert.IsTrue(versions.Count > 0);
Assert.IsTrue(versions.Any(v => v.Version == "1.20.1" || v.Version.Contains("1.20")));
}

[TestMethod]
public async Task CurseForge_GetCategories_ReturnsCategories()
{
if (!_hasCfKey) Assert.Inconclusive("PCL_CURSEFORGE_API_KEY not set");
var categories = await _cf!.GetCategories();
Assert.IsTrue(categories.Count > 0);
Assert.IsFalse(string.IsNullOrEmpty(categories[0].Name));
}

// ===== Modrinth =====

[TestMethod]
public async Task Modrinth_SearchProjects_ReturnsResults()
{
var filter = new CompSearchFilter { Query = "sodium", Limit = 5 };
var result = await _mr!.SearchProjects(filter);
Assert.IsTrue(result.Hits.Count > 0);
Assert.IsTrue(result.TotalCount > 0);
Assert.IsFalse(string.IsNullOrEmpty(result.Hits[0].Name));
}

[TestMethod]
public async Task Modrinth_GetProject_ReturnsProject()
{
var project = await _mr!.GetProject("sodium");
Assert.AreEqual("sodium", project.Slug);
Assert.AreEqual("Modrinth", project.Provider);
Assert.IsFalse(string.IsNullOrEmpty(project.Name));
}

[TestMethod]
public async Task Modrinth_GetProjectFiles_ReturnsFiles()
{
var files = await _mr!.GetProjectFiles("sodium");
Assert.IsTrue(files.Count > 0);
Assert.IsFalse(string.IsNullOrEmpty(files[0].Id));
Assert.IsFalse(string.IsNullOrEmpty(files[0].DisplayName));
}

[TestMethod]
public async Task Modrinth_GetGameVersions_ReturnsVersions()
{
var versions = await _mr!.GetGameVersions();
Assert.IsTrue(versions.Count > 0);
Assert.IsTrue(versions.Any(v => v.Version == "1.20.1" || v.Version.Contains("1.20")));
}

[TestMethod]
public async Task Modrinth_GetCategories_ReturnsCategories()
{
var categories = await _mr!.GetCategories();
Assert.IsTrue(categories.Count > 0);
Assert.IsFalse(string.IsNullOrEmpty(categories[0].Name));
}

[TestMethod]
public async Task Modrinth_GetLoaders_ReturnsLoaders()
{
var loaders = await _mr!.GetLoaders();
Assert.IsTrue(loaders.Count > 0);
Assert.IsTrue(loaders.Any(l => l.LoaderType == ModLoaderType.Forge));
}

// ===== Aggregate =====

[TestMethod]
public async Task Aggregate_SearchProjects_MergesResults()
{
if (!_hasCfKey) Assert.Inconclusive("PCL_CURSEFORGE_API_KEY not set");
var agg = new AggregateClient(_cf!, _mr!);
var filter = new CompSearchFilter { Query = "sodium", Limit = 3 };
var result = await agg.SearchProjects(filter);
Assert.IsTrue(result.Hits.Count > 0);
Assert.IsTrue(result.Hits.Any(p => p.Provider == "CurseForge"));
Assert.IsTrue(result.Hits.Any(p => p.Provider == "Modrinth"));
}
}
12 changes: 6 additions & 6 deletions PCL.Core.Test/PCL.Core.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
<ItemGroup>
<PackageReference Include="fNbt" Version="1.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="Microsoft.TestPlatform.AdapterUtilities" Version="18.0.1" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="18.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="4.1.0" />
<PackageReference Include="System.Text.Json" Version="10.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="Microsoft.TestPlatform.AdapterUtilities" Version="18.6.0" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="18.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="4.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="4.2.3" />
<PackageReference Include="System.Text.Json" Version="10.0.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCL.Core\PCL.Core.csproj" />
Expand Down
29 changes: 0 additions & 29 deletions PCL.Core.Test/Project/Modrinth.cs

This file was deleted.

3 changes: 2 additions & 1 deletion PCL.Core/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Windows.Markup;

[assembly: XmlnsDefinition("https://ce.pclc.cc/core/ui/animation", "PCL.Core.UI.Animation")]
Expand All @@ -10,3 +10,4 @@
[assembly:XmlnsPrefix("https://ce.pclc.cc/core/utils/validate", "val")]

[assembly: DisableRuntimeMarshalling]
[assembly: InternalsVisibleTo("PCL.Core.Test")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using PCL.Core.Minecraft.ResourceProject.Comp.Models;
using PCL.Core.Minecraft.ResourceProject.Comp.Models.Enums;

namespace PCL.Core.Minecraft.ResourceProject.Comp.Abstractions;

public interface ICompClient
{
Task<CompSearchResult> SearchProjects(CompSearchFilter filter, CancellationToken ct = default);
Task<CompProject> GetProject(string projectId, CancellationToken ct = default);
Task<List<CompProject>> GetProjects(IEnumerable<string> projectIds, CancellationToken ct = default);
Task<List<CompProject>> GetFeaturedProjects(string? gameVersion = null, CancellationToken ct = default);
Task<string> GetProjectDescription(string projectId, CancellationToken ct = default);

Task<List<CompFile>> GetProjectFiles(string projectId, CompSearchFilter? filter = null, CancellationToken ct = default);
Task<CompFile> GetFile(string fileId, CancellationToken ct = default);
Task<string> GetFileDownloadUrl(string fileId, CancellationToken ct = default);
Task<string> GetFileChangelog(string fileId, CancellationToken ct = default);

Task<Dictionary<string, List<CompFile>>> MatchFingerprints(
IEnumerable<string> hashes, HashAlgorithm algo, CancellationToken ct = default);
Task<CompFile?> CheckForUpdates(
string fileHash, HashAlgorithm algo, CompSearchFilter? filter = null, CancellationToken ct = default);

Task<List<CompGameVersion>> GetGameVersions(CancellationToken ct = default);
Task<List<CompLoader>> GetLoaders(CancellationToken ct = default);
Task<List<CompCategory>> GetCategories(CancellationToken ct = default);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace PCL.Core.Minecraft.ResourceProject.Comp.Abstractions;

public interface ICompClientFactory
{
ICompClient CreateCurseForgeClient(string apiKey);
ICompClient CreateModrinthClient(string? accessToken = null);
ICompClient CreateAggregateClient(params ICompClient[] clients);
}
Loading
Loading