static void Main() { CWeatherData weatherDataIn = new CWeatherData(); CWeatherData weatherDataOut = new CWeatherData(); Display display = new Display(weatherDataIn, weatherDataOut); weatherDataIn.RegisterObserver(display, 2); weatherDataOut.RegisterObserver(display, 2); StatsDisplay statsDisplay = new StatsDisplay(weatherDataIn, weatherDataOut); weatherDataIn.RegisterObserver(statsDisplay, 0); weatherDataOut.RegisterObserver(statsDisplay, 1); StatsDisplay statsDisplay1 = new StatsDisplay(weatherDataIn, weatherDataOut); weatherDataOut.RegisterObserver(statsDisplay1, 0); weatherDataIn.SetMeasurements(3, 0.7, 760); weatherDataOut.SetMeasurements(4, 0.8, 761); weatherDataOut.RemoveObserver(statsDisplay); weatherDataIn.SetMeasurements(10, 0.8, 761); weatherDataOut.SetMeasurements(-10, 0.8, 761); }
public void Can_remove_observer_on_update() { CWeatherData wd = new CWeatherData(); CTestRemovebleObserver display1 = new CTestRemovebleObserver(wd); wd.RegisterObserver(display1); wd.SetMeasurements(3, 0.7, 760); Assert.IsTrue(display1.IsRemoved); display1.IsRemoved = false; wd.SetMeasurements(4, 0.8, 761); Assert.IsFalse(display1.IsRemoved); }
public CWeatherStationDuo() { CWeatherData wdIn = new CWeatherData(LocationType.INSIDE); CWeatherData wdOut = new CWeatherData(LocationType.OUTSIDE); CDisplay display = new CDisplay(wdIn, wdOut); CStatsDisplay statsDisplay = new CStatsDisplay(wdIn, wdOut); wdIn.SetMeasurements(3, 0.7, 760); wdOut.SetMeasurements(4, 0.8, 761); wdIn.RemoveObserver(statsDisplay); wdIn.SetMeasurements(5, 0.9, 762); }
public CWeatherStationPro() { CWeatherData wd = new CWeatherData(); CDisplay display = new CDisplay(); wd.RegisterObserver(display); CStatsDisplay statsDisplay = new CStatsDisplay(); wd.RegisterObserver(statsDisplay); wd.SetMeasurements(3, 0.7, 760, 10, 0); wd.SetMeasurements(4, 0.8, 761, 8, 630); }
public CWeatherStationProEvents() { CWeatherData wd = new CWeatherData(); CDisplay display = new CDisplay(); wd.RegisterObserver(display); wd.OnTemperatureChanged += display.UpdateTemperature; wd.Temperature = 200; CStatsDisplay statsDisplay = new CStatsDisplay(); wd.RegisterObserver(statsDisplay); wd.SetMeasurements(3, 0.7, 760, 10, 0); wd.SetMeasurements(4, 0.8, 761, 8, 630); }
public void RemoveObserverInUpdate_ShouldNotThrownException() { CWeatherData wd = new CWeatherData(); TestUpdateObserver to = new TestUpdateObserver(wd); wd.RegisterObserver(to, 1); wd.SetMeasurements(3, 0.7, 760); }
public void TestDeliteObserver() { var weatherData = new CWeatherData(); var customObserver = new CustomObserver(weatherData); weatherData.RegisterObserver(customObserver, 0); weatherData.SetMeasurements(0, 0, 0); }
public CWeatherStation() { CWeatherData wd = new CWeatherData(); CDisplay display = new CDisplay(); wd.RegisterObserver(display); CStatsDisplay statsDisplay = new CStatsDisplay(); wd.RegisterObserver(statsDisplay); wd.SetMeasurements(3, 0.7, 760); wd.SetMeasurements(4, 0.8, 761); wd.RemoveObserver(statsDisplay); wd.SetMeasurements(10, 0.8, 761); wd.SetMeasurements(-10, 0.8, 761); }
static void Main() { CWeatherData wd = new CWeatherData(); Display display = new Display(); wd.RegisterObserver(display, 1); StatsDisplay statsDisplay = new StatsDisplay(); wd.RegisterObserver(statsDisplay, 0); wd.SetMeasurements(3, 0.7, 760, 4, 60); wd.SetMeasurements(4, 0.8, 761, 2, 90); wd.RemoveObserver(display); wd.SetMeasurements(10, 0.7, 760, 4, 270); wd.SetMeasurements(-10, 0.8, 761, 8, 180); }
static void Main(string [] args) { var wd = new CWeatherData(); var display1 = new CDisplay(); var display2 = new CDisplay(); var statsDisplay = new CStatsDisplay(); wd.RegisterObserver(display1, 10); wd.RegisterObserver(display2, 3); wd.RegisterObserver(statsDisplay, 4); wd.SetMeasurements(3, 0.7, 760); wd.SetMeasurements(4, 0.8, 761); wd.RemoveObserver(display1); wd.RemoveObserver(display2); wd.SetMeasurements(10, 0.8, 761); wd.SetMeasurements(-10, 0.8, 761); }
public void Cant_remove_not_added_observer() { CTestingDisplay.ResetUpdateCounter(); CWeatherData wd = new CWeatherData(); CTestingDisplay display1 = new CTestingDisplay(); display1.SetTestingValues(3, 0.7, 760); wd.SetMeasurements(3, 0.7, 760); wd.RemoveObserver(display1); }
public void Can_add_observer() { CTestingDisplay.ResetUpdateCounter(); CWeatherData wd = new CWeatherData(); CTestingDisplay display1 = new CTestingDisplay(); wd.RegisterObserver(display1); display1.SetTestingValues(3, 0.7, 760); wd.SetMeasurements(3, 0.7, 760); display1.CheckUpdateCounter(0); }
public void When_identical_observers_are_set_next_one_isnt_added() { CTestingDisplay.ResetUpdateCounter(); CWeatherData wd = new CWeatherData(); CTestingDisplay display1 = new CTestingDisplay(); wd.RegisterObserver(display1, 2); wd.RegisterObserver(display1, 1); display1.SetTestingValues(3, 0.7, 760); wd.SetMeasurements(3, 0.7, 760); display1.CheckUpdateCounter(0); }
public void Can_create_observer_with_inside_and_outside_observable_subjects() { CWeatherData wdIn = new CWeatherData(LocationType.INSIDE); CWeatherData wdOut = new CWeatherData(LocationType.OUTSIDE); WeatherStationDuoTestingDisplay display = new WeatherStationDuoTestingDisplay(wdIn, wdOut); display.SetTestingValues(3, 0.7, 760); display.SetTestLocationType(LocationType.INSIDE); wdIn.SetMeasurements(3, 0.7, 760); display.CheckUpdatesCount(1); display.SetTestingValues(4, 0.8, 761); display.SetTestLocationType(LocationType.OUTSIDE); wdOut.SetMeasurements(4, 0.8, 761); display.CheckUpdatesCount(2); }
public void Observers_WithHigherPriority_ShouldBeNotifiedFirst() { var wd = new CWeatherData(); var testDisplay1 = new TestPriorityObserver(1); var testDisplay2 = new TestPriorityObserver(2); var testDisplay3 = new TestPriorityObserver(3); wd.RegisterObserver(testDisplay1, 1); wd.RegisterObserver(testDisplay2, 2); wd.RegisterObserver(testDisplay3, 3); var sw = new StringWriter(); Console.SetOut(sw); Console.SetError(sw); wd.SetMeasurements(3, 0.7, 760); string result = sw.ToString(); Assert.AreEqual("3;2;1;", result); }
public void NotifyObservers_WithWeatherStationType() { var weatherDataIn = new CWeatherData(); var weatherDataOut = new CWeatherData(); var display = new DisplayDuo(weatherDataIn, weatherDataOut); weatherDataIn.RegisterObserver(display, 1); weatherDataOut.RegisterObserver(display, 1); var sw = new StringWriter(); Console.SetOut(sw); Console.SetError(sw); weatherDataIn.SetMeasurements(3, 0.7, 760); weatherDataOut.SetMeasurements(4, 0.8, 761); string result = sw.ToString(); string expected = "Inside;Outside;"; Assert.AreEqual(expected, result); }
public void When_priority_is_set_observers_updates_in_order_of_priority() { CTestingDisplay.ResetUpdateCounter(); CWeatherData wd = new CWeatherData(); CTestingDisplay display1 = new CTestingDisplay(); CTestingDisplay display2 = new CTestingDisplay(); CTestingDisplay display3 = new CTestingDisplay(); wd.RegisterObserver(display2, 2); wd.RegisterObserver(display1, 1); wd.RegisterObserver(display3, 3); display1.SetTestingValues(3, 0.7, 760); display2.SetTestingValues(3, 0.7, 760); display3.SetTestingValues(3, 0.7, 760); wd.SetMeasurements(3, 0.7, 760); display1.CheckUpdateCounter(0); display2.CheckUpdateCounter(1); display3.CheckUpdateCounter(2); }