diff --git a/source/TextBlade.Core.Tests/Commands/Display/ShowHelpCommandTests.cs b/source/TextBlade.Core.Tests/Commands/Display/ShowHelpCommandTests.cs index 728ebf1..13276e8 100644 --- a/source/TextBlade.Core.Tests/Commands/Display/ShowHelpCommandTests.cs +++ b/source/TextBlade.Core.Tests/Commands/Display/ShowHelpCommandTests.cs @@ -26,7 +26,7 @@ public void Execute_ReturnsABunchOfCommands(string expectedCommand) // Assert var expected = $"[{Colours.Command}]{expectedCommand}[/]".ToUpperInvariant(); - var actual = console.LastMessage; + var actual = string.Join('\n', console.Messages); Assert.That(actual.ToUpperInvariant(), Does.Contain(expected)); } } diff --git a/source/TextBlade.Core.Tests/Commands/DoNothingCommandTests.cs b/source/TextBlade.Core.Tests/Commands/DoNothingCommandTests.cs deleted file mode 100644 index 2554588..0000000 --- a/source/TextBlade.Core.Tests/Commands/DoNothingCommandTests.cs +++ /dev/null @@ -1,17 +0,0 @@ -using NUnit.Framework; -using TextBlade.Core.Commands; - -namespace TextBlade.Core.Tests.Commands; - -[TestFixture] -public class DoNothingCommandTests -{ - private readonly string[] EmptyStringArray = [string.Empty]; - - [Test] - public void Execute_DoesNothing_LiterallyAsync() - { - // Arrange/Act/Assert - Assert.That(new DoNothingCommand().Execute(null, null), Is.EqualTo(EmptyStringArray)); - } -} diff --git a/source/TextBlade.Core.Tests/Commands/ManuallySaveCommandTests.cs b/source/TextBlade.Core.Tests/Commands/ManuallySaveCommandTests.cs deleted file mode 100644 index 8abf77a..0000000 --- a/source/TextBlade.Core.Tests/Commands/ManuallySaveCommandTests.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NUnit.Framework; -using TextBlade.Core.Commands; - -namespace TextBlade.Core.Tests.Commands; - -[TestFixture] -public class ManuallySaveCommandTests -{ - private readonly string[] EmptyStringArray = [string.Empty]; - - - [Test] - public void Execute_DoesNothing_LiterallyAsync() - { - // Arrange/Act/Assert - Assert.That(new ManuallySaveCommand().Execute(null, null), Is.EqualTo(EmptyStringArray)); - } -} diff --git a/source/TextBlade.Core.Tests/Locations/DungeonTests.cs b/source/TextBlade.Core.Tests/Locations/DungeonTests.cs index de9562c..c194032 100644 --- a/source/TextBlade.Core.Tests/Locations/DungeonTests.cs +++ b/source/TextBlade.Core.Tests/Locations/DungeonTests.cs @@ -1,6 +1,8 @@ +using NSubstitute; using NUnit.Framework; using TextBlade.Core.Commands; using TextBlade.Core.Inv; +using TextBlade.Core.IO; using TextBlade.Core.Locations; namespace TextBlade.Core.Tests.Locations; @@ -15,7 +17,7 @@ public class DungeonTests public void Constructor_Throws_IfNumFloorsIsNotPositive(int numFloors) { // Arrange/Act/Assert - var ex = Assert.Throws(() => new Dungeon(null, "Lava Dungeon", "Mmm, ice-cream", numFloors, ["A", "B"], "Bossman 37")); + var ex = Assert.Throws(() => new Dungeon("Lava Dungeon", "Mmm, ice-cream", numFloors, ["A", "B"], "Bossman 37")); Assert.That(ex.Message, Does.Contain(nameof(numFloors))); } @@ -23,7 +25,7 @@ public void Constructor_Throws_IfNumFloorsIsNotPositive(int numFloors) public void Constructor_Throws_IfMonsterListIsEmpty() { // Arrange/Act/Assert - var ex = Assert.Throws(() => new Dungeon(null, "Ice Dungeon", "Mmm, stew", 33, [], "Bossman 38")); + var ex = Assert.Throws(() => new Dungeon("Ice Dungeon", "Mmm, stew", 33, [], "Bossman 38")); Assert.That(ex.Message, Does.Contain("monsters")); } @@ -119,7 +121,7 @@ public void OnVictory_DoesNotGrantsLoot_OnNonLootFloors() public void SetStateBasedOnCustomSaveData_ThrowsIfFloorNumberIsNegative(int floorNumber) { // Arrange - var dungeon = new Dungeon(null, "Test Dungeon", "N/A", 7, ["Troll"], "Nobody"); + var dungeon = new Dungeon("Test Dungeon", "N/A", 7, ["Troll"], "Nobody"); // Act/Assert var ex = Assert.Throws(() => dungeon.SetStateBasedOnCustomSaveData(MakeCustomData(floorNumber, true))); @@ -130,7 +132,7 @@ public void SetStateBasedOnCustomSaveData_ThrowsIfFloorNumberIsNegative(int floo public void SetStateBasedOnCustomSaveData_SetsCurrentFloorNumber() { // Arrange - var dungeon = new Dungeon(null, "North Seaside Cave", "N/A", 40, ["Vole"], "Nobody"); + var dungeon = new Dungeon("North Seaside Cave", "N/A", 40, ["Vole"], "Nobody"); // Act dungeon.SetStateBasedOnCustomSaveData(MakeCustomData(33, false)); @@ -144,7 +146,7 @@ public void SetStateBasedOnCustomSaveData_DoesNotClearMonstersOrLoot_IfIsClearIs { // Arrange var floorNumber = 0; - var dungeon = new Dungeon(null, "South Seaside Cave", "N/A", 1, ["Mole"], "Nobody"); + var dungeon = new Dungeon("South Seaside Cave", "N/A", 1, ["Mole"], "Nobody"); dungeon.FloorLoot[$"B{floorNumber + 1}"] = ["Troll Hair", "Vole Tail", "Moleskin"]; // Act @@ -160,7 +162,7 @@ public void SetStateBasedOnCustomSaveData_ClearsMonstersOrLoot_IfIsClearIsTrue() { // Arrange var floorNumber = 0; - var dungeon = new Dungeon(null, "South Seaside Cave", "N/A", 3, ["Mole"], "Nobody"); + var dungeon = new Dungeon("South Seaside Cave", "N/A", 3, ["Mole"], "Nobody"); dungeon.FloorLoot[$"B{floorNumber + 1}"] = ["Troll Hair"]; dungeon.FloorLoot[$"B{floorNumber + 2}"] = ["Vole Tail", "Moleskin"]; @@ -282,7 +284,7 @@ public void GetCommandFor_ReturnsTakeTurnsBattleCommand(string command) var dungeon = CreateDungeon(); // Act - var actual = dungeon.GetCommandFor(command); + var actual = dungeon.GetCommandFor(Substitute.For(), command); // Assert Assert.That(actual, Is.InstanceOf()); @@ -299,7 +301,7 @@ public void GetCommandFor_IncrementsFloorNumber_IfYouCanDescend(string command) dungeon.SetStateBasedOnCustomSaveData(MakeCustomData(0, true)); // Act - dungeon.GetCommandFor(command); + dungeon.GetCommandFor(Substitute.For(), command); // Assert Assert.That(dungeon.GetCustomSaveData()["CurrentFloor"], Is.EqualTo(1)); // base 0 @@ -315,7 +317,7 @@ public void GetCommandFor_ReturnsDoNothingCommandForDescend_IfThereAreMonsters(s var dungeon = CreateDungeon(); // Act - var actual = dungeon.GetCommandFor(command); + var actual = dungeon.GetCommandFor(Substitute.For(), command); // Assert Assert.That(dungeon.GetCustomSaveData()["CurrentFloor"], Is.EqualTo(0)); @@ -333,7 +335,7 @@ public void GetCommandFor_ReturnsDoNothingCommandForDescend_IfItsTheBottomFloor( dungeon.SetStateBasedOnCustomSaveData(MakeCustomData(0, true)); // Act - var actual = dungeon.GetCommandFor(command); + var actual = dungeon.GetCommandFor(Substitute.For(), command); // Assert Assert.That(dungeon.GetCustomSaveData()["CurrentFloor"], Is.EqualTo(0)); @@ -358,7 +360,7 @@ private Dictionary MakeCustomData(int floorNum, bool isFloorClea class DungeonStub : Dungeon { public DungeonStub(string name, string description, int numFloors, List monsters, string boss, string? locationClass = null) - : base(null, name, description, numFloors, monsters, boss, locationClass) + : base(name, description, numFloors, monsters, boss, locationClass) { } diff --git a/source/TextBlade.Core.Tests/Locations/InnTests.cs b/source/TextBlade.Core.Tests/Locations/InnTests.cs index 46853ba..8255be7 100644 --- a/source/TextBlade.Core.Tests/Locations/InnTests.cs +++ b/source/TextBlade.Core.Tests/Locations/InnTests.cs @@ -1,5 +1,7 @@ +using NSubstitute; using NUnit.Framework; using TextBlade.Core.Commands; +using TextBlade.Core.IO; using TextBlade.Core.Locations; namespace TextBlade.Core.Tests.Locations; @@ -24,7 +26,7 @@ public void GetCommandFor_ReturnsDoNothingCommand(string input) var inn = new Inn("The Inn of Fluffy Pillows", "An odd pillow-shaped white building", string.Empty); // Act - var actual = inn.GetCommandFor(input); + var actual = inn.GetCommandFor(Substitute.For(), input); // Assert Assert.That(actual, Is.InstanceOf()); @@ -39,7 +41,7 @@ public void GetCommandFor_ReturnsInnCommand_IfInputIsS(string s) var inn = new Inn("The Inn of Fluffy Minnows", "An odd fish-shaped white building", string.Empty); // Act - var actual = inn.GetCommandFor(s); + var actual = inn.GetCommandFor(Substitute.For(), s); // Assert Assert.That(actual, Is.InstanceOf()); diff --git a/source/TextBlade.Core.Tests/Locations/LocationTests.cs b/source/TextBlade.Core.Tests/Locations/LocationTests.cs index 4e95fdc..515311e 100644 --- a/source/TextBlade.Core.Tests/Locations/LocationTests.cs +++ b/source/TextBlade.Core.Tests/Locations/LocationTests.cs @@ -1,5 +1,7 @@ +using NSubstitute; using NUnit.Framework; using TextBlade.Core.Commands; +using TextBlade.Core.IO; using TextBlade.Core.Locations; namespace TextBlade.Core.Tests.Locations; @@ -14,7 +16,7 @@ public void GetCommandFor_ReturnDoNothingCommand() var location = new Location("A", "B"); // Act - var actual = location.GetCommandFor("q"); + var actual = location.GetCommandFor(Substitute.For(), "q"); // Assert Assert.That(actual, Is.InstanceOf()); diff --git a/source/TextBlade.Core/Battle/BasicMonsterAi.cs b/source/TextBlade.Core/Battle/BasicMonsterAi.cs index ed1eb93..451d402 100644 --- a/source/TextBlade.Core/Battle/BasicMonsterAi.cs +++ b/source/TextBlade.Core/Battle/BasicMonsterAi.cs @@ -13,17 +13,19 @@ public BasicMonsterAi(IConsole console, List party) ArgumentNullException.ThrowIfNull(console); _console = console; - _party = party.Where(p => p.CurrentHealth > 0).ToList(); + _party = party; } public void ProcessTurnFor(Monster monster) { - if (_party.Count == 0) + var validTargets = _party.Where(p => p.CurrentHealth > 0).ToList(); + if (validTargets.Count == 0) { // Wiped out, nothing to do + return; } - var target = _party[Random.Shared.Next(0, _party.Count)]; + var target = validTargets[Random.Shared.Next(0, validTargets.Count)]; var damage = monster.Attack(target); var message = $"{monster.Name} attacks {target.Name} for [{Colours.Highlight}]{damage}[/] damage! ";