Ejemplo n.º 1
0
    public void TestKeyModification() {

      for(int i = 0; i < 4; ++i) {
        for(int j = 0; j < 8; ++j) {

          LicenseKey testKey = new LicenseKey(
            new Guid(-1, -1, -1, 255, 255, 255, 255, 255, 255, 255, 255)
          );

          string originalString = testKey.ToString();
          testKey[i] &= ~(1 << j);
          string modifiedString = testKey.ToString();

          Assert.IsTrue(
            originalString != modifiedString, "Modified string differs from original"
          );

          testKey[i] |= (1 << j);
          string revertedString = testKey.ToString();

          Assert.AreEqual(
            originalString, revertedString, "Original state restorable"
          );

        } // for j
      } // for i

    }
Ejemplo n.º 2
0
        public void TestGuidKeyConversion()
        {
            for (int i = 0; i < 128; ++i)
            {
                // Create a new BitArray with the n.th bit set
                BitArray guidBits = new BitArray(128);
                guidBits[i] = true;

                // Create a GUID from this Bitarray
                byte[] guidBytes = new byte[16];
                guidBits.CopyTo(guidBytes, 0);
                Guid originalGuid = new Guid(guidBytes);

                // Convert the GUID into a license key and back to a GUID
                string licenseKey  = new LicenseKey(originalGuid).ToString();
                Guid   rebuiltGuid = LicenseKey.Parse(licenseKey).ToGuid();

                // Verify that the original GUID matches the fore-and-back converted one
                Assert.AreEqual(originalGuid, rebuiltGuid, "Test for GUID bit " + i);
            }
        }
Ejemplo n.º 3
0
    public void TestGuidKeyConversion() {

      for(int i = 0; i < 128; ++i) {

        // Create a new BitArray with the n.th bit set
        BitArray guidBits = new BitArray(128);
        guidBits[i] = true;

        // Create a GUID from this Bitarray
        byte[] guidBytes = new byte[16];
        guidBits.CopyTo(guidBytes, 0);
        Guid originalGuid = new Guid(guidBytes);

        // Convert the GUID into a license key and back to a GUID
        string licenseKey = new LicenseKey(originalGuid).ToString();
        Guid rebuiltGuid = LicenseKey.Parse(licenseKey).ToGuid();

        // Verify that the original GUID matches the fore-and-back converted one
        Assert.AreEqual(originalGuid, rebuiltGuid, "Test for GUID bit " + i);

      }

    }
Ejemplo n.º 4
0
    public void TestToByteArray() {
      Guid someGuid = Guid.NewGuid();
      LicenseKey someKey = new LicenseKey(someGuid);

      CollectionAssert.AreEqual(someGuid.ToByteArray(), someKey.ToByteArray());
    }
Ejemplo n.º 5
0
 public void TestSetByIndexerWithInvalidIndex() {
   LicenseKey key = new LicenseKey();
   Assert.Throws<IndexOutOfRangeException>(
     delegate() { key[-1] = 0; }
   );
 }
Ejemplo n.º 6
0
 public void TestGetByIndexerWithInvalidIndex() {
   LicenseKey key = new LicenseKey();
   Assert.Throws<IndexOutOfRangeException>(
     delegate() { Console.WriteLine(key[-1]); }
   );
 }
Ejemplo n.º 7
0
 public void TestParseInvalidLicenseKey()
 {
     Assert.Throws <ArgumentException>(
         delegate() { LicenseKey.Parse("hello world"); }
         );
 }