From baa2bbaecd45bb181407ac7761d897a2306b89f0 Mon Sep 17 00:00:00 2001 From: Craig_Oates Date: Tue, 26 Sep 2017 02:53:17 +0100 Subject: [PATCH] Added XUnit to CW_Tests. I wrote the unit tests for the test-methods in CW_Console. CW_Tests now references CW_Console. Ran units tests and they all passed. --- .../CW_Console/CW_Console.csproj | 10 ++ .../CW_Console/ConsoleCommands.cs | 26 ++-- Console.Waterworks/CW_Console/packages.config | 4 + Console.Waterworks/CW_Tests/CW_ConsoleTest.cs | 117 ++++++++++++++++++ Console.Waterworks/CW_Tests/CW_Tests.csproj | 23 +++- Console.Waterworks/CW_Tests/UnitTest1.cs | 14 --- Console.Waterworks/CW_Tests/packages.config | 7 ++ Console.Waterworks/Console.Waterworks.sln | 6 + 8 files changed, 178 insertions(+), 29 deletions(-) create mode 100644 Console.Waterworks/CW_Console/packages.config create mode 100644 Console.Waterworks/CW_Tests/CW_ConsoleTest.cs delete mode 100644 Console.Waterworks/CW_Tests/UnitTest1.cs diff --git a/Console.Waterworks/CW_Console/CW_Console.csproj b/Console.Waterworks/CW_Console/CW_Console.csproj index 25c60e4..934f945 100644 --- a/Console.Waterworks/CW_Console/CW_Console.csproj +++ b/Console.Waterworks/CW_Console/CW_Console.csproj @@ -1,5 +1,6 @@  + Debug @@ -12,6 +13,8 @@ 512 true + + AnyCPU @@ -49,6 +52,7 @@ + @@ -57,4 +61,10 @@ + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/Console.Waterworks/CW_Console/ConsoleCommands.cs b/Console.Waterworks/CW_Console/ConsoleCommands.cs index f7505d4..0e0d151 100644 --- a/Console.Waterworks/CW_Console/ConsoleCommands.cs +++ b/Console.Waterworks/CW_Console/ConsoleCommands.cs @@ -115,19 +115,19 @@ namespace CW_Console // The template // public static string paramTest(int param1) => $"Param: {param1}"; - public static string StringTest(string param1) => $"Param: {param1}"; - public static string Int16Test(Int16 param1) => $"Param: {param1}"; - public static string Int32Test(Int32 param1) => $"Param: {param1}"; - public static string Int64Test(Int64 param1) => $"Param: {param1}"; - public static string BooleanTest(bool param1) => $"Param: {param1}"; - public static string ByteTest(byte param1) => $"Param: {param1}"; - public static string CharTest(char param1) => $"Param: {param1}"; - public static string DateTimeTest(DateTime param1) => $"Param: {param1}"; - public static string DecimalTest(Decimal param1) => $"Param: {param1}"; - public static string SingleTest(Single param1) => $"Param: {param1}"; - public static string UInt16Test(UInt16 param1) => $"Param: {param1}"; - public static string UInt32Test(UInt32 param1) => $"Param: {param1}"; - public static string UInt64Test(UInt64 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 diff --git a/Console.Waterworks/CW_Console/packages.config b/Console.Waterworks/CW_Console/packages.config new file mode 100644 index 0000000..e4293cb --- /dev/null +++ b/Console.Waterworks/CW_Console/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Console.Waterworks/CW_Tests/CW_ConsoleTest.cs b/Console.Waterworks/CW_Tests/CW_ConsoleTest.cs new file mode 100644 index 0000000..b4e9edd --- /dev/null +++ b/Console.Waterworks/CW_Tests/CW_ConsoleTest.cs @@ -0,0 +1,117 @@ +using CW_Console; +using System; +using Xunit; + +namespace CW_Tests +{ + public class CW_ConsoleTest + { + [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); + } + } +} diff --git a/Console.Waterworks/CW_Tests/CW_Tests.csproj b/Console.Waterworks/CW_Tests/CW_Tests.csproj index 963e0d3..99d7b32 100644 --- a/Console.Waterworks/CW_Tests/CW_Tests.csproj +++ b/Console.Waterworks/CW_Tests/CW_Tests.csproj @@ -9,7 +9,7 @@ Properties CW_Tests CW_Tests - v4.6.1 + v4.7 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15.0 @@ -19,6 +19,7 @@ UnitTest + true @@ -46,14 +47,32 @@ + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll + - + + + + {e26d7001-2a4e-4618-8c27-8bf504993ee9} + CW_Console + + diff --git a/Console.Waterworks/CW_Tests/UnitTest1.cs b/Console.Waterworks/CW_Tests/UnitTest1.cs deleted file mode 100644 index 89bcc4f..0000000 --- a/Console.Waterworks/CW_Tests/UnitTest1.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace CW_Tests -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void TestMethod1() - { - } - } -} diff --git a/Console.Waterworks/CW_Tests/packages.config b/Console.Waterworks/CW_Tests/packages.config index d8c1b90..90d8eed 100644 --- a/Console.Waterworks/CW_Tests/packages.config +++ b/Console.Waterworks/CW_Tests/packages.config @@ -2,4 +2,11 @@ + + + + + + + \ No newline at end of file diff --git a/Console.Waterworks/Console.Waterworks.sln b/Console.Waterworks/Console.Waterworks.sln index dd94c8a..e509886 100644 --- a/Console.Waterworks/Console.Waterworks.sln +++ b/Console.Waterworks/Console.Waterworks.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console.Waterworks", "Conso EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CW_Console", "CW_Console\CW_Console.csproj", "{E26D7001-2A4E-4618-8C27-8BF504993EE9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CW_Tests", "CW_Tests\CW_Tests.csproj", "{F42AB60B-B1AF-41BD-8FFC-85D500D806A7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {E26D7001-2A4E-4618-8C27-8BF504993EE9}.Debug|Any CPU.Build.0 = Debug|Any CPU {E26D7001-2A4E-4618-8C27-8BF504993EE9}.Release|Any CPU.ActiveCfg = Release|Any CPU {E26D7001-2A4E-4618-8C27-8BF504993EE9}.Release|Any CPU.Build.0 = Release|Any CPU + {F42AB60B-B1AF-41BD-8FFC-85D500D806A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F42AB60B-B1AF-41BD-8FFC-85D500D806A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F42AB60B-B1AF-41BD-8FFC-85D500D806A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F42AB60B-B1AF-41BD-8FFC-85D500D806A7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE