Beispiel #1
0
        private void RegistrationButton_Click(object sender, EventArgs e)
        {
            TNTServicesClient client = new TNTServicesClient("BasicHttpBinding_ITNTServicesContracts");
            User user = new Objects.User()
            {
                Address      = StreetAddressTextBox.Text,
                City         = CityTextBox.Text,
                EmailAddress = EmailAddressTextBox.Text,
                Name         = NameTextBox.Text,
                PhoneNumber  = PhoneNumberTextBox.Text,
                State        = StateTextBox.Text,
                Zip          = ZipTextBox.Text
            };

            Objects.License license = client.RequestLicense(user, new Guid(ApplicationIDComboBox.SelectedItem.ToString()));

            Clipboard.SetText(license.Key);

            MessageBox.Show(this, string.Format("{0}\n\nAlso copied to clipboard.", license.Key), "License Key");
        }
        public void RequestLicenseAuthorizationTests()
        {
            DateTime now = DateTime.Now;

            User user = new User()
            {
                Address      = "Address",
                City         = "City",
                EmailAddress = "EmailAddress",
                Name         = "Name",
                PhoneNumber  = "PhoneNumber",
                State        = "State",
                Zip          = "Zip"
            };

            Guid guid = new Guid("5fd3560a-0efd-4e48-9df9-c4fa3f44ba15");

            License license = m_TNTClient.RequestLicense(user, guid);

            Assert.IsTrue(Regex.IsMatch(license.Key, "[A-Z]{4}(-[A-Z]{4}){4}"));
            Assert.AreEqual(guid, license.Application.ID);
            Assert.AreEqual("Name", license.IssuedTo.Name);
            Assert.AreEqual("Address", license.IssuedTo.Address);
            Assert.AreEqual("City", license.IssuedTo.City);
            Assert.AreEqual("EmailAddress", license.IssuedTo.EmailAddress);
            Assert.AreEqual("PhoneNumber", license.IssuedTo.PhoneNumber);
            Assert.AreEqual("State", license.IssuedTo.State);
            Assert.AreEqual("Zip", license.IssuedTo.Zip);
            Assert.IsTrue(license.IssuedOn > now);

            string hardwareID = Registration.GetVolumeSerialNumber();
            string authKey    = m_TNTClient.GetAuthorizationKey(hardwareID, guid, license.Key);

            Assert.AreEqual(Registration.GenerateSHA1Hash(string.Concat(hardwareID, guid.ToString(), license.Key)), authKey);
            Assert.AreNotEqual(Registration.GenerateSHA1Hash(string.Concat("bogushardwareid", guid.ToString(), license.Key)), authKey);
        }