Example #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);
                }
            }
        }
Example #2
0
        public void ConstructorTest()
        {
            var unit = Unit.Celsius;
            var freezingNotificationMock = NSubstitute.Substitute.For <INotification>();
            var boilingNotificationMock  = NSubstitute.Substitute.For <INotification>();

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

            Assert.AreEqual(unit, thermometer.ThermometerUnit);
            Assert.AreEqual(unit, thermometer.Temperature.Unit);
            Assert.AreEqual(0.0m, thermometer.Temperature.Value);
        }
Example #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);
        }
Example #4
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);
        }