Exemplo n.º 1
0
        public async void TestPowerSwitchOffWhenNoWater()
        {
            _kettleController = GetMockedKettleController(hasWater: false);
            await _kettleController.TogglePowerSwitch(true);

            var kettleStatus = _kettleController.KettleStatus;

            Assert.False(kettleStatus.HasWater);
            Assert.False(kettleStatus.PowerSwitch);
            Assert.False(kettleStatus.PowerLamp);
            Assert.False(kettleStatus.HeatingElement);
            Assert.True(kettleStatus.Temperature == 50);
        }
Exemplo n.º 2
0
        public async void TestHeatingElementExceptionHandling()
        {
            _kettleController = GetMockedKettleController(hasFaultInHeatingElement: true);

            await _kettleController.TogglePowerSwitch(true);

            var kettleStatus = _kettleController.KettleStatus;

            Assert.True(kettleStatus.HasWater);
            Assert.False(kettleStatus.PowerSwitch);
            Assert.False(kettleStatus.PowerLamp);
            Assert.False(kettleStatus.HeatingElement);
            Assert.True(kettleStatus.Temperature == 50);
        }
        public KettleControllerTests()
        {
            this.powerSwitch = new Mock<IPowerSwitch>();
            this.powerLamp = new Mock<IPowerLamp>();
            this.heatingElement = new Mock<IHeatingElement>();
            this.waterSensor = new Mock<IWaterSensor>();
            this.temperatureSensor = new Mock<ITemperatureSensor>();

            this.controller = new KettleController(this.powerSwitch.Object, 
            this.powerLamp.Object, 
            this.heatingElement.Object,
            this.waterSensor.Object,
            this.temperatureSensor.Object);
        }
Exemplo n.º 4
0
        private KettleController GetMockedKettleController(bool hasWater = true, int temperature = 50,
                                                           bool hasFaultInHeatingElement = false)
        {
            var powerSwitchMock = PowerSwitchMockSetup();

            var powerLampMock = PowerLampMockSetup();

            var temperatureSensorMock = TemperatureSensorMockSetup(temperature);

            var waterSensorMock = WaterSensorMockSetup(hasWater);

            var heatingElementMock = HeatingElementMockSetup(hasFaultInHeatingElement);

            // create KettleController instance
            var kettleControllerForTest = new KettleController(powerSwitchMock.Object, powerLampMock.Object,
                                                               temperatureSensorMock.Object, waterSensorMock.Object, heatingElementMock.Object);

            return(kettleControllerForTest);
        }
Exemplo n.º 5
0
        public async void TestPowerSwitchOffAt100Degree()
        {
            _kettleController = GetMockedKettleController(temperature: 100);
            await _kettleController.TogglePowerSwitch(true);

            var kettleStatus = _kettleController.KettleStatus;

            // Re-fetch status data since the triggered event needs to refresh status data;
            if (kettleStatus.PowerSwitch)
            {
                Thread.Sleep(100);
                kettleStatus = _kettleController.KettleStatus;
            }

            Assert.True(kettleStatus.HasWater);
            Assert.False(kettleStatus.PowerSwitch);
            Assert.False(kettleStatus.PowerLamp);
            Assert.False(kettleStatus.HeatingElement);
            Assert.True(kettleStatus.Temperature == 100);
        }
Exemplo n.º 6
0
 public KettleControllerTest()
 {
     _kettleController = GetMockedKettleController();
 }