Tests for the engine commands.
This commit is contained in:
parent
fae6a006b1
commit
cea1d98bc7
145
RecrownedGTK.Tools.Tests/CommandProcessor/EngineCommandTest.cs
Normal file
145
RecrownedGTK.Tools.Tests/CommandProcessor/EngineCommandTest.cs
Normal file
@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using RecrownedGTK.Tools.CommandProcessor;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace RecrownedGTK.Tools.Tests.CommandProcessor {
|
||||
public class EngineCommandTest {
|
||||
string[] fakeArguments;
|
||||
DummyInput dummyInput;
|
||||
DummyOutput dummyOutput;
|
||||
DummyCommand dummyCommand;
|
||||
EngineCommandArgument dummyCommandArgument;
|
||||
private class DummyInput : IUserInput {
|
||||
public string dummyInput;
|
||||
public string GetInput() {
|
||||
return dummyInput;
|
||||
}
|
||||
}
|
||||
|
||||
private class DummyOutput : IUserOutput
|
||||
{
|
||||
public bool cleared;
|
||||
public string output;
|
||||
public string wrappedOutput;
|
||||
public void ClearOutput()
|
||||
{
|
||||
cleared = true;
|
||||
}
|
||||
|
||||
public void Output(string output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public void WrappedOutput(string output)
|
||||
{
|
||||
this.wrappedOutput = output;
|
||||
}
|
||||
}
|
||||
|
||||
private class DummyCommand : EngineCommand
|
||||
{
|
||||
public DummyCommand(string invoker, params EngineCommandArgument[] engineCommandArguments) : base("helped", invoker) {
|
||||
this.commandArguments = engineCommandArguments;
|
||||
}
|
||||
|
||||
public override void Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments)
|
||||
{
|
||||
if (arguments != null && arguments[0] != null) {
|
||||
userOutput.Output(arguments[0] + " argument");
|
||||
} else {
|
||||
userOutput.Output(userInput.GetInput() + " input");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
dummyInput = new DummyInput();
|
||||
dummyOutput = new DummyOutput();
|
||||
dummyCommandArgument = new EngineCommandArgument("arg", "arg help", false);
|
||||
dummyCommand = new DummyCommand("invoke", dummyCommandArgument);
|
||||
}
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void InitialSetup() {
|
||||
fakeArguments = new string[] {"fake1", "fake2", "fake3", "fake4", "fake5", "fake6", "arg"};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunTestNoArguments() {
|
||||
dummyInput.dummyInput = "input";
|
||||
dummyCommand.Run(dummyInput, dummyOutput, null);
|
||||
Assert.AreEqual(dummyOutput.output, "input input");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunTestWithArguments() {
|
||||
dummyCommand.Run(dummyInput, dummyOutput, "args");
|
||||
Assert.AreEqual(dummyOutput.output, "args argument");
|
||||
}
|
||||
|
||||
public void EngineCommandArgumentOfTestValid() {
|
||||
Assert.AreEqual(dummyCommandArgument, dummyCommand.EngineCommandArgumentOf("args"));
|
||||
}
|
||||
|
||||
public void EngineCommandArgumentOfTestNull() {
|
||||
Assert.IsNull(dummyCommand.EngineCommandArgumentOf("nothing here"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidateTestFalse() {
|
||||
Assert.IsFalse(dummyCommand.Validate("notexisting"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidateTestTrue() {
|
||||
Assert.IsTrue(dummyCommand.Validate("arg"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IndexOfArgumentTestInvald() {
|
||||
try {
|
||||
EngineCommand.IndexOfArgument("fake argument", new string[] {"argument", "argument_again"});
|
||||
} catch (ArgumentException) {
|
||||
Assert.Pass();
|
||||
}
|
||||
Assert.Fail();
|
||||
}
|
||||
|
||||
[TestCase("fake1", 0)]
|
||||
[TestCase("fake3", 2)]
|
||||
[TestCase("fake6", 5)]
|
||||
[TestCase("arg", 6)]
|
||||
public void IndexOfArgumentTestValidWithString(string argument, int expected) {
|
||||
Assert.AreEqual(EngineCommand.IndexOfArgument(argument, this.fakeArguments), expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IndexOfArgumentTestValidWithObject() {
|
||||
Assert.AreEqual(6, EngineCommand.IndexOfArgument(dummyCommandArgument, fakeArguments));
|
||||
}
|
||||
|
||||
[TestCase("fake1", true)]
|
||||
[TestCase("fake3", true)]
|
||||
[TestCase("arg", true)]
|
||||
[TestCase("fake8", false)]
|
||||
public void HasArgumentTest(string argument, bool expected) {
|
||||
Assert.AreEqual(EngineCommand.HasArgument(argument, fakeArguments), expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HelpTestNoArgument() {
|
||||
string expected = "helped\r\nPossible arguments: arg. (* are required arguments.)\r\n";
|
||||
Assert.AreEqual(expected, dummyCommand.Help());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HelpTestArgument() {
|
||||
Assert.AreEqual(dummyCommand.Help("arg"), "arg help");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user