Exemple #1
0
            public void Should_throw_an_ImpossibleToPickTheLockException_when_the_lock_cannot_be_opened()
            {
                // Arrange
                var sut   = new PredefinedPicklock(new[] { "key2" });
                var @lock = new BasicLock("key1");

                // Act & Assert
                Assert.Throws <ImpossibleToPickTheLockException>(() => sut.Pick(@lock));
            }
Exemple #2
0
            public void Should_throw_an_ImpossibleToPickTheLockException_when_no_matching_key_can_be_generated()
            {
                // Arrange
                var sut   = new PredefinedPicklock(new[] { "key2" });
                var @lock = new BasicLock("key1");

                // Act & Assert
                Assert.Throws <ImpossibleToPickTheLockException>(() => sut.CreateMatchingKeyFor(@lock));
            }
Exemple #3
0
            public void Should_unlock_the_specified_ILock(ILock @lock)
            {
                // Arrange
                Assert.True(@lock.IsLocked, "The lock should be locked.");
                var sut = new PredefinedPicklock(new[] { "key1", "key2", "key3" });

                // Act
                sut.Pick(@lock);

                // Assert
                Assert.False(@lock.IsLocked, "The lock should be unlocked.");
            }
Exemple #4
0
            public void Should_return_the_matching_key_when_provided()
            {
                // Arrange
                var sut   = new PredefinedPicklock(new[] { "key1" });
                var @lock = new BasicLock("key1");

                // Act
                var key = sut.CreateMatchingKeyFor(@lock);

                // Assert
                Assert.NotNull(key);
                Assert.Equal("key1", key.Signature);
            }
Exemple #5
0
        public void Multiple_keys_with_the_same_signature_should_fit_the_same_lock()
        {
            ILock @lock = new BasicLock("key1");

            var picklock = new PredefinedPicklock(new[] { "key1" });
            var fakeKey  = picklock.CreateMatchingKeyFor(@lock);

            LockAndAssertResult(new BasicKey("key1"));
            LockAndAssertResult(new BasicKey("key1"));
            LockAndAssertResult(fakeKey);

            void LockAndAssertResult(IKey key)
            {
                var result = @lock.DoesMatch(key);

                Assert.True(result, $"The key '{key.Signature}' should fit the lock");
            }
        }