private static void TestObserverPattern() { WeatherData weatherData = new WeatherData(); TemperatureReporter temperatureReporter = new TemperatureReporter(); CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); CurrentTemperatureDisplay currentTemperatureDisplay = new CurrentTemperatureDisplay(temperatureReporter); Temperature t = new Temperature { Temp = 80 }; temperatureReporter.TemperatureChanged(t); t.Temp = 82; temperatureReporter.TemperatureChanged(t); Console.WriteLine(currentTemperatureDisplay.Display()); t.Temp = 78; temperatureReporter.TemperatureChanged(t); Console.WriteLine(currentTemperatureDisplay.Display()); weatherData.SetMeasurements(80, 65, 30.4); weatherData.SetMeasurements(82, 70, 29.2); weatherData.SetMeasurements(78, 90, 29.2); Console.WriteLine(currentConditionsDisplay.Display()); Console.WriteLine(statisticsDisplay.Display()); Console.WriteLine(forecastDisplay.Display()); Console.WriteLine(heatIndexDisplay.Display()); }
public void TestObserver() { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); //HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(50, 65, 30.4f); Assert.Equal("Temperature is " + 50 + " and " + 65, currentDisplay.Display()); weatherData.SetMeasurements(92, 70, 29.2f); Assert.Equal("Temperature is " + 92 + " and " + 70, currentDisplay.Display()); weatherData.SetMeasurements(78, 90, 29.1f); Assert.Equal("Temperature is " + 78 + " and " + 90, currentDisplay.Display()); }
public void WhenCreateCurrentConditionsDisplayAndCallSetMeasurementsMethodExpectDisplayMethodReturnCurrentConditionsMessage() { var weatherData = new WeatherData(); var currentConditionsDisplay = new CurrentConditionsDisplay(weatherData); weatherData.SetMeasurements(80, 50, 80); Assert.AreEqual("Current conditions: 80 F degrees and 50 % humidity", currentConditionsDisplay.Display()); }
public void CurrentConditionsDisplay_ShouldDisplay_WhenMeasurementsChanged() { //Act _weatherData.SetMeasurements(80, 65, 30.4f); var display = _currentConditionsDisplay.Display(); //Assert display.Should().Be("Current conditions: 80F degrees and 65% humidity"); }
public void weather_data_updates_observers_correctly() { var wd = new WeatherData(); var conditions = new CurrentConditionsDisplay(wd); var heat = new HeatIndexDisplay(wd); var stats = new StatisticsDisplay(wd); var forecast = new ForecastDisplay(wd); wd.SetMeasurements(80, 65, 30.4f); Assert.AreEqual("Current Conditions: 80 celsius and humidity 65", conditions.Display()); Assert.AreEqual("Heat index is 82.95535", heat.Display()); Assert.AreEqual("Avg/Max/Min Temperature: 80/80/80", stats.Display()); Assert.AreEqual("Improving weather on the way!", forecast.Display()); wd.SetMeasurements(78, 90, 29.2f); Assert.AreEqual("Current Conditions: 78 celsius and humidity 90", conditions.Display()); Assert.AreEqual("Heat index is 83.64967", heat.Display()); Assert.AreEqual("Avg/Max/Min Temperature: 79/80/78", stats.Display()); Assert.AreEqual("Weather is getting bad!", forecast.Display()); }
public void WhenCreateDisplayAndCallSetMeasurementsMethodExpectAllObserversAreNotified() { var weatherData = new WeatherData(); var currentConditionsDisplay = new CurrentConditionsDisplay(weatherData); var forecastDisplay = new ForecastDisplay(weatherData); weatherData.SetMeasurements(80, 50, 80); Assert.AreEqual("Current conditions: 80 F degrees and 50 % humidity", currentConditionsDisplay.Display()); Assert.AreEqual("Forecast: Improving weather on the way!", forecastDisplay.Display()); }
public void TestMethod1_WeatherStation() { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4f); weatherData.SetMeasurements(82, 70, 29.2f); weatherData.SetMeasurements(78, 90, 29.2f); var result = currentDisplay.Display(); }
public void WeatherStationHeatIndexTest() { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.SetMeasurements(80, 65, 30.4f); weatherData.SetMeasurements(82, 70, 29.2f); weatherData.SetMeasurements(78, 90, 29.2f); currentDisplay.Display(); statisticsDisplay.Display(); forecastDisplay.Display(); heatIndexDisplay.Display(); }