public void StandardLicenseTest()
        {
            Dictionary <string, string> values = StandardLicenseBuilder.Build("to-me", null, "*****@*****.**", "00200", 4);
            string licenseFolder = System.IO.Path.GetTempPath();
            string fileName      = "UTTest.lic";
            string filePath      = System.IO.Path.Combine(licenseFolder, fileName);

            using (System.IO.Stream fileStream = new System.IO.FileStream(filePath, FileMode.Create))
            {
                LicenseWriter.Write(values, new TestSigner(), fileStream);
            }
            IStandardLicense license = new TestLicense();

            Assert.That(license.Status, Is.EqualTo(LicenseStatus.NotLoaded));
            license.Load(licenseFolder);
            Assert.That(license.Status, Is.EqualTo(LicenseStatus.Active));
            Assert.That(license.LicensedTo, Is.EqualTo("to-me"), "wrong licensedto");
            Assert.That(license.LicenseTitle, Is.EqualTo("Test License"), "wrong license title");
            Assert.That(license.ExpirationDate, Is.Null, "Expiration date is not null");
            Assert.That(license.AttributeSummary, Is.EqualTo("Attribs"), "wrong attribs");
            Assert.That(license.SerialNumber, Is.EqualTo("00200"), "wrong serial number");
            Assert.That(license.EmailAddress, Is.EqualTo("*****@*****.**"), "wrong email address");
            Assert.That(license.LicenseVersion, Is.EqualTo(4), "wrong license version");
            Assert.That(license.Values[StandardLicenseBuilder.EmailAddressKey], Is.EqualTo("*****@*****.**"), "bad dictionary");
        }
        public void LicenseValid()
        {
            Dictionary <string, string> values = new Dictionary <string, string>();

            values.Add("Animal1", "Cat");
            values.Add("Animal2", "Winged Horse");
            MemoryStream licenseStream = new MemoryStream();

            LicenseWriter.Write(values, new TestSigner(), licenseStream);
            licenseStream.Position = 0;
            Dictionary <string, string> decodedValues = LicenseReader.Read(licenseStream, new TestValidator());

            Assert.That(decodedValues.Count, Is.EqualTo(2), "Wrong number of license values");
            Assert.That(decodedValues["Animal1"], Is.EqualTo("Cat"), "Animal1 should have been Cat");
            Assert.That(decodedValues["Animal2"], Is.EqualTo("Winged Horse"), "Animal2 should have been Winged Horse");
        }
        public void StandardLicenseNotExpired()
        {
            Dictionary <string, string> values = StandardLicenseBuilder.Build("to-me", DateTime.Today.AddDays(1.0D), "*****@*****.**", "00200", 4);
            string licenseFolder = System.IO.Path.GetTempPath();
            string fileName      = "UTTest.lic";
            string filePath      = System.IO.Path.Combine(licenseFolder, fileName);

            using (System.IO.Stream fileStream = new System.IO.FileStream(filePath, FileMode.Create))
            {
                LicenseWriter.Write(values, new TestSigner(), fileStream);
            }
            IStandardLicense license = new TestLicense();

            Assert.That(license.Status, Is.EqualTo(LicenseStatus.NotLoaded));
            license.Load(licenseFolder);
            Assert.That(license.Status, Is.EqualTo(LicenseStatus.Active));
            Assert.That(license.LicensedTo, Is.EqualTo("to-me"), "wrong licensedto");
            Assert.That(license.LicenseTitle, Is.EqualTo("Test License"), "wrong license title");
        }
        public void LicenseSignatureInvalid1()
        {
            Dictionary <string, string> values = new Dictionary <string, string>();

            values.Add("Animal1", "Cat");
            values.Add("Animal2", "Winged Horse");
            MemoryStream licenseStream = new MemoryStream();

            LicenseWriter.Write(values, new TestSigner(), licenseStream);
            licenseStream.Position = 150;
            licenseStream.WriteByte(1);
            licenseStream.Position = 0;
            try
            {
                Dictionary <string, string> decodedValues = LicenseReader.Read(licenseStream, new TestValidator());
                Assert.Fail("Should have thrown exception");
            }
            catch (InvalidDataException)
            {
            }
        }