Skip to content

Commit

Permalink
Unit tests for a couple of commands.
Browse files Browse the repository at this point in the history
Fix a couple of unused-allocation issues.
  • Loading branch information
nightblade9 committed Nov 23, 2024
1 parent cf51049 commit 3ea72a6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
15 changes: 15 additions & 0 deletions source/TextBlade.Core.Tests/Commands/DoNothingCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using NUnit.Framework;
using TextBlade.Core.Commands;

namespace TextBlade.Core.Tests.Commands;

[TestFixture]
public class DoNothingCommandTests
{
[Test]
public void Execute_DoesNothing_Literally()
{
// Arrange/Act/Assert
Assert.That(new DoNothingCommand().Execute(null, null), Is.Empty);
}
}
24 changes: 24 additions & 0 deletions source/TextBlade.Core.Tests/Commands/ShowHelpCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using TextBlade.Core.Commands;

namespace TextBlade.Core.Tests.Commands;

[TestFixture]
public class ShowHelpCommandTests
{
[Test]
public void Execute_ReturnsABunchOfCommands()
{
// Arrange/Act
var actuals = new ShowHelpCommand().Execute(null, null);

// Assert
// Check a bunch of commands
foreach (var expectedCommand in new string[] {"credits", "help", "quit"})
{
var expected = $"[red]{expectedCommand}[/]".ToUpperInvariant();
var actual = actuals.Single(a => a.ToUpperInvariant().Contains(expected));
Assert.That(actual.ToUpperInvariant(), Does.Contain(expected));
}
}
}
2 changes: 1 addition & 1 deletion source/TextBlade.Core/Commands/DoNothingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class DoNothingCommand : ICommand
{
public IEnumerable<string> Execute(IGame game, List<Character> party)
{
return new string[0];
return Array.Empty<string>();
}
}
4 changes: 2 additions & 2 deletions source/TextBlade.Core/Commands/QuitGameCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public IEnumerable<string> Execute(IGame game, List<Character> party)
if (input.KeyChar != 'y' && input.KeyChar != 'Y')
{
Console.WriteLine("Cancelling ...");
return new string[0];
return Array.Empty<string>();
}

Console.WriteLine("Bye!");
Environment.Exit(0);
return null; // Makes compiler go brrrr
return null; // Unreachable code. Makes compiler go brrrr.
}
}

0 comments on commit 3ea72a6

Please sign in to comment.