コード例 #1
0
 public static void TestAddNewKnownKey()
 {
     KnownKeys knownKeys = new KnownKeys();
     AesKey key = new AesKey();
     knownKeys.Add(key);
     Assert.That(knownKeys.Keys.First(), Is.EqualTo(key), "The first and only key should be the one just added.");
 }
コード例 #2
0
 public static void TestAddSameKeyTwice()
 {
     KnownKeys knownKeys = new KnownKeys();
     AesKey key = new AesKey();
     knownKeys.Add(key);
     knownKeys.Add(key);
     Assert.That(knownKeys.Keys.Count(), Is.EqualTo(1), "Only one key should be in the collection even if added twice.");
     Assert.That(knownKeys.Keys.First(), Is.EqualTo(key), "The first and only key should be the one just added.");
 }
コード例 #3
0
 public static void TestAddTwoNewKnownKeys()
 {
     KnownKeys knownKeys = new KnownKeys();
     AesKey key1 = new AesKey();
     knownKeys.Add(key1);
     AesKey key2 = new AesKey();
     knownKeys.Add(key2);
     Assert.That(knownKeys.Keys.First(), Is.EqualTo(key2), "The first key should be the last one added.");
     Assert.That(knownKeys.Keys.Last(), Is.EqualTo(key1), "The last key should be the first one added.");
 }
コード例 #4
0
 private void Initialize(StreamingContext context)
 {
     _lock = new object();
     KnownKeys = new KnownKeys();
 }
コード例 #5
0
 public static void TestChangedEvent()
 {
     bool wasChanged = false;
     KnownKeys knownKeys = new KnownKeys();
     knownKeys.Changed += (object sender, EventArgs e) =>
     {
         wasChanged = true;
     };
     AesKey key1 = new AesKey();
     knownKeys.Add(key1);
     Assert.That(wasChanged, Is.True, "A new key should trigger the Changed event.");
     wasChanged = false;
     knownKeys.Add(key1);
     Assert.That(wasChanged, Is.False, "Re-adding an existing key should not trigger the Changed event.");
 }
コード例 #6
0
        public static void TestSettingNullDefaultEncryptionKey()
        {
            KnownKeys knownKeys = new KnownKeys();
            AesKey key1 = new AesKey();
            knownKeys.Add(key1);
            AesKey key2 = new AesKey();
            knownKeys.DefaultEncryptionKey = key2;

            Assert.That(knownKeys.Keys.Count(), Is.EqualTo(2), "Setting the DefaultEncryptionKey should also add it as a known key.");

            knownKeys.DefaultEncryptionKey = null;
            Assert.That(knownKeys.Keys.Count(), Is.EqualTo(2), "Setting the DefaultEncryptionKey to null should not affect the known keys.");
        }
コード例 #7
0
 public static void TestDefaultEncryptionKey()
 {
     KnownKeys knownKeys = new KnownKeys();
     AesKey key = new AesKey();
     knownKeys.DefaultEncryptionKey = key;
     Assert.That(knownKeys.DefaultEncryptionKey, Is.EqualTo(key), "The DefaultEncryptionKey should be the one just set as it.");
     Assert.That(knownKeys.Keys.Count(), Is.EqualTo(1), "Only one key should be in the collection.");
     Assert.That(knownKeys.Keys.First(), Is.EqualTo(key), "The first and only key should be the one just set as DefaultEncryptionKey.");
 }
コード例 #8
0
        public static void TestClear()
        {
            KnownKeys knownKeys = new KnownKeys();
            AesKey key1 = new AesKey();
            knownKeys.Add(key1);
            AesKey key2 = new AesKey();
            knownKeys.Add(key2);
            Assert.That(knownKeys.Keys.Count(), Is.EqualTo(2), "There should be two keys in the collection.");

            knownKeys.Clear();
            Assert.That(knownKeys.Keys.Count(), Is.EqualTo(0), "There should be zero keys in the collection after Clear().");
        }