// TC-01
        [Test] public void StartCooking_TimerStarts_PowerTubeTurnsOn()
        {
            // Arrange
            int inputPower         = 350;
            int expectedPercentage = 50;
            int timerSetting       = 2;
            // Ensure test only executes once
            bool oneShot = true;

            // Act
            _sut.StartCooking(inputPower, timerSetting);
            // ref timer has 100ms extra to ensure the sut timer expires first
            _refTimer.Start(timerSetting + 1);

            while (_refTimer.TimeRemaining > 0)
            {
                if (oneShot)
                {
                    oneShot = false;

                    // Assert Power "consumption" in tube is expectedPercentage
                    _stubPowerTube.Received().TurnOn(expectedPercentage);
                }
            }
        }
Exemplo n.º 2
0
        public void CookController_StartCooking_WithReal_PowerTube(int power, int timeinsec)
        {
            _uut.StartCooking(power, timeinsec);
            string expectedout = $"PowerTube works with {power} W";

            _output.Received(1).OutputLine(Arg.Is <string>(txt => txt == expectedout));
        }
        public void StartCookController_PowerTubeIsValid_TurnOnCalledIsCalledWithPowerOutput(int power, int timer)
        {
            //Arrange
            _cookController.StartCooking(power, timer);

            //Assert
            _fakeOutput.Received(1).OutputLine($"PowerTube works with {power} W");
        }
Exemplo n.º 4
0
        public void OnTimerExpiredOutputIsCalled()
        {
            _uut.StartCooking(50, 1);

            Thread.Sleep(2000);

            _fakeOutput.Received().OutputLine($"PowerTube turned off");
        }
Exemplo n.º 5
0
        public void StartCookCalledStartTimer()
        {
            int time  = 2000;
            int power = 300;

            CC_.StartCooking(power, time);
            Assert.That(timer_.TimeRemaining, Is.EqualTo(time));
        }
Exemplo n.º 6
0
        public void StartCooking_ValidParameters_TimeStarted(int time)
        {
            _cookController.StartCooking(50, time);

            Assert.That(_timer.TimeRemaining, Is.EqualTo(time));

            _cookController.Stop();
        }
Exemplo n.º 7
0
        public void OnTimerEvent_TimeIsRemaining_DisplayIsUpdatedEachSecond(int sleepTimeMilliSeconds, int cookTimeSeconds, int numberOfEvents)
        {
            var power = 50;

            _cookController.StartCooking(power, cookTimeSeconds);
            Thread.Sleep(sleepTimeMilliSeconds);

            _display.Received(numberOfEvents).ShowTime(Arg.Any <int>(), Arg.Any <int>());
        }
        public void StartCooking_Called_TurnOn(int power)
        {
            _stringWriter = new System.IO.StringWriter();
            Console.SetOut(_stringWriter);
            int time = 30;

            _cookController.StartCooking(power, time);
            string expected = ($"PowerTube works with {power}");

            StringAssert.Contains(expected, _stringWriter.ToString());
        }
Exemplo n.º 9
0
        public void StartCooking_TimerTick_WaitForTick_DisplayShowTime()
        {
            ManualResetEvent pause = new ManualResetEvent(false);

            _timer.TimerTick += (sender, args) => pause.Set();
            _cookController.StartCooking(50, 60);

            // wait for one tick
            Assert.That(pause.WaitOne(1100));
            _display.Received(1).ShowTime(Arg.Any <int>(), Arg.Any <int>());
        }