This repository has been archived by the owner on Feb 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add Remove installed kitchen equipment action tests
- Loading branch information
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
backend/app/Savor22b.Tests/Action/RemoveInstalledKitchenEquipmentActionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
namespace Savor22b.Tests.Action; | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using Libplanet.State; | ||
using Savor22b.Action; | ||
using Savor22b.Action.Exceptions; | ||
using Savor22b.Model; | ||
using Savor22b.States; | ||
using Xunit; | ||
|
||
public class RemoveInstalledKitchenEquipmentActionTests : ActionTests | ||
{ | ||
public RemoveInstalledKitchenEquipmentActionTests() { } | ||
|
||
private readonly Guid EquipmentStateId = new(); | ||
|
||
[Fact] | ||
public void Execute_Success_Normal() | ||
{ | ||
IAccountStateDelta beforeState = new DummyState(); | ||
RootState beforeRootState = new RootState( | ||
new InventoryState( | ||
ImmutableList<SeedState>.Empty, | ||
ImmutableList<RefrigeratorState>.Empty, | ||
ImmutableList<KitchenEquipmentState>.Empty.Add( | ||
new KitchenEquipmentState(EquipmentStateId, 1, 1) | ||
), | ||
ImmutableList<ItemState>.Empty | ||
), | ||
new UserDungeonState(), | ||
new VillageState(new HouseState(1, 1, 1, new KitchenState())) | ||
); | ||
beforeRootState.VillageState!.HouseState.KitchenState.InstallKitchenEquipment( | ||
new KitchenEquipmentState(EquipmentStateId, 1, 1), | ||
1 | ||
); | ||
|
||
beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize()); | ||
|
||
var action = new RemoveInstalledKitchenEquipmentAction( | ||
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID | ||
); | ||
|
||
var afterState = action.Execute( | ||
new DummyActionContext | ||
{ | ||
PreviousStates = beforeState, | ||
Signer = SignerAddress(), | ||
Random = random, | ||
Rehearsal = false, | ||
BlockIndex = 1, | ||
} | ||
); | ||
|
||
var afterRootStateEncoded = afterState.GetState(SignerAddress()); | ||
RootState afterRootState = afterRootStateEncoded is Bencodex.Types.Dictionary bdict | ||
? new RootState(bdict) | ||
: throw new Exception(); | ||
|
||
Assert.Null( | ||
afterRootState | ||
.VillageState! | ||
.HouseState | ||
.KitchenState | ||
.FirstApplianceSpace | ||
.InstalledKitchenEquipmentStateId | ||
); | ||
Assert.Single(afterRootState.InventoryState.KitchenEquipmentStateList); | ||
} | ||
|
||
[Fact] | ||
public void Execute_Failure_NotInstalledKitchenEquipment() | ||
{ | ||
IAccountStateDelta beforeState = new DummyState(); | ||
|
||
RootState beforeRootState = new RootState( | ||
new InventoryState( | ||
ImmutableList<SeedState>.Empty, | ||
ImmutableList<RefrigeratorState>.Empty, | ||
ImmutableList<KitchenEquipmentState>.Empty, | ||
ImmutableList<ItemState>.Empty | ||
), | ||
new UserDungeonState(), | ||
new VillageState(new HouseState(1, 1, 1, new KitchenState())) | ||
); | ||
|
||
beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize()); | ||
|
||
var action = new RemoveInstalledKitchenEquipmentAction(Guid.NewGuid()); | ||
|
||
Assert.Throws<InvalidValueException>(() => | ||
{ | ||
action.Execute( | ||
new DummyActionContext | ||
{ | ||
PreviousStates = beforeState, | ||
Signer = SignerAddress(), | ||
Random = random, | ||
Rehearsal = false, | ||
BlockIndex = 1, | ||
} | ||
); | ||
}); | ||
} | ||
} |