2021-09-27 12:42:46 +00:00
|
|
|
using System.Net.Http;
|
|
|
|
using System.Text.Json;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Wabbajack.Common;
|
|
|
|
using Wabbajack.DTOs.JsonConverters;
|
|
|
|
using Wabbajack.DTOs.Validation;
|
|
|
|
using Wabbajack.Networking.WabbajackClientApi;
|
|
|
|
using Wabbajack.Paths.IO;
|
2021-10-21 03:18:15 +00:00
|
|
|
using Wabbajack.RateLimiter;
|
2021-09-27 12:42:46 +00:00
|
|
|
using Xunit;
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.DTOs.Test;
|
|
|
|
|
|
|
|
public class ModListTests
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
private readonly HttpClient _client;
|
|
|
|
private readonly ILogger<ModListTests> _logger;
|
|
|
|
private readonly ParallelOptions _parallelOptions;
|
|
|
|
private readonly DTOSerializer _serializer;
|
|
|
|
private readonly Client _wjClient;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public ModListTests(ILogger<ModListTests> logger, DTOSerializer serializer, HttpClient client, Client wjClient,
|
|
|
|
ParallelOptions parallelOptions)
|
|
|
|
{
|
|
|
|
_serializer = serializer;
|
|
|
|
_client = client;
|
|
|
|
_wjClient = wjClient;
|
|
|
|
_logger = logger;
|
|
|
|
_parallelOptions = parallelOptions;
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void CanLoadModListSummaryInfo()
|
|
|
|
{
|
|
|
|
var jsonPath = KnownFolders.EntryPoint.Combine(@"Resources\ModListSummarySample.json");
|
|
|
|
var data = JsonSerializer.Deserialize<ModListSummary[]>(jsonPath.ReadAllText());
|
|
|
|
Assert.NotNull(data);
|
|
|
|
Assert.Equal(38, data.Length);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public void CanLoadModList()
|
|
|
|
{
|
|
|
|
var jsonPath = KnownFolders.EntryPoint.Combine(@"Resources\ModListSample.json");
|
|
|
|
var data = _serializer.Deserialize<ModList>(jsonPath.ReadAllText());
|
|
|
|
var s = _serializer.Serialize(data);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Theory]
|
|
|
|
[InlineData("https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/modlists.json")]
|
|
|
|
[InlineData("https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/utility_modlists.json")]
|
|
|
|
[InlineData("https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/unlisted_modlists.json")]
|
|
|
|
public async Task CanLoadModListMetadata(string uri)
|
|
|
|
{
|
|
|
|
var str = await _client.GetStringAsync(uri);
|
|
|
|
var data = _serializer.Deserialize<ModlistMetadata[]>(str);
|
|
|
|
var s = _serializer.Serialize(data);
|
|
|
|
Assert.True(data!.Length > 0);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Theory]
|
|
|
|
[InlineData("https://raw.githubusercontent.com/wabbajack-tools/opt-out-lists/master/ServerWhitelist.yml")]
|
|
|
|
public async Task CanLoadAllowList(string uri)
|
|
|
|
{
|
|
|
|
var str = await _client.GetStringAsync(uri);
|
|
|
|
var d = new DeserializerBuilder()
|
|
|
|
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
|
|
|
.Build();
|
|
|
|
var list = d.Deserialize<ServerAllowList>(str);
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
Assert.True(list.GoogleIDs.Length > 1);
|
|
|
|
Assert.True(list.AllowedPrefixes.Length > 1);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
[Fact]
|
|
|
|
public async Task CanGetListStatus()
|
|
|
|
{
|
|
|
|
var statuses = await _wjClient.GetListStatuses();
|
|
|
|
Assert.True(statuses.Length > 10);
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
await statuses.PDoAll(new Resource<ModListTests>("Resource Test", 4),
|
|
|
|
async status =>
|
2021-09-27 12:42:46 +00:00
|
|
|
{
|
|
|
|
_logger.LogInformation("Loading {machineURL}", status.MachineURL);
|
|
|
|
var detailed = await _wjClient.GetDetailedStatus(status.MachineURL);
|
|
|
|
Assert.True(detailed.MachineURL == status.MachineURL);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|