public void LockEverything_Saves_Item() { // Arrange const bool expected = true; bool updateCalled = false; Lock lck = new Lock { IsUnlocked = !expected }; Mock <ILockRepository> mockRepository = new Mock <ILockRepository>(MockBehavior.Loose); mockRepository.Setup(m => m.GetAll()).Returns(new List <Lock> { lck }); mockRepository.Setup(m => m.Update(It.IsAny <Lock>())).Callback(() => updateCalled = true); // Act DoorLocker locker = new DoorLocker(mockRepository.Object); locker.LockEverything(expected); // Assert updateCalled.Should().Be(true, "It didn't save"); mockRepository.VerifyAll(); }
public void DoorLockerTest() { string COMPort = "COM9"; KioskoHardware.DoorLocker doorLocker = Helpers.Utilities.GetDoorLockerByName("ContainerReceiver"); DoorLocker door = new DoorLocker(doorLocker); door.IsOpen(0x01); door.Open(0x01); door.Open(0x05); door.Open(0x03); door.Open(0x04); door.Close(); }
public void SetsLockToUnlocked() { // Arrange const bool expected = true; Lock lck = new Lock { IsUnlocked = !expected }; // Act DoorLocker doorLocker = new DoorLocker(null); doorLocker.LockTheLock(lck, expected); // Assert lck.IsUnlocked.Should().Be(expected); }
public void GracefullyHandlesANullLock() { // Arrange const bool expected = false; Lock lck = null; // Act DoorLocker doorLocker = new DoorLocker(null); bool threw = false; try { doorLocker.LockTheLock(lck, expected); // Assert // We're still here, it worked } catch (ArgumentNullException ex) { ex.ParamName.Should().Be(typeof(Lock).Name); threw = true; } threw.Should().Be(true); }
public void LocksEverything(int expected, bool locked) { // Arrange int counter = 0; List <Lock> db = new List <Lock>(); for (int i = 0; i < expected; i++) { db.Add(new Lock { IsUnlocked = !locked }); } Mock <ILockRepository> lockRepository = this.GetMockLockRepository(db, () => counter++); // Act DoorLocker doorLocker = new DoorLocker(lockRepository.Object); doorLocker.LockEverything(locked); // Assert counter.Should().Be(expected, "it should call update for as many items as are in the list"); }