Exemplo n.º 1
0
        public void GarageDoorTest()
        {
            Remotes    remote = new Remotes();
            GarageDoor door   = new GarageDoor();

            Assert.AreEqual(door.LightState, GarageDoor.LightStates.Off);
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Down);
            DoorUpCommand   doorUp   = new DoorUpCommand(door);
            DoorDownCommand doorDown = new DoorDownCommand(door);

            remote.SetCommand(doorUp);
            remote.ButtonWasPressed();

            // Make sure that the door went up and the light turned on
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);
            Assert.AreEqual(door.LightState, GarageDoor.LightStates.On);

            remote.ButtonWasPressed();

            // Make sure that the door stayed up and the light stayed on after a second door up command
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);
            Assert.AreEqual(door.LightState, GarageDoor.LightStates.On);

            door.AddObstruction();

            remote.SetCommand(doorDown);
            remote.ButtonWasPressed();

            // Make sure the door did not start closing when an obstruction was in the way
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);

            door.RemoveObstruction();
            remote.ButtonWasPressed();

            // Make sure that the door started ot go down when the button was pressed
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.GoingDown);

            door.AddObstruction();

            remote.ButtonWasPressed();

            // Make sure the door detected that something was in the way when is was coming down and went back up
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);

            door.RemoveObstruction();

            remote.ButtonWasPressed();
            remote.ButtonWasPressed();


            // Make sure that when there are no obstructions and the button is pressed twice that the door closes
            // and the light turns off
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Down);
            Assert.AreEqual(door.LightState, GarageDoor.LightStates.Off);
        }