コード例 #1
0
        public void HandleTemperatureChangedWithAlerterTest()
        {
            var alertIssued = false;
            var alert       = new BidirectionalAlert("test", 10.5m, 1m, () =>
            {
                alertIssued = true;
            });

            var alertList = new List <IAlerter>
            {
                alert
            };

            var thermometer = new AlerterThermometer(Unit.Celsius, null, alertList);

            thermometer.UpdateTemperature(new Temperature(0.5m, Unit.Celsius));
            thermometer.UpdateTemperature(new Temperature(10.5m, Unit.Celsius));
            Assert.Equal(10.5m, thermometer.Temperature.Value);
            Assert.Equal(Unit.Celsius, thermometer.Temperature.Unit);
            Assert.Equal(true, alertIssued);
        }
コード例 #2
0
        public void HandleTemperatureChangedWithSameUnit(Unit unit)
        {
            var converter = new Mock <ITemperatureConverter>();

            converter.Setup(x => x.Convert(It.IsAny <ITemperature>(), It.IsAny <Unit>()))
            .Returns(new Temperature(0.5m, Unit.Celsius));

            var alerterMock = new Mock <IAlerter>();
            var thermometer = new AlerterThermometer(unit, converter.Object, new List <IAlerter> {
                alerterMock.Object
            });

            thermometer.UpdateTemperature(new Temperature(10.5m, unit));

            Assert.Equal(10.5m, thermometer.Temperature.Value);
            Assert.Equal(unit, thermometer.Temperature.Unit);

            thermometer.UpdateTemperature(new Temperature(5.5m, unit));
            Assert.Equal(5.5m, thermometer.Temperature.Value);
            Assert.Equal(unit, thermometer.Temperature.Unit);
        }