public IRegistryRecord StringToRegistryRecord(string textToConvertFrom)
        {
            if (StringExtensions.IsNullOrEmptyWhitespace_Ext(textToConvertFrom))
            {
                throw new ArgumentNullException(nameof(textToConvertFrom));
            }

            string[] text = textToConvertFrom.Split(new char[] { ',' });

            ValidateInputData(text);

            string tmpRoot = GetRootFromRegistryPath(text[0]);
            string key     = GetRegistryPathFromString(text[0], tmpRoot);

            RegistryKey       root      = RegistryRecord.ConvertStringToRegistryKey(tmpRoot);
            string            valueName = text[1];
            string            value     = text[2];
            RegistryValueKind valueKind = RegistryValueKind.DWord; // Default value

            if (text.Length == 4)
            {
                valueKind = (RegistryValueKind)Enum.Parse(typeof(RegistryValueKind), text[3], true);
            }

            return(new RegistryRecord(root, key, valueName, value, valueKind));
        }
Exemplo n.º 2
0
        public void ConvertStringToRegistryKey_ClassesRootString_ExpectClassesRootObj()
        {
            string      root = "hkey_CLASSES_root";
            RegistryKey expectedRegistryKey = Registry.ClassesRoot;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Exemplo n.º 3
0
        public void ConvertStringToRegistryKey_CurrentUserRootString_ExpectCurrentUserRootObj()
        {
            string      root = "HKEY_CURRENT_USER";
            RegistryKey expectedRegistryKey = Registry.CurrentUser;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Exemplo n.º 4
0
        public void ConvertStringToRegistryKey_LocalMachineRootStringUpperCase_ExpectLocalMachineRootObj()
        {
            string      root = "HKEY_LOCAL_MACHINE";
            RegistryKey expectedRegistryKey = Registry.LocalMachine;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Exemplo n.º 5
0
        public void ConvertStringToRegistryKey_LocalMachineRootStringLowerCase_ExpectLocalMachineRootObj()
        {
            string      root = "hkey_local_machine";
            RegistryKey expectedRegistryKey = Registry.LocalMachine;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Exemplo n.º 6
0
        public void ConvertStringToRegistryKey_NotSupportedRegistryRoot_ExpectArgumentException()
        {
            string      root        = "HKEY_iMaGiNeD_rOoT_tYpE";
            RegistryKey registryKey = null;

            bool exceptionWasTrown = false;

            try {
                registryKey = RegistryRecord.ConvertStringToRegistryKey(root);
            } catch (ArgumentException) {
                exceptionWasTrown = true;
            }

            Assert.IsTrue(exceptionWasTrown);
            Assert.IsNull(registryKey);
        }