private void SimulateTimeElapse(IMicrowaveOvenControler ctrl, uint seconds)
 {
     while (seconds > 0)
     {
         ctrl.OneSecondTick();
         seconds--;
     }
 }
 public void US7_When_I_open_the_door_twice(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
 {
     using (var ctx = new MicrowaveTestSetup(ctrl, hw))
     {
         // simulate door open twice - does it make any sense?
         ctx.Ui.OpenDoor();
         ctx.Ui.OpenDoor();
     }
 }
        public void US1_When_I_open_door_Light_is_on(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
        {
            using (var ctx = new MicrowaveTestSetup(ctrl, hw))
            {
                // simulate door open
                ctx.Ui.OpenDoor();

                Assert.IsTrue(ctx.Hw.LightOn, "ensure the light is on after door closing");
            }
        }
        public void US2_When_I_close_door_Light_turns_off(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
        {
            using (var ctx = new MicrowaveTestSetup(ctrl, hw))
            {
                // simulate door open
                ctx.Ui.OpenDoor();
                Assert.IsTrue(ctx.Hw.LightOn, "ensure the light is on after door closing");

                // simulate door close
                ctx.Ui.CloseDoor();
                Assert.IsFalse(ctx.Hw.LightOn, "ensure the light is off after door closing");
            }
        }
Example #5
0
        public MicrowaveTestSetup(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
        {
            Ctrl = ctrl;
            Hw   = hw;

            Hw.Initialize();
            Ctrl.Initialize(Hw);

            // ensure the heater is off and the door closed - default initial state
            Assert.IsFalse(Hw.HeaterOn);
            Assert.IsFalse(Hw.DoorOpen);
            Assert.IsFalse(Hw.LightOn);
        }
        public void US3_When_I_open_door_heater_stops_if_running(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
        {
            using (var ctx = new MicrowaveTestSetup(ctrl, hw))
            {
                // simulate press start button - start heating
                ctx.Ui.PressStartButton();

                Assert.IsTrue(ctx.Hw.HeaterOn, "ensure the heater has been started after 'PressStartButton'");

                // simulate door open
                ctx.Ui.OpenDoor();

                Assert.IsFalse(ctx.Hw.HeaterOn, "ensure the heater has been stopped after opening the door");
                Assert.IsTrue(ctx.Hw.LightOn, "ensure if light is on after opening the door");
            }
        }
        public void US4_When_I_press_start_button_when_door_is_open_nothing_happens(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
        {
            using (var ctx = new MicrowaveTestSetup(ctrl, hw))
            {
                // simulate door open
                ctx.Ui.OpenDoor();

                Assert.IsTrue(ctx.Hw.DoorOpen, "ensure if door state is correct");
                Assert.IsTrue(ctx.Hw.LightOn, "ensure the light is on");
                Assert.IsFalse(ctx.Hw.HeaterOn, "ensure the heater is off");

                // simulate press start button
                ctx.Ui.PressStartButton();

                Assert.IsFalse(ctx.Hw.HeaterOn, "ensure if heating has not been started after 'PressStartButton'");
            }
        }
        public void US5_When_button_pressed_and_door_closed_heater_runs_for_1_minute(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
        {
            using (var ctx = new MicrowaveTestSetup(ctrl, hw))
            {
                // simulate press start button
                ctx.Ui.PressStartButton();

                Assert.IsTrue(ctx.Hw.HeaterOn, "ensure the heater has been started after 'PressStartButton'");

                SimulateTimeElapse(ctx.Ctrl, 59);

                Assert.IsTrue(ctx.Hw.HeaterOn, "ensure the heater is on 1 second before the end of heating");

                SimulateTimeElapse(ctx.Ctrl, 1);

                Assert.IsFalse(ctx.Hw.HeaterOn, "ensure the heater is off when 60 second elapsed");
            }
        }
        public void US3_When_I_open_door_heater_stops_if_running_ensure_total_time(IMicrowaveOvenControler ctrl, IMicrowaveOvenHWEx hw)
        {
            using (var ctx = new MicrowaveTestSetup(ctrl, hw))
            {
                // simulate press start button - start heating
                ctx.Ui.PressStartButton();

                Assert.IsTrue(ctx.Hw.HeaterOn, "ensure the heater has been started after 'PressStartButton'");

                // simulate door open
                ctx.Ui.OpenDoor();

                // simulate time elapsed - should not change enything
                SimulateTimeElapse(ctx.Ctrl, 60);

                // simulate door close
                ctx.Ui.CloseDoor();

                SimulateTimeElapse(ctx.Ctrl, 59);

                Assert.IsTrue(ctx.Hw.HeaterOn, "ensure the heater is still running");
                Assert.IsFalse(ctx.Hw.LightOn, "ensure if light is of after closing the door");
            }
        }