static void Main(string[] args) { var wdIn = new WeatherData(); var wdOut = new WeatherDataPro(); var display = new Display(wdIn, wdOut); var statsDisplay = new StatsDisplay(wdIn, wdOut); wdIn.UpdateWeatherInfo(3, 0.7, 760); wdIn.UpdateWeatherInfo(4, 0.8, 761); wdOut.UpdateWeatherInfo(4, 0.8, 761, 90, 11); wdOut.UpdateWeatherInfo(4, 0.8, 761, 270, 10); wdIn.RemoveObserver(statsDisplay); wdOut.RemoveObserver(statsDisplay); wdIn.UpdateWeatherInfo(10, 0.8, 761); }
public void UpdateWeatherInfo_StatsDisplayIsSubscriber_StatsDisplayCalledTwoTimes() { // Arrange var statsDisplayCalledCount = 0; var wdIn = new WeatherData(); var wdOut = new WeatherDataPro(); var statsDisplayMock = new Mock <StatsDisplay>(wdIn, wdOut); wdIn.RegisterObserver(statsDisplayMock.Object); wdOut.RegisterObserver(statsDisplayMock.Object); statsDisplayMock .Setup(d => d.Update(It.IsAny <IObservable <WeatherInfo> >(), It.IsAny <WeatherInfo>())) .Callback(() => ++ statsDisplayCalledCount); // Act wdIn.UpdateWeatherInfo(3, 0.7, 760); wdOut.UpdateWeatherInfo(4, 0.8, 761, 10, 10); // Assert Assert.Equal(2, statsDisplayCalledCount); }