Browse Source
- Unit tests checkes the coercion logic in the CW_Core_Console. - CW_Core_Console now has command-methods for users to test out and review. Apart from proof reading and the inevitable refactoring, this is the bulk of the work done (codewise).merge-requests/1/head
Craig Oates
6 years ago
8 changed files with 249 additions and 25 deletions
@ -1,11 +1,123 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using Console.Waterworks.Core.Attributes; |
||||
using Console.Waterworks.Core; |
||||
|
||||
namespace CW_Core_Console |
||||
{ |
||||
public class ConsoleCommands |
||||
{ |
||||
public static string Test() => "Working"; |
||||
#region Demo-Methods |
||||
|
||||
// These command-methods are to show how a Console.Waterworks program typically looks. |
||||
|
||||
[ListCommand()] |
||||
[Description("Displays the Help section at run-time")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> Help")] |
||||
public static string Help() |
||||
{ |
||||
CW_Liaison liaison = new CW_Liaison(); |
||||
return liaison.RequestHelpDocumentation("CW_Core_Console"); |
||||
} |
||||
|
||||
[ListCommand()] |
||||
[Description("Outputs a message indicating this program is running okay.")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> Test")] |
||||
public static string Test() => "Test complete."; |
||||
|
||||
[ListCommand()] |
||||
[Description("Repeats back to the user the string they entered.")] |
||||
[Parameters("<string> input")] |
||||
[Usage("CW_Console> Say \"Hello, World.\"")] |
||||
public static string Say(string input) => $"{input}"; |
||||
|
||||
[ListCommand()] |
||||
[Description("Displays the date and time at the moment the command is entered")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> GetDate")] |
||||
public static string GetDate() => $"{DateTime.Now}"; |
||||
|
||||
[ListCommand()] |
||||
[Description("Takes the two ints and adds them together.")] |
||||
[Parameters("<int> int, <int> int2")] |
||||
[Usage("CW_Console> Add 31 10")] |
||||
public static string Add(int int1, int int2) => $"{int1} + {int2} = {int1 + int2}"; |
||||
|
||||
[ListCommand()] |
||||
[Description("Terminates the program.")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> Quit")] |
||||
public static void Quit() => Environment.Exit(-1); |
||||
#endregion |
||||
|
||||
#region Alias-Methods |
||||
|
||||
/* |
||||
* A NOTE ABOUT ALIAS-METHODS - DELETE AFTER READING |
||||
* ========================================================= |
||||
* These methods are shorthand versions of the ones above. |
||||
* For the most part, this is a hack. |
||||
* But, it is a useful one. |
||||
* When new users start using your console program, they need help getting started. |
||||
* This is why I recommend using descriptive names for your command-methods. |
||||
* But, when your users become more familiar with the program, they will want terser commands. |
||||
* They will no longer need their hand holding. This is where these alias-commands come in. |
||||
*/ |
||||
|
||||
[ListCommand(false)] // change to true or delete "false" for it to show at run-time. |
||||
[Description("Alias for \"Test\". See \"Test\" for details.")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> test")] |
||||
public static string test() => Test(); |
||||
|
||||
[ListCommand(false)] |
||||
[Description("Alias for \"Say\". See \"Say\" for details.")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> say \"Hello, World.\"")] |
||||
public static string say(string input) => Say(input); |
||||
|
||||
[ListCommand(false)] |
||||
[Description("Alias for \"GetDate\". See \"GetDate\" for details.")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> date")] |
||||
public static string date() => GetDate(); |
||||
|
||||
[ListCommand(false)] |
||||
[Description("Alias for \"Add\". See \"Add\" for details.")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> add 24 67")] |
||||
public static string add(int int1, int int2) => Add(int1, int2); |
||||
|
||||
[ListCommand(false)] |
||||
[Description("Alias for Quit. See Quit for details.")] |
||||
[Parameters("None")] |
||||
[Usage("CW_Console> quit")] |
||||
public static void quit() => Quit(); |
||||
#endregion |
||||
|
||||
#region Test-Methods |
||||
|
||||
// The command-methods are for testing purposes only. |
||||
// You can use them at run-time but they will not appear in the help section. |
||||
|
||||
// The template |
||||
// public static string paramTest(int param1) => $"Param: {param1}"; |
||||
public static string StringTest(String param1) => $"{param1}"; |
||||
public static string Int16Test(Int16 param1) => $"{param1}"; |
||||
public static string Int32Test(Int32 param1) => $"{param1}"; |
||||
public static string Int64Test(Int64 param1) => $"{param1}"; |
||||
public static string BooleanTest(Boolean param1) => $"{param1}"; |
||||
public static string ByteTest(Byte param1) => $"{param1}"; |
||||
public static string CharTest(Char param1) => $"{param1}"; |
||||
public static string DateTimeTest(DateTime param1) => $"{param1}"; |
||||
public static string DecimalTest(Decimal param1) => $"{param1}"; |
||||
public static string SingleTest(Single param1) => $"{param1}"; |
||||
public static string UInt16Test(UInt16 param1) => $"{param1}"; |
||||
public static string UInt32Test(UInt32 param1) => $"{param1}"; |
||||
public static string UInt64Test(UInt64 param1) => $"{param1}"; |
||||
|
||||
|
||||
#endregion |
||||
} |
||||
} |
||||
|
@ -0,0 +1,117 @@
|
||||
using CW_Core_Console; |
||||
using System; |
||||
using Xunit; |
||||
|
||||
namespace CW_Core_Tests |
||||
{ |
||||
public class ConsoleTests |
||||
{ |
||||
[Fact] |
||||
public void StringTest() |
||||
{ |
||||
string testInput = "Test Input"; |
||||
var realInput = ConsoleCommands.StringTest(testInput); |
||||
Assert.Equal(testInput, realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void Int16Test() |
||||
{ |
||||
// Int16 = -32,768 to + 32,767 |
||||
Int16 testInput = 1; |
||||
var realInput = ConsoleCommands.Int16Test(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void Int32Test() |
||||
{ |
||||
// Int32 = -2,147,483,648 to +2,147,483,647 |
||||
Int32 testInput = 10000; |
||||
var realInput = ConsoleCommands.Int32Test(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void Int64Test() |
||||
{ |
||||
// Int64 = -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 |
||||
Int64 testInput = 1000000000; |
||||
var realInput = ConsoleCommands.Int64Test(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void BooleanTest() |
||||
{ |
||||
Boolean testInput = true; |
||||
var realInput = ConsoleCommands.BooleanTest(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void ByteTest() |
||||
{ |
||||
Byte testInput = 1; |
||||
var realInput = ConsoleCommands.ByteTest(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void CharTest() |
||||
{ |
||||
Char testInput = 'a'; |
||||
var realInput = ConsoleCommands.CharTest(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void DateTimeTest() |
||||
{ |
||||
DateTime testInput = DateTime.Today; // Be careful with this. |
||||
var realInput = ConsoleCommands.DateTimeTest(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void DecimalTest() |
||||
{ |
||||
Decimal testInput = 1.001m; |
||||
var realInput = ConsoleCommands.DecimalTest(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void SingleTest() |
||||
{ |
||||
Single testInput = 1.001f; |
||||
var realInput = ConsoleCommands.SingleTest(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void UInt16Test() |
||||
{ |
||||
// UInt16 = 0 to 65535 |
||||
UInt16 testInput = 1; |
||||
var realInput = ConsoleCommands.UInt16Test(testInput); |
||||
Assert.Equal(testInput.ToString(), realInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void UInt32Test() |
||||
{ |
||||
// UInt32 = 0 to 4,294,967,295 |
||||
UInt32 testInput = 100000; |
||||
var realInput = ConsoleCommands.UInt32Test(testInput); |
||||
} |
||||
|
||||
[Fact] |
||||
public void UInt64Test() |
||||
{ |
||||
// UInt64 = 0 to 18,446,744,073,709,551,615 |
||||
UInt64 testInput = 10000000000; |
||||
var realInput = ConsoleCommands.UInt64Test(testInput); |
||||
} |
||||
} |
||||
} |
@ -1,14 +0,0 @@
|
||||
using System; |
||||
using Xunit; |
||||
|
||||
namespace CW_Core_Tests |
||||
{ |
||||
public class UnitTest1 |
||||
{ |
||||
[Fact] |
||||
public void Test1() |
||||
{ |
||||
|
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue