示例#1
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));
            }
示例#2
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);
            }
示例#3
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");
            }
        }