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"));
        }
Esempio n. 2
0
        /// <summary>
        /// Get the days remaining of a key already installed.
        /// </summary>
        public static int GetDaysRemaining(KeyObject key)
        {
            //Check hashed install date, todays date to get days remaining
            int daysRemaining = KeyUtil.GetExpireDate(key).Subtract(DateTime.Now).Days;

            return daysRemaining;
        }
Esempio n. 3
0
 public void TestUnInstallKey()
 {
     //Setup
     KeyObject key = new KeyObject("TestName", "SAMPLEKEYCODE", "TestCompany", "TestProductName", "1.0.0");
     KeyUtil.InstallKey(key);//Make sure key is installed.
     //Execute    
     Assert.IsTrue(KeyUtil.UninstallKey(key)); 
     //Verify
     //Undo
 }
 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
 }
Esempio n. 5
0
 public static DateTime GetExpireDate(KeyObject key)
 {
     RegistryEdit reg = new RegistryEdit();
     RegistryKey regKey = reg.Read(BuildRegPath(key));
     object regValue = regKey.GetValue("ExpireDate");
     try
     {
         return DateTime.Parse(regValue.ToString());
     }
     catch 
     {
         return DateTime.MinValue;//Invalid date
     }
 }
Esempio n. 6
0
 public void TestIsKeyInstalled()
 {
     //Setup
     KeyObject key = new KeyObject("TestName", "SAMPLEKEYCODE", "TestCompany", "TestProductName", "1.0.0");
     KeyUtil.UninstallKey(key);//Make sure key is uninstalled.
     //Execute  
     Assert.IsFalse(KeyUtil.IsKeyInstalled(null));
     Assert.IsFalse(KeyUtil.IsKeyInstalled(key)); //A key, but it is not installed.
     Assert.IsTrue(KeyUtil.InstallKey(key));
     //Verify
     Assert.IsTrue(KeyUtil.IsKeyInstalled(key)); //Key should have already been installed.
     //Undo
     Assert.IsTrue(KeyUtil.UninstallKey(key)); 
 }
Esempio n. 7
0
        public static bool IsKeyExpired(KeyObject key)
        {
            bool isKeyExpired = true;

            if (IsKeyInstalled(key))
            {
                DateTime expireDate = KeyUtil.GetExpireDate(key);
                if (expireDate > DateTime.Now)
                {
                    isKeyExpired = false;
                }
            }

            return isKeyExpired; //The default is that the key is expired.  Prove it is not.
        }
Esempio n. 8
0
 public void TestGetExpireDate()
 {
     //Setup
     CodeGen gen = new CodeGen();
     string name = "Test User";
     string keyCode = gen.CreateKey(name, 30);//30-day expiration key
     KeyObject key = new KeyObject(name, keyCode, "Test Company", "Test Product", "1.0.0");
     LicenseKey.InstallKey(key);
     Assert.IsTrue(LicenseKey.IsKeyInstalled(key)); //Make sure key is installed.
     //Execute      
     //Verify
     Assert.IsTrue(KeyUtil.GetExpireDate(key).ToShortDateString() == DateTime.Now.AddDays(30).ToShortDateString());
     //Undo
     Assert.IsTrue(KeyUtil.UninstallKey(key)); 
 }
 public void TestIsKeyCodeValid()
 {
     //Setup
     CodeGen gen = new CodeGen();
     string name = "Test User";
     string keyCode = gen.CreateKey(name, 30);//30-day expiration key
     KeyObject key = new KeyObject(name, keyCode, "Test Company", "Test Product", "1.0.0");
     LicenseKey.InstallKey(key);
     Assert.IsTrue(LicenseKey.IsKeyInstalled(key)); //Make sure key is installed.
     //Execute       
     Assert.IsTrue(LicenseKey.IsKeyCodeValid(key.Name, key.Key));
     //Verify
     //Undo
     Assert.IsTrue(LicenseKey.UninstallKey(key));
 }
Esempio n. 10
0
 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;
     }
 }
Esempio n. 11
0
 public void TestIsKeyInstalled()
 {
     //Setup
     CodeGen gen = new CodeGen();
     string name = "Test User";
     string keyCode = gen.CreateKey(name, 30);//30-day expiration key
     KeyObject key = new KeyObject(name, keyCode, "Test Company", "Test Product", "1.0.0");
     LicenseKey.UninstallKey(key);
     //Execute        
     Assert.IsFalse(LicenseKey.IsKeyInstalled(null));
     Assert.IsFalse(LicenseKey.IsKeyInstalled(key)); //A key, but has not been installed
     Assert.IsTrue(LicenseKey.InstallKey(key));            
     //Verify
     Assert.IsTrue(LicenseKey.IsKeyInstalled(key));
     //Undo
     Assert.IsTrue(LicenseKey.UninstallKey(key));
 }
 public void TestRead()
 {
     //Setup
     RegistryEdit reg = new RegistryEdit();
     KeyObject keyObject = new KeyObject("firstname", "lastname", "TestCompany", "TestProductName", "1.0.0");
     string regPath = KeyUtil.BuildRegPath(keyObject);
     reg.DeleteKey(regPath, "TestCompany");
     //Execute  
     //Verify
     try 
     {
         reg.Read(null);
     }
     catch (Exception ex) { Assert.IsTrue(true, ex.Message); }
     Assert.IsNull(reg.Read(regPath)); //Non-existant reg key
     //Undo
 }
