コード例 #1
0
        public void CanReadValidLicense()
        {
            IsValidIfLocalLicenseDoesNotAlreadyExist();

            // Assuming test environment can write in one of folders license file may be.
            using (var path = new TemporaryFile(LicenseManager.GetLicenseFilePath()))
            {
                // In test environment there isn't license file/storage then this test must fail.
                // After this we must discard cached (and empty) license to load the newly created one.
                Assert.IsNull(LicenseManager.License);
                Assert.IsFalse(LicenseManager.IsLicenseValid);

                LicenseManager.Renew();

                // Now we prepare a fake license file to check few basics in
                // LicenseManager class.
                var contact = ContactFactory.Create <Contact>();
                var license = LicenseFactory.Create <License>(contact);
                license.Features.Add((int)Feature.Example1, 1);

                LicenseWriter.ToFile(path, license);

                Assert.IsTrue(LicenseManager.IsLicenseValid);
                Assert.IsNotNull(LicenseManager.License);
                Assert.AreEqual(LicenseManager.License.Id, license.Id);
                Assert.IsTrue(LicenseManager.IsFeatureAvailable(Feature.Example1));
            }
        }
コード例 #2
0
 private static License SaveAndReloadFromDisk(License license)
 {
     using (var path = new TemporaryFile())
     {
         LicenseWriter.ToFile(path, license);
         return(LicenseReader.FromFile(path));
     }
 }
コード例 #3
0
        public void ValidForMinorHardwareChanges()
        {
            using (var temp = new TemporaryFile())
            {
                var contact = ContactFactory.Create <ContactForSlightlyChangedHardware>();
                var license = LicenseFactory.Create <License>(contact);

                LicenseWriter.ToFile(temp, license);

                license = LicenseReader.FromFile <LicenseWithSlightlyChangedHardware, IniLicenseTextConverter <LicenseWithSlightlyChangedHardware> >(temp);
                Assert.IsTrue(license.IsValid());
            }
        }
コード例 #4
0
        public void InvalidIfHardwareConfigurationChanged()
        {
            using (var temp = new TemporaryFile())
            {
                var contact = ContactFactory.Create <Contact>();
                var license = LicenseFactory.Create <License>(contact);

                LicenseWriter.ToFile(temp, license);

                license = LicenseReader.FromFile <LicenseWithChangedHardware, IniLicenseTextConverter <LicenseWithChangedHardware> >(temp);
                Assert.IsFalse(license.IsValid());
            }
        }
コード例 #5
0
        public void SelfIssuedLicense()
        {
            using (var temp = new TemporaryFile())
            {
                var contact = ContactFactory.Create <Contact>();
                var license = LicenseFactory.Create <License>(contact);

                LicenseWriter.ToFile(temp, license);

                license = LicenseReader.FromFile(temp);
                Assert.IsTrue(license.IsValid());
            }
        }