wabbajack/Wabbajack.Test/AVortexCompilerTest.cs
2019-12-07 00:40:29 -06:00

78 lines
2.4 KiB
C#

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack.Test
{
public abstract class AVortexCompilerTest
{
public TestContext TestContext { get; set; }
protected TestUtils utils { get; set; }
[TestInitialize]
public void TestInitialize()
{
Consts.TestMode = true;
utils = new TestUtils
{
Game = Game.DarkestDungeon
};
Utils.LogMessages.Subscribe(f => TestContext.WriteLine(f.ShortDescription));
}
[TestCleanup]
public void TestCleanup()
{
utils.Dispose();
}
protected async Task<VortexCompiler> ConfigureAndRunCompiler()
{
var vortexCompiler = MakeCompiler();
vortexCompiler.DownloadsFolder = utils.DownloadsFolder;
vortexCompiler.StagingFolder = utils.InstallFolder;
Directory.CreateDirectory(utils.InstallFolder);
Assert.IsTrue(await vortexCompiler.Begin());
return vortexCompiler;
}
protected VortexCompiler MakeCompiler()
{
return new VortexCompiler(
game: utils.Game,
gamePath: utils.GameFolder,
vortexFolder: VortexCompiler.TypicalVortexFolder(),
downloadsFolder: VortexCompiler.RetrieveDownloadLocation(utils.Game),
stagingFolder: VortexCompiler.RetrieveStagingLocation(utils.Game),
outputFile: $"test{ExtensionManager.Extension}");
}
protected async Task<ModList> CompileAndInstall()
{
var vortexCompiler = await ConfigureAndRunCompiler();
Install(vortexCompiler);
return vortexCompiler.ModList;
}
protected void Install(VortexCompiler vortexCompiler)
{
var modList = AInstaller.LoadFromFile(vortexCompiler.ModListOutputFile);
var installer = new MO2Installer(
archive: vortexCompiler.ModListOutputFile,
modList: modList,
outputFolder: utils.InstallFolder,
downloadFolder: utils.DownloadsFolder)
{
GameFolder = utils.GameFolder,
};
installer.Begin().Wait();
}
}
}