diff --git a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs index 41644de5..1637f798 100644 --- a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs +++ b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs @@ -102,5 +102,73 @@ public void GivenTargetIsRoom_WhenInvoke_ThenInform() Assert.AreEqual(ReactionResult.Inform, result.Result); } + + [TestMethod] + public void GivenItemOnRoomInteractionCausesItemExpire_WhenInvoke_ThenItemRemovedFromRoom() + { + var item = new Item(Identifier.Empty, Description.Empty, true); + var room = new Room(Identifier.Empty, Description.Empty, items: [item], interaction: (i) => + { + return new Interaction(InteractionResult.ItemExpired, i); + }); + var region = new Region(string.Empty, string.Empty); + region.AddRoom(room, 0, 0, 0); + var overworld = new Overworld(string.Empty, string.Empty); + overworld.AddRegion(region); + var player = new PlayableCharacter(Identifier.Empty, Description.Empty); + var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var command = new UseOn(item, room); + command.Invoke(game); + + var result = room.ContainsItem(item); + + Assert.IsFalse(result); + } + + [TestMethod] + public void GivenItemOnPlayerInteractionCausesTargetExpire_WhenInvoke_ThenPlayerNotAlive() + { + var item = new Item(Identifier.Empty, Description.Empty, true); + var room = new Room(Identifier.Empty, Description.Empty, items: [item]); + var region = new Region(string.Empty, string.Empty); + region.AddRoom(room, 0, 0, 0); + var overworld = new Overworld(string.Empty, string.Empty); + overworld.AddRegion(region); + var player = new PlayableCharacter(Identifier.Empty, Description.Empty, interaction: (i) => + { + return new Interaction(InteractionResult.TargetExpired, i); + }); + var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var command = new UseOn(item, player); + command.Invoke(game); + + var result = player.IsAlive; + + Assert.IsFalse(result); + } + + [TestMethod] + public void GivenItemOnPlayerInteractionCausesItemAndTargetExpire_WhenInvoke_ThenPlayerNotAliveAndItemNotInRoom() + { + var item = new Item(Identifier.Empty, Description.Empty, true); + var room = new Room(Identifier.Empty, Description.Empty, items: [item]); + var region = new Region(string.Empty, string.Empty); + region.AddRoom(room, 0, 0, 0); + var overworld = new Overworld(string.Empty, string.Empty); + overworld.AddRegion(region); + var player = new PlayableCharacter(Identifier.Empty, Description.Empty, interaction: (i) => + { + return new Interaction(InteractionResult.ItemAndTargetExpired, i); + }); + var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var command = new UseOn(item, player); + command.Invoke(game); + + var result1 = player.IsAlive; + var result2 = room.ContainsItem(item); + + Assert.IsFalse(result1); + Assert.IsFalse(result2); + } } }