Skip to content

Commit

Permalink
test: add support for mock toggling/installing of api
Browse files Browse the repository at this point in the history
  • Loading branch information
fifty-six committed Sep 23, 2023
1 parent 66ab0fc commit dde777e
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Scarab/Mock/MockViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,39 @@ public static DesignModPageViewModel DesignInstance
{
get
{
ModState apiInstall = new NotInstalledState();

var src = A.Fake<IModSource>();
A.CallTo(() => src.ApiInstall).Returns(new NotInstalledState());
A.CallTo(() => src.ApiInstall).ReturnsLazily(() => apiInstall);

var installer = A.Fake<IInstaller>();

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<ISettings>(), db, A.Fake<IInstaller>(), src)
return new DesignModPageViewModel(A.Fake<ISettings>(), db, installer, src)
{
SelectedModItem = db.Items.ToList()[0]
};
Expand Down

0 comments on commit dde777e

Please sign in to comment.