Beispiel #1
0
 private void btnCreateKey_Click(object sender, EventArgs e)
 {
     CodeGen cg = new CodeGen();
     string name = txtName.Text.Trim();
     if (name.Length > 0)
     {
         if (txtDays.Text.Trim().Length > 0)
         {
             txtKey.Text = cg.CreateKey(name, Convert.ToInt32(txtDays.Text));
         }
         else
         {
             txtKey.Text = cg.CreateKey(name);
         }
     }
     else
     {
         MessageBox.Show("Enter a valid name.");
     }
 }
 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));
 }
 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 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 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));
 }
 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)); 
 }