public void TestWriteValue() { //Setup RegistryEdit reg = new RegistryEdit(); KeyObject keyObject = new KeyObject("firstname", "lastname", "TestCompany", "TestProductName", "1.0.0"); string regPath = KeyUtil.BuildRegPath(keyObject); Assert.IsNotNull(reg.WriteKey(regPath)); //Execute try { reg.WriteValue(null, null, null); } catch (Exception ex) { Assert.IsTrue(true, ex.Message); } try { reg.WriteValue(regPath, "testkey", null); } catch (Exception ex) { Assert.IsTrue(true, ex.Message); } Assert.IsTrue(reg.WriteValue(regPath, "testkey", "testvalue")); //Verify //Undo Assert.IsTrue(reg.DeleteKey(regPath, "TestCompany")); }
public void TestDeleteKey() { //Setup RegistryEdit reg = new RegistryEdit(); KeyObject keyObject = new KeyObject("firstname", "lastname", "TestCompany", "TestProductName", "1.0.0"); string regPath = KeyUtil.BuildRegPath(keyObject); Assert.IsNotNull(reg.WriteKey(regPath)); //Execute Assert.IsTrue(reg.DeleteKey(regPath, "TestCompany")); //Verify Assert.IsNull(reg.Read(regPath)); //Undo }
public static bool InstallKey(KeyObject key) { RegistryEdit reg = new RegistryEdit(); string keyPath = BuildRegPath(key); RegistryKey regKey = reg.WriteKey(keyPath); if (regKey != null) { bool isKeyNameWritten = reg.WriteValue(keyPath, "KeyName", key.Name); bool isKeyCodeWritten = reg.WriteValue(keyPath, "KeyCode", key.Key); bool isExpireDateWritten = reg.WriteValue(keyPath, "ExpireDate", key.ExpireDate); return isKeyNameWritten & isKeyCodeWritten & isExpireDateWritten; } else { return false; } }