public void LoadSaveLicense() { string publicXmlKey = KeyHelpers.GetPrivateKey(); ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey, new MockLicenseStore(), new MachineIdentifierProviderMock(), new UserInformationProviderMock() { Username = "******", Company = "Company", Email = "*****@*****.**" }); ProductLicense license = licenseManager.LoadLicense("MyProductName"); string productKey = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**"); var licenseActivated = GetProductActivated(productKey); Assert.AreEqual(LicenseStatus.NotFound, license.Status, license.StatusReason); license = licenseManager.ActivateProduct(licenseActivated); licenseManager.SaveLicense("MyProductName", license); license = licenseManager.LoadLicense("MyProductName"); Assert.AreEqual(LicenseStatus.Licensed, license.Status, license.StatusReason); Assert.AreEqual(123, license.ProductID); Assert.AreEqual(456, license.ProductFeatures); Assert.AreEqual(0, license.TrialDays); }
public void ActivateProductMachineMismatch() { MachineIdentifierProviderMock machineMock = new MachineIdentifierProviderMock(false); string productKey = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**"); var licenseActivated = GetProductActivated(productKey); string publicXmlKey = KeyHelpers.GetPrivateKey(); ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey, null, machineMock, new UserInformationProviderMock() { Username = "******", Company = "Company", Email = "*****@*****.**" }); ProductLicense license = licenseManager.ActivateProduct(licenseActivated); Assert.AreEqual(LicenseStatus.MachineHashMismatch, license.Status, license.StatusReason); }
public void ActivateProductWrongUserInfo() { string productKey = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**"); var licenseActivated = GetProductActivated(productKey); string publicXmlKey = KeyHelpers.GetPrivateKey(); ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey, new MockLicenseStore(), new MachineIdentifierProviderMock(), new UserInformationProviderMock() { Username = "******", Company = "Company", Email = "*****@*****.**" }); ProductLicense license = licenseManager.ActivateProduct(licenseActivated); Assert.AreEqual(LicenseStatus.Invalid, license.Status, license.StatusReason); }
public void LoadSaveLicenseRealHash() { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR"); System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR"); string publicXmlKey = KeyHelpers.GetPrivateKey(); ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey, new MockLicenseStore(), new MachineIdentifierProvider(null, new Security.Activation.MachineIdentifiers.VolumeInfoIdentifier(null)), new UserInformationProviderMock() { Username = "******", Company = "Company", Email = "*****@*****.**" }); var hash = licenseManager.GetMachineHash(); ProductLicense license = licenseManager.LoadLicense("MyProductName"); string productKey = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**"); var licenseActivated = GetProductActivatedRealHash(productKey, hash); try { using (StreamWriter writer = new StreamWriter("out.ksk", false)) { XmlSerializer serializer = new XmlSerializer(typeof(ProductLicenseInfo)); serializer.Serialize(writer, licenseActivated); } } catch (Exception ex) { Assert.Fail(ex.Message); return; } Assert.AreEqual(LicenseStatus.NotFound, license.Status, license.StatusReason); KProcess.Ksmed.Security.Activation.ProductLicenseInfo licenseInfo = null; try { using (System.IO.StreamReader reader = new System.IO.StreamReader("out.ksk")) { var serializer = new System.Xml.Serialization.XmlSerializer(typeof(KProcess.Ksmed.Security.Activation.ProductLicenseInfo)); licenseInfo = (KProcess.Ksmed.Security.Activation.ProductLicenseInfo)serializer.Deserialize(reader); } license = licenseManager.ActivateProduct(licenseInfo); } catch (Exception e) { Assert.Fail(e.Message); } license = licenseManager.ActivateProduct(licenseInfo); licenseManager.SaveLicense("MyProductName", license); license = licenseManager.LoadLicense("MyProductName"); Assert.AreEqual(LicenseStatus.Licensed, license.Status, license.StatusReason); Assert.AreEqual(123, license.ProductID); Assert.AreEqual(456, license.ProductFeatures); Assert.AreEqual(0, license.TrialDays); }