Browse Source

Added testing and console demo.

- 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 5 years ago
parent
commit
ff1e87c6c9
  1. 7
      CW_Core_Console/CW_Core_Console.csproj
  2. 118
      CW_Core_Console/ConsoleCommands.cs
  3. 8
      CW_Core_Tests/CW_Core_Tests.csproj
  4. 117
      CW_Core_Tests/ConsoleTests.cs
  5. 14
      CW_Core_Tests/UnitTest1.cs
  6. 6
      Console.Waterworks.Core.sln
  7. 2
      Console.Waterworks.Core/Assistants/CommandsAssistant.cs
  8. 2
      Console.Waterworks.Core/Console.Waterworks.Core.csproj

7
CW_Core_Console/CW_Core_Console.csproj

@ -3,6 +3,13 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<StartupObject>CW_Core_Console.Program</StartupObject>
<Authors>Craig Oates</Authors>
<Company />
<Product />
<Description>This console program is part of the Console.Waterworks.Core project. Its main use is to help test and demonstrate the Console.Waterworks.Core class library.</Description>
<Copyright>Copyright © 2017 Craig Oates</Copyright>
<NeutralLanguage>en-GB</NeutralLanguage>
</PropertyGroup>
<ItemGroup>

118
CW_Core_Console/ConsoleCommands.cs

@ -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
}
}

8
CW_Core_Tests/CW_Core_Tests.csproj

@ -4,12 +4,14 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<StartupObject></StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20171031-01" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>

117
CW_Core_Tests/ConsoleTests.cs

@ -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);
}
}
}

14
CW_Core_Tests/UnitTest1.cs

@ -1,14 +0,0 @@
using System;
using Xunit;
namespace CW_Core_Tests
{
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
}

6
Console.Waterworks.Core.sln

@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2006
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console.Waterworks.Core", "Console.Waterworks.Core\Console.Waterworks.Core.csproj", "{D3F12E66-79AF-4CC3-BDAE-D574AA6CEA3E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.Waterworks.Core", "Console.Waterworks.Core\Console.Waterworks.Core.csproj", "{D3F12E66-79AF-4CC3-BDAE-D574AA6CEA3E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CW_Core_Console", "CW_Core_Console\CW_Core_Console.csproj", "{FE969A76-153C-4691-8561-98F6426BB786}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CW_Core_Console", "CW_Core_Console\CW_Core_Console.csproj", "{FE969A76-153C-4691-8561-98F6426BB786}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CW_Core_Tests", "CW_Core_Tests\CW_Core_Tests.csproj", "{B36C3922-1786-4E8D-9016-2EAD5E806D19}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CW_Core_Tests", "CW_Core_Tests\CW_Core_Tests.csproj", "{B36C3922-1786-4E8D-9016-2EAD5E806D19}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

2
Console.Waterworks.Core/Assistants/CommandsAssistant.cs

@ -85,8 +85,6 @@ namespace Console.Waterworks.Core.Assistants
{
try
{
//var result = typeInfo.GetMethod(command.Name).Invoke(command.Name, inputArguments).ToString();
// return result.ToString();
return typeInfo.GetMethod(command.Name).Invoke(command.Name, inputArguments).ToString();
}
catch (TargetInvocationException ex)

2
Console.Waterworks.Core/Console.Waterworks.Core.csproj

@ -2,6 +2,8 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<NeutralLanguage>English (United Kingdom)</NeutralLanguage>
<Copyright>Copyright © 2017 Craig Oates</Copyright>
</PropertyGroup>
</Project>

Loading…
Cancel
Save