Esempio n. 1
0
        static void Main(string[] args)
        {
            IThermometer thermometer;
            var          freezingNotification = new FreezingNotification("Freezing notification", 0.0m, 0.5m, () => Console.WriteLine("----Freezing!!!------"));
            var          boilingNotification  = new BoilingNotification("Boiling notification", 100, 0.5m, () => Console.WriteLine("----Boiling Alert!!!----"));

            thermometer = new AdvancedThermometer(Unit.Celsius, freezingNotification, boilingNotification);


            for (var i = 0; i < 2; i++)
            {
                foreach (var temperature in GetTemperatures())
                {
                    Console.WriteLine($"new temp received {temperature}");
                    try
                    {
                        thermometer.UpdateTemperature(temperature);
                        Console.WriteLine($" -- >temp in Thermometer {thermometer.Temperature}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine();
                        Console.WriteLine(ex.Message);
                    }

                    Thread.Sleep(1000);
                }
            }
        }
Esempio n. 2
0
        public void HandleTemperatureChangedWithSameUnit()
        {
            var unit = Unit.Celsius;
            var freezingNotificationMock = NSubstitute.Substitute.For <INotification>();
            var boilingNotificationMock  = NSubstitute.Substitute.For <INotification>();

            var thermometer = new AdvancedThermometer(unit,
                                                      freezingNotificationMock, boilingNotificationMock);

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

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

            thermometer.UpdateTemperature(new Temperature(5.5m, unit));
            Assert.AreEqual(5.5m, thermometer.Temperature.Value);
            Assert.AreEqual(unit, thermometer.Temperature.Unit);
        }
Esempio n. 3
0
        public void HandleTemperatureChangedWithDifferentUnit()
        {
            var unit = Unit.Fahrenheit;
            var freezingNotificationMock = NSubstitute.Substitute.For <INotification>();
            var boilingNotificationMock  = NSubstitute.Substitute.For <INotification>();

            var thermometer = new AdvancedThermometer(Unit.Celsius,
                                                      freezingNotificationMock, boilingNotificationMock);


            thermometer.UpdateTemperature(new Temperature(32.0m, unit));
            Assert.AreEqual(0.0m, thermometer.Temperature.Value);
            Assert.AreEqual(Unit.Celsius, thermometer.Temperature.Unit);
        }