wabbajack/Wabbajack.Test.ListValidation/ListValidation.cs

84 lines
2.5 KiB
C#
Raw Normal View History

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;
using Wabbajack.Lib.NexusApi;
2019-11-04 23:21:58 +00:00
namespace Wabbajack.Test.ListValidation
{
[TestClass]
public class ListValidation
{
[TestInitialize]
public void Setup()
{
Directory.CreateDirectory(Consts.ModListDownloadFolder);
Utils.SetLoggerFn(s => TestContext.WriteLine(s));
WorkQueue.Init();
var api = new NexusApiClient();
api.ClearUpdatedModsInCache();
2019-11-04 23:21:58 +00:00
}
private TestContext testContextInstance;
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
[DataTestMethod]
[DynamicData(nameof(GetModLists), DynamicDataSourceType.Method)]
public void ValidateModLists(string name, ModlistMetadata list)
2019-11-04 23:21:58 +00:00
{
Log($"Testing {list.Links.MachineURL} - {list.Title}");
var state = DownloadDispatcher.ResolveArchive(list.Links.Download);
Log($"Downloading {list.Links.MachineURL} - {list.Title}");
var modlist_path = Path.Combine(Consts.ModListDownloadFolder, list.Links.MachineURL + ".wabbajack");
state.Download(modlist_path);
Log($"Loading {modlist_path}");
var installer = Installer.LoadFromFile(modlist_path);
Log($"{installer.Archives.Count} archives to validate");
var invalids = installer.Archives
.PMap(archive =>
{
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()
{
return ModlistMetadata.LoadFromGithub().Select(l => new object[] {l.Title, l});
2019-11-04 23:21:58 +00:00
}
}
}