From 424531b13f3068f623504233b6453adbd8bda5d8 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 22 May 2024 11:18:51 -0600 Subject: [PATCH] Don't manage the game on every single test (#1417) --- tests/NexusMods.UI.Tests/AVmTest.cs | 25 ++++++++----------- .../RightContent/LoadoutGridViewModelTests.cs | 2 ++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/NexusMods.UI.Tests/AVmTest.cs b/tests/NexusMods.UI.Tests/AVmTest.cs index f5070ff595..36fe66f20a 100644 --- a/tests/NexusMods.UI.Tests/AVmTest.cs +++ b/tests/NexusMods.UI.Tests/AVmTest.cs @@ -13,7 +13,7 @@ namespace NexusMods.UI.Tests; -public class AVmTest : AUiTest, IAsyncLifetime +public class AVmTest : AUiTest where TVm : IViewModelInterface { protected AbsolutePath DataZipLzma => FileSystem.GetKnownPath(KnownPath.EntryDirectory).Combine("Resources/data_zip_lzma.zip"); @@ -32,7 +32,15 @@ public class AVmTest : AUiTest, IAsyncLifetime protected IFileOriginRegistry FileOriginRegistry { get; } private Loadout.Model? _loadout; - protected Loadout.Model Loadout => _loadout!; + protected Loadout.Model Loadout + { + get + { + if (_loadout == null) + throw new Exception("Must call CreateLoadout before accessing Loadout."); + return _loadout!; + } + } public AVmTest(IServiceProvider provider) : base(provider) { @@ -47,7 +55,7 @@ public AVmTest(IServiceProvider provider) : base(provider) protected TVm Vm => _vmWrapper.VM; - public async Task InitializeAsync() + public async Task CreateLoadout() { _loadout = await ((IGame)Install.Game).Synchronizer.CreateLoadout(Install, "Test"); } @@ -68,14 +76,3 @@ public Task DisposeAsync() return Task.CompletedTask; } } - -public class AVmTest : AVmTest where TVmInterface : IViewModelInterface -where TVm : TVmInterface -{ - public AVmTest(IServiceProvider provider) : base(provider) { } - - /// - /// The concrete view model, not the interface. - /// - public TVm ConcreteVm => (TVm) Vm; -} diff --git a/tests/NexusMods.UI.Tests/RightContent/LoadoutGridViewModelTests.cs b/tests/NexusMods.UI.Tests/RightContent/LoadoutGridViewModelTests.cs index c01a5267aa..8ac220f986 100644 --- a/tests/NexusMods.UI.Tests/RightContent/LoadoutGridViewModelTests.cs +++ b/tests/NexusMods.UI.Tests/RightContent/LoadoutGridViewModelTests.cs @@ -10,6 +10,7 @@ public class LoadoutGridViewModelTests(IServiceProvider provider) : AVmTest [Fact] public async Task CanDeleteMods() { + await CreateLoadout(); Vm.LoadoutId = Loadout.LoadoutId; var ids = new List();