mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #126 from wabbajack-tools/end-to-end-tests
End to end tests
This commit is contained in:
commit
af1d4ff609
@ -272,7 +272,6 @@ namespace Wabbajack.Common
|
||||
return JsonConvert.DeserializeObject<T>(data,
|
||||
new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Auto});
|
||||
}
|
||||
|
||||
public static T FromJSON<T>(this Stream data)
|
||||
{
|
||||
var s = Encoding.UTF8.GetString(data.ReadAll());
|
||||
|
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using Wabbajack.Lib.Validation;
|
||||
|
||||
namespace Wabbajack.Lib.Downloaders
|
||||
@ -25,6 +27,11 @@ namespace Wabbajack.Lib.Downloaders
|
||||
/// <param name="destination"></param>
|
||||
public abstract void Download(Archive a, string destination);
|
||||
|
||||
public void Download(string destination)
|
||||
{
|
||||
Download(new Archive {Name = Path.GetFileName(destination)}, destination);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this link is still valid
|
||||
/// </summary>
|
||||
|
@ -242,6 +242,17 @@ namespace Wabbajack.Lib.NexusApi
|
||||
return GetCached<NexusFileInfo>(url);
|
||||
}
|
||||
|
||||
public class GetModFilesResponse
|
||||
{
|
||||
public List<NexusFileInfo> files;
|
||||
}
|
||||
|
||||
public IList<NexusFileInfo> GetModFiles(Game game, int modid)
|
||||
{
|
||||
var url = $"https://api.nexusmods.com/v1/games/{GameRegistry.Games[game].NexusName}/mods/{modid}/files.json";
|
||||
return GetCached<GetModFilesResponse>(url).files;
|
||||
}
|
||||
|
||||
public ModInfo GetModInfo(string gameName, string modId)
|
||||
{
|
||||
if (!Directory.Exists(Consts.NexusCacheDirectory))
|
||||
|
154
Wabbajack.Test/EndToEndTests.cs
Normal file
154
Wabbajack.Test/EndToEndTests.cs
Normal file
@ -0,0 +1,154 @@
|
||||
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;
|
||||
using Wabbajack.Lib.NexusApi;
|
||||
|
||||
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"
|
||||
});
|
||||
|
||||
DownloadAndInstall(Game.SkyrimSpecialEdition, 12604, "SkyUI");
|
||||
|
||||
utils.Configure();
|
||||
|
||||
var modlist = CompileAndInstall(profile);
|
||||
|
||||
utils.VerifyAllFiles();
|
||||
}
|
||||
|
||||
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 void DownloadAndInstall(Game game, int modid, string mod_name)
|
||||
{
|
||||
utils.AddMod(mod_name);
|
||||
var client = new NexusApiClient();
|
||||
var file = client.GetModFiles(game, modid).First(f => f.is_primary);
|
||||
var src = Path.Combine(DOWNLOAD_FOLDER, file.file_name);
|
||||
|
||||
var ini = string.Join("\n",
|
||||
new List<string>
|
||||
{
|
||||
"[General]",
|
||||
$"gameName={GameRegistry.Games[game].MO2ArchiveName}",
|
||||
$"modID={modid}",
|
||||
$"fileID={file.file_id}"
|
||||
});
|
||||
|
||||
if (!File.Exists(file.file_name))
|
||||
{
|
||||
|
||||
var state = DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
||||
state.Download(src);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(utils.DownloadsFolder))
|
||||
{
|
||||
Directory.CreateDirectory(utils.DownloadsFolder);
|
||||
}
|
||||
|
||||
var dest = Path.Combine(utils.DownloadsFolder, file.file_name);
|
||||
File.Copy(src, dest);
|
||||
|
||||
FileExtractor.ExtractAll(src, Path.Combine(utils.ModsFolder, mod_name));
|
||||
|
||||
File.WriteAllText(dest + ".meta", ini);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,10 +7,12 @@ using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Wabbajack.Common;
|
||||
using Directory = Alphaleonis.Win32.Filesystem.Directory;
|
||||
using File = Alphaleonis.Win32.Filesystem.File;
|
||||
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
|
||||
using Path = Alphaleonis.Win32.Filesystem.Path;
|
||||
|
||||
namespace Wabbajack.Test
|
||||
@ -60,18 +62,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;
|
||||
@ -171,5 +173,42 @@ namespace Wabbajack.Test
|
||||
Assert.Fail($"Index {x} of {mod}\\{file} are not the same");
|
||||
}
|
||||
}
|
||||
|
||||
public void VerifyAllFiles()
|
||||
{
|
||||
foreach (var dest_file in Directory.EnumerateFiles(InstallFolder, "*", DirectoryEnumerationOptions.Recursive))
|
||||
{
|
||||
var rel_file = dest_file.RelativeTo(InstallFolder);
|
||||
if (rel_file.StartsWith(Consts.LOOTFolderFilesDir) || rel_file.StartsWith(Consts.GameFolderFilesDir))
|
||||
continue;
|
||||
Assert.IsTrue(File.Exists(Path.Combine(MO2Folder, rel_file)), $"Only in Destination: {rel_file}");
|
||||
}
|
||||
|
||||
var skip_extensions = new HashSet<string> {".txt", ".ini"};
|
||||
|
||||
foreach (var src_file in Directory.EnumerateFiles(MO2Folder, "*", DirectoryEnumerationOptions.Recursive))
|
||||
{
|
||||
var rel_file = src_file.RelativeTo(MO2Folder);
|
||||
|
||||
if (rel_file.StartsWith("downloads\\"))
|
||||
continue;
|
||||
|
||||
var dest_file = Path.Combine(InstallFolder, rel_file);
|
||||
Assert.IsTrue(File.Exists(dest_file), $"Only in Source: {rel_file}");
|
||||
|
||||
var fi_src = new FileInfo(src_file);
|
||||
var fi_dest = new FileInfo(dest_file);
|
||||
|
||||
|
||||
|
||||
if (!skip_extensions.Contains(Path.GetExtension(src_file)))
|
||||
{
|
||||
Assert.AreEqual(fi_src.Length, fi_dest.Length, $"Differing sizes {rel_file}");
|
||||
Assert.AreEqual(src_file.FileSHA256(), dest_file.FileSHA256(), $"Differing content hash {rel_file}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,9 @@
|
||||
<Reference Include="AlphaFS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=4d31a58f7d7ad5c9, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\AlphaFS.2.2.6\lib\net452\AlphaFS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DynamicData, Version=6.13.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DynamicData.6.13.18\lib\net461\DynamicData.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
|
||||
@ -69,15 +72,47 @@
|
||||
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="ReactiveUI, Version=10.5.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ReactiveUI.10.5.7\lib\net461\ReactiveUI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Splat, Version=9.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Splat.9.1.1\lib\net461\Splat.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Splat.Drawing, Version=9.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Splat.Drawing.9.1.1\lib\net461\Splat.Drawing.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Drawing.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Drawing.Primitives.4.3.0\lib\net45\System.Drawing.Primitives.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Reactive, Version=4.2.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reactive.4.2.0\lib\net46\System.Reactive.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Windows.Presentation" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DownloaderTests.cs" />
|
||||
<Compile Include="EndToEndTests.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="ModlistMetadataTests.cs" />
|
||||
<Compile Include="TestUtils.cs" />
|
||||
|
@ -1,6 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AlphaFS" version="2.2.6" targetFramework="net472" />
|
||||
<package id="DynamicData" version="6.13.18" targetFramework="net472" />
|
||||
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net472" />
|
||||
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net472" />
|
||||
<package id="ReactiveUI" version="10.5.7" targetFramework="net472" />
|
||||
<package id="Splat" version="9.1.1" targetFramework="net472" />
|
||||
<package id="Splat.Drawing" version="9.1.1" targetFramework="net472" />
|
||||
<package id="System.Drawing.Primitives" version="4.3.0" targetFramework="net472" />
|
||||
<package id="System.Reactive" version="4.2.0" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user