Skip to content

Commit

Permalink
Starfield TerminalMenu sort test
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Aug 28, 2024
1 parent 3844722 commit efb70b1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<int> Run()
sorter = new SortPropertiesFallout4();
break;
case GameCategory.Starfield:
sorter = new SortPropertiesStarfield();
sorter = new SortPropertiesStarfield(new FileSystem());
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Mutagen.Bethesda;
using System.IO.Abstractions;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Starfield;
using Noggog;
Expand All @@ -7,6 +8,13 @@ namespace Spriggit.CLI.Lib.Commands.SortProperties;

public class SortPropertiesStarfield : ISortProperties
{
private readonly IFileSystem _fileSystem;

public SortPropertiesStarfield(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
}

public bool HasWorkToDo(
ModPath path,
GameRelease release,
Expand All @@ -16,6 +24,7 @@ public bool HasWorkToDo(
.FromPath(path)
.WithLoadOrderFromHeaderMasters()
.WithDataFolder(dataFolder)
.WithFileSystem(_fileSystem)
.Construct();
foreach (var hasVM in mod
.EnumerateMajorRecords<IHaveVirtualMachineAdapterGetter>()
Expand Down Expand Up @@ -95,6 +104,7 @@ public async Task Run(
.FromPath(path)
.WithNoLoadOrder()
.Mutable()
.WithFileSystem(_fileSystem)
.Construct();
foreach (var hasVM in mod
.EnumerateMajorRecords<IHaveVirtualMachineAdapter>())
Expand Down Expand Up @@ -147,6 +157,7 @@ await mod.BeginWrite
.WithDataFolder(dataFolder)
.ToPath(outputPath)
.NoModKeySync()
.WithFileSystem(_fileSystem)
.WriteAsync();
}

Expand Down
66 changes: 66 additions & 0 deletions Spriggit.Tests/SortPropertiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
using FluentAssertions;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Skyrim;
using Mutagen.Bethesda.Starfield;
using Mutagen.Bethesda.Testing.AutoData;
using Noggog;
using Spriggit.CLI.Lib.Commands.SortProperties;
using Xunit;
using Npc = Mutagen.Bethesda.Skyrim.Npc;
using Quest = Mutagen.Bethesda.Skyrim.Quest;
using QuestFragmentAlias = Mutagen.Bethesda.Skyrim.QuestFragmentAlias;
using ScriptBoolProperty = Mutagen.Bethesda.Skyrim.ScriptBoolProperty;
using ScriptEntry = Mutagen.Bethesda.Skyrim.ScriptEntry;
using ScriptFloatProperty = Mutagen.Bethesda.Skyrim.ScriptFloatProperty;
using ScriptProperty = Mutagen.Bethesda.Skyrim.ScriptProperty;

namespace Spriggit.Tests;

Expand Down Expand Up @@ -94,4 +102,62 @@ await skyrimMod.BeginWrite
.Should()
.Equal("Abc", "Xyz");
}

[Theory, MutagenModAutoData(GameRelease.Starfield)]
public async Task SpecificStarfieldTest(
IFileSystem fileSystem,
DirectoryPath existingDir,
DirectoryPath existingDir2,
StarfieldMod mod,
TerminalMenu terminalMenu,
string someName,
SortPropertiesStarfield sortPropertiesStarfield)
{
terminalMenu.VirtualMachineAdapter ??= new();
terminalMenu.VirtualMachineAdapter.Scripts.Add(new Mutagen.Bethesda.Starfield.ScriptEntry()
{
Name = someName,
Properties = new ExtendedList<Mutagen.Bethesda.Starfield.ScriptProperty>()
{
new Mutagen.Bethesda.Starfield.ScriptObjectListProperty()
{
Name = "Xyz",
},
new Mutagen.Bethesda.Starfield.ScriptFloatProperty()
{
Name = "Abc",
}
}
});

var modPath = Path.Combine(existingDir, mod.ModKey.FileName);

await mod.BeginWrite
.WithLoadOrderFromHeaderMasters()
.WithNoDataFolder()
.ToPath(modPath)
.WithFileSystem(fileSystem)
.NoModKeySync()
.WriteAsync();

var modPath2 = Path.Combine(existingDir2, mod.ModKey.FileName);

sortPropertiesStarfield.HasWorkToDo(modPath, GameRelease.Starfield, null)
.Should().BeTrue();
await sortPropertiesStarfield.Run(modPath, GameRelease.Starfield, modPath2, null);

using var reimport = StarfieldMod.Create(StarfieldRelease.Starfield)
.FromPath(modPath2)
.WithLoadOrderFromHeaderMasters()
.WithNoDataFolder()
.WithFileSystem(fileSystem)
.Construct();
reimport.TerminalMenus.Records.Select(x => x.VirtualMachineAdapter)
.NotNull()
.SelectMany(x => x.Scripts)
.SelectMany(x => x.Properties)
.Select(x => x.Name)
.Should()
.Equal("Abc", "Xyz");
}
}

0 comments on commit efb70b1

Please sign in to comment.