Example #1
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Starting Application");
            System.Console.WriteLine();

            // Will create the License file
            LicenseCreator licenseCreator = new LicenseCreator();

            // Will read the existing license file for details
            LicenseReader licenseReader = new LicenseReader();

            // Specify license details
            string      expirationDate = "20160901";
            string      clientDetails  = "Peter&Ted Co.";
            LicenseType licenseType    = LicenseType.Demo;

            // Create new License file
            var dataString = licenseCreator.Create(expirationDate, clientDetails, licenseType);

            System.Console.Write("Data string created: ");
            System.Console.WriteLine(dataString);
            System.Console.WriteLine();

            // Read the data in the newly created license file
            var licenseData = licenseReader.Read();

            System.Console.Write("Data read: ");
            System.Console.WriteLine(licenseData);

            System.Console.WriteLine();
            System.Console.Write("Press ANY KEY to terminate");
            System.Console.ReadLine();
        }
        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 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)
            {
            }
        }