From dde777eaae6bdea7670d2fd18cde96355308a23d Mon Sep 17 00:00:00 2001 From: Yusuf Bham Date: Sat, 23 Sep 2023 17:16:04 -0400 Subject: [PATCH] test: add support for mock toggling/installing of api --- Scarab/Mock/MockViewModel.cs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Scarab/Mock/MockViewModel.cs b/Scarab/Mock/MockViewModel.cs index 842d9ced..90bf7287 100644 --- a/Scarab/Mock/MockViewModel.cs +++ b/Scarab/Mock/MockViewModel.cs @@ -21,12 +21,39 @@ public static DesignModPageViewModel DesignInstance { get { + ModState apiInstall = new NotInstalledState(); + var src = A.Fake(); - A.CallTo(() => src.ApiInstall).Returns(new NotInstalledState()); + A.CallTo(() => src.ApiInstall).ReturnsLazily(() => apiInstall); + + var installer = A.Fake(); + + A.CallTo(() => installer.ToggleApi()) + .ReturnsLazily( + () => + { + apiInstall = apiInstall switch + { + InstalledState(true, _, _) i => i with { Enabled = false }, + InstalledState(false, _, _) i => i with { Enabled = true }, + _ => throw new ArgumentOutOfRangeException(nameof(apiInstall)) + }; + + return Task.CompletedTask; + } + ); + A.CallTo(() => installer.InstallApi()) + .ReturnsLazily( + () => + { + apiInstall = new InstalledState(true, new Version(1, 0), true); + return Task.CompletedTask; + } + ); var db = new MockDatabase(); - return new DesignModPageViewModel(A.Fake(), db, A.Fake(), src) + return new DesignModPageViewModel(A.Fake(), db, installer, src) { SelectedModItem = db.Items.ToList()[0] };