diff --git a/ModularToolManger/JSONSettings/JSON/SettingsNode.cs b/ModularToolManger/JSONSettings/JSON/SettingsNode.cs index f0579af..7601c7c 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; 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/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/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/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..770b7f7 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/ModularToolManagerTest.csproj @@ -0,0 +1,84 @@ + + + + + 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 + + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + {b33b0063-b387-40b0-b9fb-be918abcb0b4} + JSONSettings + + + {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/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/Settings/SettingsNodeTest.cs b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs new file mode 100644 index 0000000..5aa1c7e --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/Settings/SettingsNodeTest.cs @@ -0,0 +1,126 @@ +using System; +using JSONSettings; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ModularToolManagerTest +{ + [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, 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, 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); + } + + } +} diff --git a/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs b/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs new file mode 100644 index 0000000..a198fdf --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/Settings/SettingsTests.cs @@ -0,0 +1,343 @@ +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); + + 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/ToolManager/PasswordCryptTest.cs b/ModularToolManger/ModularToolManagerTest/ToolManager/PasswordCryptTest.cs new file mode 100644 index 0000000..4fa60b5 --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/ToolManager/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 PasswordCryptTestSetupTest() + { + 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/ToolManager/PasswordHasherTest.cs b/ModularToolManger/ModularToolManagerTest/ToolManager/PasswordHasherTest.cs new file mode 100644 index 0000000..9b5498d --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/ToolManager/PasswordHasherTest.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 PasswordHasherSetupTest() + { + 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/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 new file mode 100644 index 0000000..bb8f59f --- /dev/null +++ b/ModularToolManger/ModularToolManagerTest/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ModularToolManger/ModularToolManger.sln b/ModularToolManger/ModularToolManger.sln index 0ad23d5..6c22fff 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 @@ -11,13 +11,13 @@ 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 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 @@ -74,18 +74,18 @@ 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 + {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 97% rename from ModularToolManger/ModularToolManger/ModularToolManger.csproj rename to ModularToolManger/ModularToolManger/ModularToolManager.csproj index 8b6809a..317a55f 100644 --- a/ModularToolManger/ModularToolManger/ModularToolManger.csproj +++ b/ModularToolManger/ModularToolManger/ModularToolManager.csproj @@ -191,10 +191,6 @@ - - {cb888391-e0d0-4bf7-8a75-3da4f611ecff} - DymFormDesign - {b33b0063-b387-40b0-b9fb-be918abcb0b4} JSONSettings