2019-11-04 23:21:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
|
|
|
|
using Wabbajack.Lib.ModListRegistry;
|
2019-11-05 05:08:47 +00:00
|
|
|
|
using Wabbajack.Lib.NexusApi;
|
2019-11-04 23:21:58 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test.ListValidation
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ListValidation
|
|
|
|
|
{
|
2019-11-14 21:53:29 +00:00
|
|
|
|
[ClassInitialize]
|
2019-11-14 22:58:29 +00:00
|
|
|
|
public static void SetupNexus(TestContext context)
|
2019-11-04 23:21:58 +00:00
|
|
|
|
{
|
2019-12-04 04:12:08 +00:00
|
|
|
|
Utils.LogMessages.Subscribe(m => context.WriteLine(m.ToString()));
|
2019-11-05 05:08:47 +00:00
|
|
|
|
var api = new NexusApiClient();
|
|
|
|
|
api.ClearUpdatedModsInCache();
|
2019-11-04 23:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-17 04:16:42 +00:00
|
|
|
|
private WorkQueue Queue { get; set; }
|
2019-11-14 21:53:29 +00:00
|
|
|
|
[TestInitialize]
|
2019-11-17 04:16:42 +00:00
|
|
|
|
public void Setup()
|
2019-11-04 23:21:58 +00:00
|
|
|
|
{
|
2019-11-14 21:53:29 +00:00
|
|
|
|
Directory.CreateDirectory(Consts.ModListDownloadFolder);
|
2019-12-04 04:12:08 +00:00
|
|
|
|
Utils.LogMessages.Subscribe(s => TestContext.WriteLine(s.ToString()));
|
2019-11-17 04:16:42 +00:00
|
|
|
|
Queue = new WorkQueue();
|
2019-11-04 23:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-17 04:16:42 +00:00
|
|
|
|
[TestCleanup]
|
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
Queue.Shutdown();
|
|
|
|
|
Queue = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-14 21:53:29 +00:00
|
|
|
|
public TestContext TestContext { get; set; }
|
|
|
|
|
|
2019-11-05 22:51:16 +00:00
|
|
|
|
[TestCategory("ListValidation")]
|
2019-11-04 23:21:58 +00:00
|
|
|
|
[DataTestMethod]
|
|
|
|
|
[DynamicData(nameof(GetModLists), DynamicDataSourceType.Method)]
|
2019-11-04 23:49:10 +00:00
|
|
|
|
public void ValidateModLists(string name, ModlistMetadata list)
|
2019-11-04 23:21:58 +00:00
|
|
|
|
{
|
|
|
|
|
Log($"Testing {list.Links.MachineURL} - {list.Title}");
|
2019-11-05 22:11:39 +00:00
|
|
|
|
var modlist_path = Path.Combine(Consts.ModListDownloadFolder, list.Links.MachineURL + ".wabbajack");
|
2019-11-04 23:21:58 +00:00
|
|
|
|
|
2019-11-05 22:11:39 +00:00
|
|
|
|
if (list.NeedsDownload(modlist_path))
|
|
|
|
|
{
|
|
|
|
|
var state = DownloadDispatcher.ResolveArchive(list.Links.Download);
|
|
|
|
|
Log($"Downloading {list.Links.MachineURL} - {list.Title}");
|
|
|
|
|
state.Download(modlist_path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log($"No changes detected from downloaded modlist");
|
|
|
|
|
}
|
2019-11-04 23:21:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log($"Loading {modlist_path}");
|
|
|
|
|
|
2019-11-21 15:05:10 +00:00
|
|
|
|
var installer = AInstaller.LoadFromFile(modlist_path);
|
2019-11-04 23:21:58 +00:00
|
|
|
|
|
|
|
|
|
Log($"{installer.Archives.Count} archives to validate");
|
|
|
|
|
|
|
|
|
|
var invalids = installer.Archives
|
2019-11-17 04:16:42 +00:00
|
|
|
|
.PMap(Queue,archive =>
|
2019-11-04 23:21:58 +00:00
|
|
|
|
{
|
|
|
|
|
Log($"Validating: {archive.Name}");
|
|
|
|
|
return new {archive, is_valid = archive.State.Verify()};
|
|
|
|
|
})
|
|
|
|
|
.Where(a => !a.is_valid)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
DownloadDispatcher.PrepareAll(installer.Archives.Select(a => a.State));
|
|
|
|
|
|
|
|
|
|
Log("Invalid Archives");
|
|
|
|
|
foreach (var invalid in invalids)
|
|
|
|
|
{
|
|
|
|
|
Log(invalid.archive.State.GetReportEntry(invalid.archive));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(invalids.Count, 0, "There were invalid archives");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Log(string msg)
|
|
|
|
|
{
|
|
|
|
|
TestContext.WriteLine(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<object[]> GetModLists()
|
|
|
|
|
{
|
2019-11-04 23:49:10 +00:00
|
|
|
|
return ModlistMetadata.LoadFromGithub().Select(l => new object[] {l.Title, l});
|
2019-11-04 23:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|