Skip to content

Commit

Permalink
Improved coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ben_singer committed Nov 17, 2024
1 parent ff0d2c4 commit cdc0fea
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions NetAF.Tests/Commands/Scene/UseOn_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit cdc0fea

Please sign in to comment.