Esempio n. 13
0
        public static KeyObject GetInstalledKey(string companyName, string productName, string productVersion)
        {
            KeyObject key = new KeyObject("", "", companyName, productName, productVersion);
            string regPath = BuildRegPath(key);
            RegistryEdit reg = new RegistryEdit();
            RegistryKey regKey = reg.Read(regPath);
            if (regKey == null) return null;

            object keyName = regKey.GetValue("KeyName");
            object keyCode = regKey.GetValue("KeyCode");
            if (keyName != null)
                key.Name = keyName.ToString();

            if (keyCode != null)
                key.Key = keyCode.ToString();
            return key;
        }
Esempio n. 14
0
        public static bool IsKeyInstalled(KeyObject key)
        {            
            RegistryKey regKey = null;

            if (key != null)
            {
                string regPath = BuildRegPath(key);
                RegistryEdit reg = new RegistryEdit();
                regKey = reg.Read(regPath);
                if ((regKey != null) &&
                    ((regKey.GetValue("KeyName").ToString() == key.Name) & (regKey.GetValue("KeyCode").ToString() == key.Key)))
                {
                    return true;
                }
            }

            return false; //If we make it this far, the key was not installed.
        }
Esempio n. 15
0
        public static bool InstallKey(KeyObject key)
        {
            SimpleHash.VerifyHash(key.Name, SimpleHash.HashEnum.SHA1, key.Key);
            string daysToExpire = SimpleHash._salt;
            int num;
            bool isNumeric = int.TryParse(daysToExpire, out num);
            if (isNumeric)
            {
                int days = -1;
                days = Convert.ToInt32(num);
                DateTime expireDate = DateTime.Now.AddDays(days);
                key.ExpireDate = expireDate.ToShortDateString();
            }
            else
            {
                // value is not a number
            }

            return KeyUtil.InstallKey(key);
        }
Esempio n. 16
0
 public void TestGetDaysRemaining()
 {
     //Setup
     CodeGen gen = new CodeGen();
     string name = "Test User";
     string keyCode = gen.CreateKey(name, 30);//30-day expiration key
     KeyObject key = new KeyObject(name, keyCode, "Test Company", "Test Product", "1.0.0");
     LicenseKey.InstallKey(key);
     Assert.IsTrue(LicenseKey.IsKeyInstalled(key)); //Make sure key is installed.
     //Execute        
     //Verify
     Assert.IsTrue(LicenseKey.GetDaysRemaining(key) == 29);//Is 29 instead of 30 since time remaining is less than exactly 30 days.
     //Undo
     Assert.IsTrue(LicenseKey.UninstallKey(key));
 }
Esempio n. 17
0
 public void TestGetInstalledKey()
 {
     CodeGen gen = new CodeGen();
     string name = "Test User";
     string keyCode = gen.CreateKey(name, 30);//30-day expiration key
     KeyObject key = new KeyObject(name, keyCode, "Test Company", "Test Product", "1.0.0");
     LicenseKey.InstallKey(key);
     Assert.IsTrue(LicenseKey.IsKeyInstalled(key)); //Make sure key is installed.
     //Execute    
     KeyObject installedKey = KeyUtil.GetInstalledKey("Test Company", "Test Product", "1.0.0");
     //Verify
     Assert.IsTrue(installedKey.Name == name);
     Assert.IsTrue(installedKey.Key == keyCode);
     //Undo
     Assert.IsTrue(KeyUtil.UninstallKey(key)); 
 }
Esempio n. 18
0
 public static bool IsKeyInstalled(KeyObject key)
 {
     return KeyUtil.IsKeyInstalled(key);
 }
Esempio n. 19
0
 public static string BuildRegPath(KeyObject key)
 {
     StringBuilder regPath = new StringBuilder();
     regPath.Append(string.Format(@"{0}\{1}\{2}\{3}\license", REG_KEY_BASE, key.CompanyName, key.ProductName, key.Version));
     return regPath.ToString();
 }
Esempio n. 20
0
 public static bool UninstallKey(KeyObject key)
 {
     RegistryEdit reg = new RegistryEdit();
     string keyPath = BuildRegPath(key);
     return reg.DeleteKey(keyPath, key.CompanyName);
 }
Esempio n. 21
0
 public static bool UninstallKey(KeyObject key)
 {
     return KeyUtil.UninstallKey(key);
 }