private ILock CreateLockedLock(string expectedSignature) { var lockedLock = new BasicLock(expectedSignature); lockedLock.Lock(new BasicKey(expectedSignature)); _locks.Add(lockedLock); return(lockedLock); }
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)); }
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)); }
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); }
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"); } }
public BasicLockTest() { sut = new BasicLock("WorkingKey"); _invalidKey = new BasicKey("InvalidKey"); _workingKey = new BasicKey("WorkingKey"); }