Ejemplo n.º 1
0
        public void BasicUsageTest()
        {
            foreach (var temperature in temperatures)
            {
                thermometer.UpdateTemperature(temperature);
            }

            Assert.Equal(4, numberOfAlert1);
            Assert.Equal(1, numberOfAlert2);
            Assert.Equal(2, numberOfAlert3);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var converter = new TemperatureConverter(new ConverterFactory(
                                                         new List <IUnitConverter>
            {
                new CelsiusConverter(),
                new FahrenheitConverter()
            }));

            var alerters = new List <IAlerter>
            {
                new DropAlert("Freezing alert", 0.0m, 0.5m, () => Console.WriteLine("----Freezing Alert------s")),
                new RaiseAlert("Boiling alert", 100, 0.5m, () => Console.WriteLine("----Boiling Alert----")),
                new BidirectionalAlert("Nice temperature alert", 28.0m, 1m, async() =>
                {
                    Console.WriteLine("----Really nice temperature starting a long process to notify everyone-------");
                    await Task.Delay(3000);
                    Console.WriteLine("----end of the really nice notification process-------");
                })
            };

            thermometer = new AlerterThermometer(Unit.Celsius, converter, alerters);


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

                    Thread.Sleep(1000);
                }
            }
        }