From 36df8896f962f9f9901155385c9d533e3b7a8b7a Mon Sep 17 00:00:00 2001 From: XanatosX Date: Thu, 30 Aug 2018 22:22:59 +0200 Subject: [PATCH 1/7] Fixed naming error Adding new project with basic unit tests --- .../JSONSettings/JSONSettings.csproj | 7 ++ .../JSONSettings/packages.config | 4 + .../ModularToolManagerTest.csproj | 74 +++++++++++++++++++ .../PasswordCryptTest.cs | 36 +++++++++ .../Properties/AssemblyInfo.cs | 20 +++++ .../ModularToolManagerTest/UnitTest1.cs | 49 ++++++++++++ .../ModularToolManagerTest/packages.config | 5 ++ ModularToolManger/ModularToolManger.sln | 16 +++- ...anger.csproj => ModularToolManager.csproj} | 0 9 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 ModularToolManger/JSONSettings/packages.config create mode 100644 ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj create mode 100644 ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs create mode 100644 ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs create mode 100644 ModularToolManger/ModularToolManagerTest/UnitTest1.cs create mode 100644 ModularToolManger/ModularToolManagerTest/packages.config rename ModularToolManger/ModularToolManger/{ModularToolManger.csproj => ModularToolManager.csproj} (100%) diff --git a/ModularToolManger/JSONSettings/JSONSettings.csproj b/ModularToolManger/JSONSettings/JSONSettings.csproj index 6e8f536..f9df962 100644 --- a/ModularToolManger/JSONSettings/JSONSettings.csproj +++ b/ModularToolManger/JSONSettings/JSONSettings.csproj @@ -38,11 +38,15 @@ False ..\ModularToolManger\DLL\Newtonsoft.Json.dll + + ..\packages\Octokit.0.19.0\lib\net45\Octokit.dll + + @@ -51,5 +55,8 @@ + + + \ No newline at end of file diff --git a/ModularToolManger/JSONSettings/packages.config b/ModularToolManger/JSONSettings/packages.config new file mode 100644 index 0000000..c258dca --- /dev/null +++ b/ModularToolManger/JSONSettings/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj new file mode 100644 index 0000000..7eeec23 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37} + Library + Properties + ModularToolManagerTest + ModularToolManagerTest + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + {42e97a0e-bb73-47a3-8831-80cfe591ff78} + ModularToolManager + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs b/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs new file mode 100644 index 0000000..b16f2ba --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ModularToolManger.Core; + +namespace ModularToolManagerTest +{ + [TestClass] + public class PasswordCryptTest + { + private static PasswordManager manager; + + [ClassInitialize()] + public static void ClassInit(TestContext context) + { + Console.WriteLine("ClassInit " + context.TestName); + manager = new PasswordManager(); + } + + [TestMethod()] + public void SetupTest() + { + Assert.AreEqual(typeof(PasswordManager), manager.GetType()); + } + + [TestMethod()] + public void EncryptDecryptPasswordTest() + { + string password = "SomeStrongPassword"; + string initialData = "Some text to encrypt"; + string cryptData = manager.EncryptPassword(initialData, password); + string afterConvert = manager.DecryptPassword(cryptData, password); + + Assert.AreEqual(initialData, afterConvert); + } + } +} diff --git a/ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs b/ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8e1f1a7 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("ModularToolManagerTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ModularToolManagerTest")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("f3cc052b-a820-4de9-8131-8d86c04a2f37")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ModularToolManger/ModularToolManagerTest/UnitTest1.cs b/ModularToolManger/ModularToolManagerTest/UnitTest1.cs new file mode 100644 index 0000000..3847061 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/UnitTest1.cs @@ -0,0 +1,49 @@ +using System; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ModularToolManger.Core; + +namespace ModularToolManagerTest +{ + [TestClass] + public class PasswordHasherTest + { + private static PasswordHasher hasher; + + [ClassInitialize()] + public static void ClassInit(TestContext context) + { + Console.WriteLine("ClassInit " + context.TestName); + hasher = new PasswordHasher(); + } + + [TestMethod()] + public void SetupTest() + { + Assert.AreEqual(typeof(PasswordHasher), hasher.GetType()); + } + + [TestMethod()] + public void GetHashedPasswordNoSaltTest() + { + string myPassword = "SuperSafePassword"; + string hashedPassword = hasher.GetHashedPassword(myPassword); + Assert.IsTrue(hasher.CheckPassword(myPassword, hashedPassword)); + } + + [TestMethod()] + public void GetHashedPasswordSaltTest() + { + string myPassword = "SuperSafePassword"; + string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIKLMNOPQRSTUVWXYZ0123456789"; + Random rnd = new Random(); + string myHash = new string(Enumerable.Repeat(allowedChars, 16).Select(s => s[rnd.Next(s.Length)]).ToArray()); + + string hashedPassword = hasher.GetHashedPassword(myPassword, Encoding.UTF8.GetBytes(myHash)); + Assert.IsTrue(hasher.CheckPassword(myPassword, hashedPassword)); + } + + + } +} diff --git a/ModularToolManger/ModularToolManagerTest/packages.config b/ModularToolManger/ModularToolManagerTest/packages.config new file mode 100644 index 0000000..192f200 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManger.sln b/ModularToolManger/ModularToolManger.sln index 0ad23d5..a0e491f 100644 --- a/ModularToolManger/ModularToolManger.sln +++ b/ModularToolManger/ModularToolManger.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26730.12 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModularToolManger", "ModularToolManger\ModularToolManger.csproj", "{42E97A0E-BB73-47A3-8831-80CFE591FF78}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModularToolManager", "ModularToolManger\ModularToolManager.csproj", "{42E97A0E-BB73-47A3-8831-80CFE591FF78}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolMangerInterface", "ToolMangerInterface\ToolMangerInterface.csproj", "{51804EDD-6999-4F6B-B279-0868A9E2505C}" EndProject @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\README.md = ..\README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModularToolManagerTest", "ModularToolManagerTest\ModularToolManagerTest.csproj", "{F3CC052B-A820-4DE9-8131-8D86C04A2F37}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -86,6 +88,18 @@ Global {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|Mixed Platforms.Build.0 = Release|Any CPU {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|x86.ActiveCfg = Release|Any CPU {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|x86.Build.0 = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|x86.ActiveCfg = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|x86.Build.0 = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Any CPU.Build.0 = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|x86.ActiveCfg = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ModularToolManger/ModularToolManger/ModularToolManger.csproj b/ModularToolManger/ModularToolManger/ModularToolManager.csproj similarity index 100% rename from ModularToolManger/ModularToolManger/ModularToolManger.csproj rename to ModularToolManger/ModularToolManger/ModularToolManager.csproj From 21448fd2f0fe8f841d3383cd80d7c7125ff463b2 Mon Sep 17 00:00:00 2001 From: XanatosX Date: Thu, 30 Aug 2018 22:22:59 +0200 Subject: [PATCH 2/7] Fixed naming error Adding new project with basic unit tests --- .../JSONSettings/JSONSettings.csproj | 7 ++ .../JSONSettings/packages.config | 4 + .../ModularToolManagerTest.csproj | 74 +++++++++++++++++++ .../PasswordCryptTest.cs | 36 +++++++++ .../Properties/AssemblyInfo.cs | 20 +++++ .../ModularToolManagerTest/UnitTest1.cs | 49 ++++++++++++ .../ModularToolManagerTest/packages.config | 5 ++ ModularToolManger/ModularToolManger.sln | 16 +++- ...anger.csproj => ModularToolManager.csproj} | 0 9 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 ModularToolManger/JSONSettings/packages.config create mode 100644 ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj create mode 100644 ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs create mode 100644 ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs create mode 100644 ModularToolManger/ModularToolManagerTest/UnitTest1.cs create mode 100644 ModularToolManger/ModularToolManagerTest/packages.config rename ModularToolManger/ModularToolManger/{ModularToolManger.csproj => ModularToolManager.csproj} (100%) diff --git a/ModularToolManger/JSONSettings/JSONSettings.csproj b/ModularToolManger/JSONSettings/JSONSettings.csproj index 6e8f536..f9df962 100644 --- a/ModularToolManger/JSONSettings/JSONSettings.csproj +++ b/ModularToolManger/JSONSettings/JSONSettings.csproj @@ -38,11 +38,15 @@ False ..\ModularToolManger\DLL\Newtonsoft.Json.dll + + ..\packages\Octokit.0.19.0\lib\net45\Octokit.dll + + @@ -51,5 +55,8 @@ + + + \ No newline at end of file diff --git a/ModularToolManger/JSONSettings/packages.config b/ModularToolManger/JSONSettings/packages.config new file mode 100644 index 0000000..c258dca --- /dev/null +++ b/ModularToolManger/JSONSettings/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj new file mode 100644 index 0000000..7eeec23 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37} + Library + Properties + ModularToolManagerTest + ModularToolManagerTest + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + {42e97a0e-bb73-47a3-8831-80cfe591ff78} + ModularToolManager + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs b/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs new file mode 100644 index 0000000..b16f2ba --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ModularToolManger.Core; + +namespace ModularToolManagerTest +{ + [TestClass] + public class PasswordCryptTest + { + private static PasswordManager manager; + + [ClassInitialize()] + public static void ClassInit(TestContext context) + { + Console.WriteLine("ClassInit " + context.TestName); + manager = new PasswordManager(); + } + + [TestMethod()] + public void SetupTest() + { + Assert.AreEqual(typeof(PasswordManager), manager.GetType()); + } + + [TestMethod()] + public void EncryptDecryptPasswordTest() + { + string password = "SomeStrongPassword"; + string initialData = "Some text to encrypt"; + string cryptData = manager.EncryptPassword(initialData, password); + string afterConvert = manager.DecryptPassword(cryptData, password); + + Assert.AreEqual(initialData, afterConvert); + } + } +} diff --git a/ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs b/ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8e1f1a7 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("ModularToolManagerTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ModularToolManagerTest")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("f3cc052b-a820-4de9-8131-8d86c04a2f37")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ModularToolManger/ModularToolManagerTest/UnitTest1.cs b/ModularToolManger/ModularToolManagerTest/UnitTest1.cs new file mode 100644 index 0000000..3847061 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/UnitTest1.cs @@ -0,0 +1,49 @@ +using System; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ModularToolManger.Core; + +namespace ModularToolManagerTest +{ + [TestClass] + public class PasswordHasherTest + { + private static PasswordHasher hasher; + + [ClassInitialize()] + public static void ClassInit(TestContext context) + { + Console.WriteLine("ClassInit " + context.TestName); + hasher = new PasswordHasher(); + } + + [TestMethod()] + public void SetupTest() + { + Assert.AreEqual(typeof(PasswordHasher), hasher.GetType()); + } + + [TestMethod()] + public void GetHashedPasswordNoSaltTest() + { + string myPassword = "SuperSafePassword"; + string hashedPassword = hasher.GetHashedPassword(myPassword); + Assert.IsTrue(hasher.CheckPassword(myPassword, hashedPassword)); + } + + [TestMethod()] + public void GetHashedPasswordSaltTest() + { + string myPassword = "SuperSafePassword"; + string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIKLMNOPQRSTUVWXYZ0123456789"; + Random rnd = new Random(); + string myHash = new string(Enumerable.Repeat(allowedChars, 16).Select(s => s[rnd.Next(s.Length)]).ToArray()); + + string hashedPassword = hasher.GetHashedPassword(myPassword, Encoding.UTF8.GetBytes(myHash)); + Assert.IsTrue(hasher.CheckPassword(myPassword, hashedPassword)); + } + + + } +} diff --git a/ModularToolManger/ModularToolManagerTest/packages.config b/ModularToolManger/ModularToolManagerTest/packages.config new file mode 100644 index 0000000..192f200 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManger.sln b/ModularToolManger/ModularToolManger.sln index 0ad23d5..a0e491f 100644 --- a/ModularToolManger/ModularToolManger.sln +++ b/ModularToolManger/ModularToolManger.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26730.12 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModularToolManger", "ModularToolManger\ModularToolManger.csproj", "{42E97A0E-BB73-47A3-8831-80CFE591FF78}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModularToolManager", "ModularToolManger\ModularToolManager.csproj", "{42E97A0E-BB73-47A3-8831-80CFE591FF78}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToolMangerInterface", "ToolMangerInterface\ToolMangerInterface.csproj", "{51804EDD-6999-4F6B-B279-0868A9E2505C}" EndProject @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\README.md = ..\README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModularToolManagerTest", "ModularToolManagerTest\ModularToolManagerTest.csproj", "{F3CC052B-A820-4DE9-8131-8D86C04A2F37}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -86,6 +88,18 @@ Global {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|Mixed Platforms.Build.0 = Release|Any CPU {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|x86.ActiveCfg = Release|Any CPU {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|x86.Build.0 = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|x86.ActiveCfg = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|x86.Build.0 = Debug|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Any CPU.Build.0 = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|x86.ActiveCfg = Release|Any CPU + {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ModularToolManger/ModularToolManger/ModularToolManger.csproj b/ModularToolManger/ModularToolManger/ModularToolManager.csproj similarity index 100% rename from ModularToolManger/ModularToolManger/ModularToolManger.csproj rename to ModularToolManger/ModularToolManger/ModularToolManager.csproj From 3024a3d716586165227baa1d5d5622531972b727 Mon Sep 17 00:00:00 2001 From: XanatosX Date: Fri, 31 Aug 2018 08:22:27 +0200 Subject: [PATCH 3/7] Fixed names for test so that it's more clear which one get's performed --- ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs | 2 +- ModularToolManger/ModularToolManagerTest/UnitTest1.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs b/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs index b16f2ba..4fa60b5 100644 --- a/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs +++ b/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs @@ -17,7 +17,7 @@ public static void ClassInit(TestContext context) } [TestMethod()] - public void SetupTest() + public void PasswordCryptTestSetupTest() { Assert.AreEqual(typeof(PasswordManager), manager.GetType()); } diff --git a/ModularToolManger/ModularToolManagerTest/UnitTest1.cs b/ModularToolManger/ModularToolManagerTest/UnitTest1.cs index 3847061..9b5498d 100644 --- a/ModularToolManger/ModularToolManagerTest/UnitTest1.cs +++ b/ModularToolManger/ModularToolManagerTest/UnitTest1.cs @@ -19,7 +19,7 @@ public static void ClassInit(TestContext context) } [TestMethod()] - public void SetupTest() + public void PasswordHasherSetupTest() { Assert.AreEqual(typeof(PasswordHasher), hasher.GetType()); } From 016a126864936e4c7e3dc0bbc825bbbe85d451da Mon Sep 17 00:00:00 2001 From: XanatosX Date: Fri, 31 Aug 2018 17:26:15 +0200 Subject: [PATCH 4/7] Changed the structure of the Tests Added folder for tests --- .../ModularToolManagerTest.csproj | 9 +++++++-- .../{ => ToolManager}/PasswordCryptTest.cs | 0 .../PasswordHasherTest.cs} | 0 ModularToolManger/ModularToolManger.sln | 14 -------------- .../ModularToolManger/ModularToolManager.csproj | 4 ---- 5 files changed, 7 insertions(+), 20 deletions(-) rename ModularToolManger/ModularToolManagerTest/{ => ToolManager}/PasswordCryptTest.cs (100%) rename ModularToolManger/ModularToolManagerTest/{UnitTest1.cs => ToolManager/PasswordHasherTest.cs} (100%) diff --git a/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj index 7eeec23..b96fc91 100644 --- a/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj +++ b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj @@ -48,14 +48,19 @@ - + + - + + + {b33b0063-b387-40b0-b9fb-be918abcb0b4} + JSONSettings + {42e97a0e-bb73-47a3-8831-80cfe591ff78} ModularToolManager diff --git a/ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs b/ModularToolManger/ModularToolManagerTest/ToolManager/PasswordCryptTest.cs similarity index 100% rename from ModularToolManger/ModularToolManagerTest/PasswordCryptTest.cs rename to ModularToolManger/ModularToolManagerTest/ToolManager/PasswordCryptTest.cs diff --git a/ModularToolManger/ModularToolManagerTest/UnitTest1.cs b/ModularToolManger/ModularToolManagerTest/ToolManager/PasswordHasherTest.cs similarity index 100% rename from ModularToolManger/ModularToolManagerTest/UnitTest1.cs rename to ModularToolManger/ModularToolManagerTest/ToolManager/PasswordHasherTest.cs diff --git a/ModularToolManger/ModularToolManger.sln b/ModularToolManger/ModularToolManger.sln index a0e491f..6c22fff 100644 --- a/ModularToolManger/ModularToolManger.sln +++ b/ModularToolManger/ModularToolManger.sln @@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DefaultTools", "DefaultTool EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JSONSettings", "JSONSettings\JSONSettings.csproj", "{B33B0063-B387-40B0-B9FB-BE918ABCB0B4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DymFormDesign", "DymFormDesign\DymFormDesign.csproj", "{CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BE409F60-F5A2-4643-B028-F124F6CC151A}" ProjectSection(SolutionItems) = preProject ..\README.md = ..\README.md @@ -76,18 +74,6 @@ Global {B33B0063-B387-40B0-B9FB-BE918ABCB0B4}.Release|Mixed Platforms.Build.0 = Release|Any CPU {B33B0063-B387-40B0-B9FB-BE918ABCB0B4}.Release|x86.ActiveCfg = Release|Any CPU {B33B0063-B387-40B0-B9FB-BE918ABCB0B4}.Release|x86.Build.0 = Release|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Debug|x86.ActiveCfg = Debug|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Debug|x86.Build.0 = Debug|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|Any CPU.Build.0 = Release|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|x86.ActiveCfg = Release|Any CPU - {CB888391-E0D0-4BF7-8A75-3DA4F611ECFF}.Release|x86.Build.0 = Release|Any CPU {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Any CPU.Build.0 = Debug|Any CPU {F3CC052B-A820-4DE9-8131-8D86C04A2F37}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU diff --git a/ModularToolManger/ModularToolManger/ModularToolManager.csproj b/ModularToolManger/ModularToolManger/ModularToolManager.csproj index 8b6809a..317a55f 100644 --- a/ModularToolManger/ModularToolManger/ModularToolManager.csproj +++ b/ModularToolManger/ModularToolManger/ModularToolManager.csproj @@ -191,10 +191,6 @@ - - {cb888391-e0d0-4bf7-8a75-3da4f611ecff} - DymFormDesign - {b33b0063-b387-40b0-b9fb-be918abcb0b4} JSONSettings From d4e035c5530bac31333da0a3acc77bca45856e46 Mon Sep 17 00:00:00 2001 From: XanatosX Date: Fri, 31 Aug 2018 17:26:30 +0200 Subject: [PATCH 5/7] Added tests for SettingsNode Small refactor of the SettingsNode class --- .../JSONSettings/JSON/SettingsNode.cs | 83 +++++------- .../Settings/SettingsNodeTest.cs | 126 ++++++++++++++++++ 2 files changed, 162 insertions(+), 47 deletions(-) create mode 100644 ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs diff --git a/ModularToolManger/JSONSettings/JSON/SettingsNode.cs b/ModularToolManger/JSONSettings/JSON/SettingsNode.cs index f0579af..880baba 100644 --- a/ModularToolManger/JSONSettings/JSON/SettingsNode.cs +++ b/ModularToolManger/JSONSettings/JSON/SettingsNode.cs @@ -14,11 +14,6 @@ public class SettingsNode readonly List _settings; public List Settings => _settings; - public SettingsNode() - { - _settings = new List(); - } - public SettingsNode(string name) { _settings = new List(); @@ -27,18 +22,8 @@ public SettingsNode(string name) private void AddKeyValue(string key, object Value, SettingsType valueType = SettingsType.String) { - if (KeyContained(key)) - { - foreach (KeyValue pair in Settings) - { - if (pair.Key == key) - { - pair.Value = Value.ToString(); - pair.ValueType = valueType; - } - } - } - else + KeyValue pair = GetKeyValue(key); + if (pair == null) { Settings.Add(new KeyValue { @@ -46,68 +31,72 @@ private void AddKeyValue(string key, object Value, SettingsType valueType = Sett Value = Value.ToString(), ValueType = valueType, }); + return; } + + pair.Value = Value.ToString(); + pair.ValueType = valueType; } public bool AddOrChangeKeyValue(string key, object Value) { - SettingsType type; - TypeCode code = Type.GetTypeCode(Value.GetType()); + SettingsType type = GetValueType(Value); + if (type != SettingsType.Error) + { + AddKeyValue(key, Value, type); + return true; + } + + return false; + } + + private SettingsType GetValueType(object valueToCheck) + { + TypeCode code = Type.GetTypeCode(valueToCheck.GetType()); + SettingsType returnType = SettingsType.Error; switch (code) { case TypeCode.Boolean: - type = SettingsType.Bool; + returnType = SettingsType.Bool; break; case TypeCode.Int32: - type = SettingsType.Int; + returnType = SettingsType.Int; break; case TypeCode.Single: case TypeCode.Decimal: - type = SettingsType.Float; + returnType = SettingsType.Float; break; default: - type = SettingsType.String; + returnType = SettingsType.String; break; } - if (type != SettingsType.Error) - { - AddKeyValue(key, Value, type); - return true; - } - - return false; - + return returnType; } public string GetKeyValue(string key, out SettingsType type) { - if (KeyContained(key)) + type = SettingsType.Error; + KeyValue pair = GetKeyValue(key); + + if (pair == null) { - foreach (KeyValue pair in Settings) - { - if (pair.Key == key) - { - type = pair.ValueType; - return pair.Value; - } - } - + return String.Empty; } - type = SettingsType.Error; - return String.Empty; + + type = pair.ValueType; + return pair.Value; } - private bool KeyContained(string key) + private KeyValue GetKeyValue(string key) { - foreach (KeyValue pair in Settings) { if (pair.Key == key) { - return true; + return pair; } } - return false; + return null; } } } diff --git a/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs new file mode 100644 index 0000000..746dc2d --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs @@ -0,0 +1,126 @@ +using System; +using JSONSettings; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ModularToolManagerTest.Settings +{ + [TestClass] + public class SettingsNodeTest + { + private static SettingsNode settingsNode; + + [ClassInitialize()] + public static void ClassInit(TestContext context) + { + Console.WriteLine("ClassInit " + context.TestName); + settingsNode = new SettingsNode("Test"); + } + + [TestMethod] + public void SimpleSetupTest() + { + string name = "GetTested!"; + SettingsNode testNode = new SettingsNode(name); + Assert.AreEqual(name, testNode.Name); + Assert.IsNotNull(testNode.Settings); + } + + [TestMethod] + public void SimpleKeyAddString() + { + string nodeName = "Test"; + string nodeValue = "This is a test value"; + + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + Assert.AreEqual(nodeValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.String, typeOfValue); + } + + [TestMethod] + public void SimpleKeyAddInt() + { + string nodeName = "Test"; + int nodeValue = 123; + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + Assert.AreEqual(nodeValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.Int, typeOfValue); + } + + [TestMethod] + public void SimpleKeyAddDecimal() + { + string nodeName = "Test"; + float nodeValue = 1.57f; + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + Assert.AreEqual(nodeValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.Float, typeOfValue); + } + + [TestMethod] + public void SimpleKeyAddBool() + { + string nodeName = "Test"; + bool nodeValue = true; + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + Assert.AreEqual(nodeValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.Bool, typeOfValue); + } + + [TestMethod] + public void TryUpdateString() + { + string nodeName = "Test"; + string nodeValue = "This is a test value"; + string updatedValue = "Well i'm updated now!"; + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + settingsNode.AddOrChangeKeyValue(nodeName, updatedValue); + Assert.AreEqual(updatedValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.String, typeOfValue); + } + + [TestMethod] + public void TryUpdateInt() + { + string nodeName = "Test"; + int nodeValue = 123; + int updatedValue = 56181; + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + settingsNode.AddOrChangeKeyValue(nodeName, updatedValue); + Assert.AreEqual(updatedValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.Int, typeOfValue); + } + + [TestMethod] + public void TryUpdateDecimal() + { + string nodeName = "Test"; + float nodeValue = 1.47539284f; + float updatedValue = 5.235748f; + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + settingsNode.AddOrChangeKeyValue(nodeName, updatedValue); + Assert.AreEqual(updatedValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.Float, typeOfValue); + } + + [TestMethod] + public void TryUpdatebool() + { + string nodeName = "Test"; + bool nodeValue = false; + bool updatedValue = true; + + settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); + settingsNode.AddOrChangeKeyValue(nodeName, updatedValue); + Assert.AreEqual(updatedValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(SettingsType.Bool, typeOfValue); + } + + } +} From 223a239e6da524f03e93d5230e95f3a792d6db8d Mon Sep 17 00:00:00 2001 From: XanatosX Date: Fri, 31 Aug 2018 18:20:00 +0200 Subject: [PATCH 6/7] Added unit tests for Settings --- ModularToolManger/JSONSettings/Settings.cs | 4 +- .../ModularToolManagerTest.csproj | 5 + .../Settings/SettingsNodeTest.cs | 2 +- .../Settings/SettingsTests.cs | 344 ++++++++++++++++++ .../ModularToolManagerTest/app.config | 11 + .../ModularToolManagerTest/packages.config | 1 + 6 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs create mode 100644 ModularToolManger/ModularToolManagerTest/app.config diff --git a/ModularToolManger/JSONSettings/Settings.cs b/ModularToolManger/JSONSettings/Settings.cs index e67e973..47cb2ef 100644 --- a/ModularToolManger/JSONSettings/Settings.cs +++ b/ModularToolManger/JSONSettings/Settings.cs @@ -46,7 +46,7 @@ public void AddOrChangeKeyValue(string Key, object Value) public bool GetBoolValue(string Name, string key) { - bool returnBool = false; ; + bool returnBool = false; string value = _settings.GetValue(Name, key, out SettingsType type); if (type == SettingsType.Bool) { @@ -189,8 +189,6 @@ public void Cleanup() Load(); } - - public void ForceLoad() { Load(); diff --git a/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj index b96fc91..770b7f7 100644 --- a/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj +++ b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj @@ -44,16 +44,21 @@ ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + diff --git a/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs index 746dc2d..1c40e18 100644 --- a/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs +++ b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs @@ -2,7 +2,7 @@ using JSONSettings; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace ModularToolManagerTest.Settings +namespace ModularToolManagerTest { [TestClass] public class SettingsNodeTest diff --git a/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs b/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs new file mode 100644 index 0000000..4ed94ad --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs @@ -0,0 +1,344 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using JSONSettings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; + +namespace ModularToolManagerTest +{ + [TestClass()] + public class SettingsTests + { + private static string filePath; + + private const string TEST_APP_NAME = "TestApp"; + private const string TEST_APP_NAME2 = "TestApp2"; + + private const string BOOL_TEST_KEY = "boolTest"; + private const string STRING_TEST_KEY = "stringTest"; + private const string FLOAT_TEST_KEY = "floatTest"; + private const string INT_TEST_KEY = "intTest"; + + + private const bool BOOL_TEST_VALUE = true; + private const string STRING_TEST_VALUE = "stringValueTest"; + private const float FLOAT_TEST_VALUE = 452.3045f; + private const int INT_TEST_VALUE = 543862; + + private const bool BOOL_TEST_VALUE2 = true; + private const string STRING_TEST_VALUE2 = "stringValueTest2"; + private const float FLOAT_TEST_VALUE2 = 545.3045f; + private const int INT_TEST_VALUE2 = 16186; + + private void createSimpleTestFile() + { + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(TEST_APP_NAME); + + testSettings.AddOrChangeKeyValue(BOOL_TEST_KEY, BOOL_TEST_VALUE); + testSettings.AddOrChangeKeyValue(STRING_TEST_KEY, STRING_TEST_VALUE); + testSettings.AddOrChangeKeyValue(FLOAT_TEST_KEY, FLOAT_TEST_VALUE); + testSettings.AddOrChangeKeyValue(INT_TEST_KEY, INT_TEST_VALUE); + + testSettings.AddNewField(TEST_APP_NAME2); + + testSettings.AddOrChangeKeyValue(TEST_APP_NAME2, BOOL_TEST_KEY, BOOL_TEST_VALUE2); + testSettings.AddOrChangeKeyValue(TEST_APP_NAME2, STRING_TEST_KEY, STRING_TEST_VALUE2); + testSettings.AddOrChangeKeyValue(TEST_APP_NAME2, FLOAT_TEST_KEY, FLOAT_TEST_VALUE2); + testSettings.AddOrChangeKeyValue(TEST_APP_NAME2, INT_TEST_KEY, INT_TEST_VALUE2); + + testSettings.Save(); + } + + [ClassInitialize()] + public static void ClassInit(TestContext context) + { + Console.WriteLine("ClassInit " + context.TestName); + filePath = context.TestDir + "\\TestFile.json"; + } + + [TestMethod()] + public void SettingsTest() + { + Settings testSettings = new Settings(filePath); + Assert.IsNotNull(testSettings); + } + + [TestMethod()] + public void AddNewFieldTest() + { + string testAppName = "TestApp"; + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(testAppName); + + Assert.AreEqual(testAppName, testSettings.DefaultApp); + } + + [TestMethod()] + public void AddOrChangeKeyValueTestDefaultApp() + { + string testAppName = "TestApp"; + string testKey = "TestKey"; + string testValue = "TestValue"; + + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(testAppName); + testSettings.AddOrChangeKeyValue(testKey, testValue); + + string returnVal = testSettings.GetValue(testKey, out SettingsType type); + + Assert.AreEqual(testValue, returnVal); + Assert.AreEqual(SettingsType.String, type); + } + + [TestMethod()] + public void AddOrChangeKeyValueTestOtherApp() + { + string testAppName = "TestApp"; + string otherAppName = "ChangedTestAppName"; + string testKey = "TestKey"; + string testValue = "TestValue"; + + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(testAppName); + testSettings.AddNewField(otherAppName); + testSettings.AddOrChangeKeyValue(otherAppName, testKey, testValue); + + string returnVal = testSettings.GetValue(otherAppName, testKey, out SettingsType type); + + Assert.AreEqual(testValue, returnVal); + Assert.AreEqual(SettingsType.String, type); + } + + [TestMethod()] + public void SimpleSaveLoadTestNoCompression() + { + string testAppName = "TestApp"; + string otherAppName = "ChangedTestAppName"; + + string testKey1 = "TestKey"; + string testValue1 = "TestValue"; + + string testKey2 = "TestKey"; + bool testValue2 = true; + + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(testAppName); + testSettings.AddNewField(otherAppName); + + testSettings.AddOrChangeKeyValue(otherAppName, testKey1, testValue1); + testSettings.AddOrChangeKeyValue(testKey2, testValue2); + + testSettings.Save(); + testSettings = null; + + Settings testSettings2 = new Settings(filePath); + + string returnVal1 = testSettings2.GetValue(otherAppName, testKey1, out SettingsType type1); + string returnVal2 = testSettings2.GetValue(testKey2, out SettingsType type2); + + Assert.AreEqual(testValue1, returnVal1); + Assert.AreEqual(SettingsType.String, type1); + + Assert.AreEqual(testValue2.ToString(), returnVal2); + Assert.AreEqual(SettingsType.Bool, type2); + } + + [TestMethod()] + public void SimpleSaveLoadTestCompression() + { + string testAppName = "TestApp"; + string otherAppName = "ChangedTestAppName"; + + string testKey1 = "TestKey"; + string testValue1 = "TestValue"; + + string testKey2 = "TestKey"; + bool testValue2 = true; + + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(testAppName); + testSettings.AddNewField(otherAppName); + + testSettings.AddOrChangeKeyValue(otherAppName, testKey1, testValue1); + testSettings.AddOrChangeKeyValue(testKey2, testValue2); + + testSettings.Save(true); + testSettings = null; + + Settings testSettings2 = new Settings(filePath); + + string returnVal1 = testSettings2.GetValue(otherAppName, testKey1, out SettingsType type1); + string returnVal2 = testSettings2.GetValue(testKey2, out SettingsType type2); + + Assert.AreEqual(testValue1, returnVal1); + Assert.AreEqual(SettingsType.String, type1); + + Assert.AreEqual(testValue2.ToString(), returnVal2); + Assert.AreEqual(SettingsType.Bool, type2); + } + + [TestMethod()] + public void SimpleSaveLoadTestCompression2() + { + string testAppName = "TestApp"; + string otherAppName = "ChangedTestAppName"; + + string testKey1 = "TestKey"; + int testValue1 = 1234; + + string testKey2 = "TestKey"; + float testValue2 = 1234.4246f; + + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(testAppName); + testSettings.AddNewField(otherAppName); + + testSettings.AddOrChangeKeyValue(otherAppName, testKey1, testValue1); + testSettings.AddOrChangeKeyValue(testKey2, testValue2); + + testSettings.Save(true); + testSettings = null; + + Settings testSettings2 = new Settings(filePath); + + string returnVal1 = testSettings2.GetValue(otherAppName, testKey1, out SettingsType type1); + string returnVal2 = testSettings2.GetValue(testKey2, out SettingsType type2); + + Assert.AreEqual(testValue1.ToString(), returnVal1); + Assert.AreEqual(SettingsType.Int, type1); + + Assert.AreEqual(testValue2.ToString(), returnVal2); + Assert.AreEqual(SettingsType.Float, type2); + } + + [TestMethod()] + public void GetBoolValueTest() + { + string testAppName = "TestApp"; + string testKey = "TestKey"; + bool testValue = false; + + Settings testSettings = new Settings(filePath); + testSettings.AddNewField(testAppName); + testSettings.AddOrChangeKeyValue(testKey, testValue); + + bool returnVal = testSettings.GetBoolValue(testKey); + + Assert.AreEqual(testValue, returnVal); + } + + [TestMethod()] + public void GetBoolValueTest2() + { + createSimpleTestFile(); + Settings testSettings = new Settings(filePath); + bool returnVal = testSettings.GetBoolValue(TEST_APP_NAME2, BOOL_TEST_KEY); + + Assert.AreEqual(BOOL_TEST_VALUE2, returnVal); + } + + [TestMethod()] + public void GetIntValueTest() + { + createSimpleTestFile(); + Settings testSettings = new Settings(filePath); + int returnVal = testSettings.GetIntValue(INT_TEST_KEY); + + Assert.AreEqual(INT_TEST_VALUE, returnVal); + } + + [TestMethod()] + public void GetIntValueTest2() + { + createSimpleTestFile(); + Settings testSettings = new Settings(filePath); + int returnVal = testSettings.GetIntValue(TEST_APP_NAME2, INT_TEST_KEY); + + Assert.AreEqual(INT_TEST_VALUE2, returnVal); + } + + [TestMethod()] + public void GetFloatValueTest() + { + createSimpleTestFile(); + Settings testSettings = new Settings(filePath); + float returnVal = testSettings.GetFloatValue(FLOAT_TEST_KEY); + + Assert.AreEqual(FLOAT_TEST_VALUE, returnVal, 0.001); + } + + [TestMethod()] + public void GetFloatValueTest1() + { + createSimpleTestFile(); + Settings testSettings = new Settings(filePath); + float returnVal = testSettings.GetFloatValue(TEST_APP_NAME2, FLOAT_TEST_KEY); + + Assert.AreEqual(FLOAT_TEST_VALUE2, returnVal, 0.001); + } + + [TestMethod()] + public void CleanupTest() + { + createSimpleTestFile(); + Settings beforeCleanupTest = new Settings(filePath); + beforeCleanupTest.Cleanup(); + + Settings afterCleanupTest = new Settings(filePath); + + bool boolTest = afterCleanupTest.GetBoolValue(BOOL_TEST_KEY); + string stringTest = afterCleanupTest.GetValue(STRING_TEST_KEY); + float floatTest = afterCleanupTest.GetFloatValue(FLOAT_TEST_KEY); + int intTest = afterCleanupTest.GetIntValue(INT_TEST_KEY); + + Assert.AreEqual(BOOL_TEST_VALUE, boolTest); + Assert.AreEqual(STRING_TEST_VALUE, stringTest); + Assert.AreEqual(FLOAT_TEST_VALUE, floatTest); + Assert.AreEqual(INT_TEST_VALUE, intTest); + } + + [TestMethod()] + public void CleanupTest2() + { + createSimpleTestFile(); + Settings beforeCleanupTest = new Settings(filePath); + beforeCleanupTest.Cleanup(); + + Settings afterCleanupTest = new Settings(filePath); + + bool boolTest = afterCleanupTest.GetBoolValue(TEST_APP_NAME2, BOOL_TEST_KEY); + string stringTest = afterCleanupTest.GetValue(TEST_APP_NAME2, STRING_TEST_KEY); + float floatTest = afterCleanupTest.GetFloatValue(TEST_APP_NAME2, FLOAT_TEST_KEY); + int intTest = afterCleanupTest.GetIntValue(TEST_APP_NAME2, INT_TEST_KEY); + + Assert.AreEqual(BOOL_TEST_VALUE2, boolTest); + Assert.AreEqual(STRING_TEST_VALUE2, stringTest); + Assert.AreEqual(FLOAT_TEST_VALUE2, floatTest); + Assert.AreEqual(INT_TEST_VALUE2, intTest); + } + + [TestMethod()] + public void ClearTest() + { + createSimpleTestFile(); + Settings beforeClearTest = new Settings(filePath); + beforeClearTest.Clear(); + + Settings afterClearTest = new Settings(filePath); + Assert.IsNull(afterClearTest.DefaultApp); + } + + [ClassCleanup] + public static void ClassCleanup() + { + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file diff --git a/ModularToolManger/ModularToolManagerTest/app.config b/ModularToolManger/ModularToolManagerTest/app.config new file mode 100644 index 0000000..2bbe771 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManagerTest/packages.config b/ModularToolManger/ModularToolManagerTest/packages.config index 192f200..bb8f59f 100644 --- a/ModularToolManger/ModularToolManagerTest/packages.config +++ b/ModularToolManger/ModularToolManagerTest/packages.config @@ -2,4 +2,5 @@ + \ No newline at end of file From 33bf774a7ca2d9440381101617e9d7bab27615be Mon Sep 17 00:00:00 2001 From: XanatosX Date: Fri, 31 Aug 2018 18:35:55 +0200 Subject: [PATCH 7/7] Small refactoring --- ModularToolManger/JSONSettings/JSON/SettingsNode.cs | 2 +- .../ModularToolManagerTest/Settings/SettingsNodeTest.cs | 4 ++-- .../ModularToolManagerTest/Settings/SettingsTests.cs | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ModularToolManger/JSONSettings/JSON/SettingsNode.cs b/ModularToolManger/JSONSettings/JSON/SettingsNode.cs index 880baba..7601c7c 100644 --- a/ModularToolManger/JSONSettings/JSON/SettingsNode.cs +++ b/ModularToolManger/JSONSettings/JSON/SettingsNode.cs @@ -53,7 +53,7 @@ public bool AddOrChangeKeyValue(string key, object Value) private SettingsType GetValueType(object valueToCheck) { TypeCode code = Type.GetTypeCode(valueToCheck.GetType()); - SettingsType returnType = SettingsType.Error; + SettingsType returnType; switch (code) { case TypeCode.Boolean: diff --git a/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs index 1c40e18..5aa1c7e 100644 --- a/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs +++ b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs @@ -33,7 +33,7 @@ public void SimpleKeyAddString() settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); - Assert.AreEqual(nodeValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(nodeValue, settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); Assert.AreEqual(SettingsType.String, typeOfValue); } @@ -79,7 +79,7 @@ public void TryUpdateString() settingsNode.AddOrChangeKeyValue(nodeName, nodeValue); settingsNode.AddOrChangeKeyValue(nodeName, updatedValue); - Assert.AreEqual(updatedValue.ToString(), settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); + Assert.AreEqual(updatedValue, settingsNode.GetKeyValue(nodeName, out SettingsType typeOfValue)); Assert.AreEqual(SettingsType.String, typeOfValue); } diff --git a/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs b/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs index 4ed94ad..a198fdf 100644 --- a/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs +++ b/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs @@ -167,7 +167,6 @@ public void SimpleSaveLoadTestCompression() testSettings.AddOrChangeKeyValue(testKey2, testValue2); testSettings.Save(true); - testSettings = null; Settings testSettings2 = new Settings(filePath);