mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
start of large scale integration tests
This commit is contained in:
parent
4c688bf593
commit
5f05e6a6bb
115
Wabbajack.Test/EndToEndTests.cs
Normal file
115
Wabbajack.Test/EndToEndTests.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using VFS;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
|
||||
namespace Wabbajack.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class EndToEndTests
|
||||
{
|
||||
private const string DOWNLOAD_FOLDER = "downloads";
|
||||
|
||||
private TestUtils utils = new TestUtils();
|
||||
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
Consts.TestMode = true;
|
||||
|
||||
utils = new TestUtils();
|
||||
utils.GameName = "Skyrim Special Edition";
|
||||
|
||||
Utils.SetStatusFn((f, idx) => { });
|
||||
Utils.SetLoggerFn(f => TestContext.WriteLine(f));
|
||||
WorkQueue.Init((x, y, z) => { }, (min, max) => { });
|
||||
|
||||
if (!Directory.Exists(DOWNLOAD_FOLDER))
|
||||
Directory.CreateDirectory(DOWNLOAD_FOLDER);
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateModlist()
|
||||
{
|
||||
var profile = utils.AddProfile("Default");
|
||||
var mod = utils.AddMod();
|
||||
|
||||
DownloadAndInstall(
|
||||
"https://github.com/ModOrganizer2/modorganizer/releases/download/v2.2.1/Mod.Organizer.2.2.1.7z",
|
||||
"Mod.Organizer.2.2.1.7z",
|
||||
utils.MO2Folder);
|
||||
File.WriteAllLines(Path.Combine(utils.DownloadsFolder, "Mod.Organizer.2.2.1.7z.meta"),
|
||||
new List<string>
|
||||
{
|
||||
"[General]",
|
||||
"directURL=https://github.com/ModOrganizer2/modorganizer/releases/download/v2.2.1/Mod.Organizer.2.2.1.7z"
|
||||
});
|
||||
|
||||
utils.Configure();
|
||||
|
||||
var modlist = CompileAndInstall(profile);
|
||||
|
||||
Assert.IsTrue(modlist.Directives.Count > 1);
|
||||
}
|
||||
|
||||
private void DownloadAndInstall(string url, string filename, string mod_name = null)
|
||||
{
|
||||
var src = Path.Combine(DOWNLOAD_FOLDER, filename);
|
||||
if (!File.Exists(src))
|
||||
{
|
||||
var state = DownloadDispatcher.ResolveArchive(url);
|
||||
state.Download(new Archive() { Name = "Unknown"}, src);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(utils.DownloadsFolder))
|
||||
{
|
||||
Directory.CreateDirectory(utils.DownloadsFolder);
|
||||
}
|
||||
|
||||
File.Copy(src, Path.Combine(utils.DownloadsFolder, filename));
|
||||
|
||||
if (mod_name == null)
|
||||
FileExtractor.ExtractAll(src, utils.MO2Folder);
|
||||
else
|
||||
FileExtractor.ExtractAll(src, Path.Combine(utils.ModsFolder, mod_name));
|
||||
|
||||
}
|
||||
|
||||
private ModList CompileAndInstall(string profile)
|
||||
{
|
||||
var compiler = ConfigureAndRunCompiler(profile);
|
||||
Install(compiler);
|
||||
return compiler.ModList;
|
||||
}
|
||||
|
||||
private void Install(Compiler compiler)
|
||||
{
|
||||
var modlist = Installer.LoadFromFile(compiler.ModListOutputFile);
|
||||
var installer = new Installer(compiler.ModListOutputFile, modlist, utils.InstallFolder);
|
||||
installer.DownloadFolder = utils.DownloadsFolder;
|
||||
installer.GameFolder = utils.GameFolder;
|
||||
installer.Install();
|
||||
}
|
||||
|
||||
private Compiler ConfigureAndRunCompiler(string profile)
|
||||
{
|
||||
VirtualFileSystem.Reconfigure(utils.TestFolder);
|
||||
var compiler = new Compiler(utils.MO2Folder);
|
||||
compiler.VFS.Reset();
|
||||
compiler.MO2Profile = profile;
|
||||
compiler.ShowReportWhenFinished = false;
|
||||
Assert.IsTrue(compiler.Compile());
|
||||
return compiler;
|
||||
}
|
||||
}
|
||||
}
|
@ -60,18 +60,18 @@ namespace Wabbajack.Test
|
||||
});
|
||||
}
|
||||
|
||||
public string AddProfile()
|
||||
public string AddProfile(string name = null)
|
||||
{
|
||||
string profile_name = RandomName();
|
||||
string profile_name = name ?? RandomName();
|
||||
Directory.CreateDirectory(Path.Combine(MO2Folder, "profiles", profile_name));
|
||||
Profiles.Add(profile_name);
|
||||
return profile_name;
|
||||
}
|
||||
public HashSet<string> Profiles = new HashSet<string>();
|
||||
|
||||
public string AddMod()
|
||||
public string AddMod(string name = null)
|
||||
{
|
||||
string mod_name = RandomName();
|
||||
string mod_name = name ?? RandomName();
|
||||
Directory.CreateDirectory(Path.Combine(MO2Folder, "mods", mod_name));
|
||||
Mods.Add(mod_name);
|
||||
return mod_name;
|
||||
|
@ -78,6 +78,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DownloaderTests.cs" />
|
||||
<Compile Include="EndToEndTests.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="ModlistMetadataTests.cs" />
|
||||
<Compile Include="TestUtils.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user