public void The_view_is_updated_when_the_timer_fires_and_no_data_is_downloaded() { // Given const string uRL = @"http://hello.world/boo"; CreateMockFactory(); var target = new TeamCityMetricsPresenter(CreateConfiguration(uRL: uRL)); _mockDownload.Setup(m => m.DownloadMetrics(uRL)) .Returns(""); TeamCityMetricsEventArgs actualArguments = null; var wait = new System.Threading.AutoResetEvent(false); target.MetricsUpdated += (s, e) => { actualArguments = e; wait.Set(); }; // When _mockTimer.Raise(m => m.Tick += null, _mockTimer.Object, EventArgs.Empty); // Then Assert.IsTrue(wait.WaitOne(5000), "No event raised when the timer fired"); Assert.AreEqual(0, actualArguments.Series.Count); _mockDownload.VerifyAll(); _mockTimer.VerifyAll(); }
public void The_view_is_updated_when_the_timer_fires_and_invalid_data_is_downloaded() { // Given const string uRL = @"http://hello.world/boo"; CreateMockFactory(); var target = new TeamCityMetricsPresenter(CreateConfiguration(uRL: uRL)); _mockDownload.Setup(m => m.DownloadMetrics(uRL)) .Returns(@"Build number,Build status,Start time,Series,Value 4,SUCCESS,2015-11-12 09:59,OpenCppCoverage"); var wait = new System.Threading.AutoResetEvent(false); target.MetricsError += (s, e) => { wait.Set(); }; // When _mockTimer.Raise(m => m.Tick += null, _mockTimer.Object, EventArgs.Empty); // Then Assert.IsTrue(wait.WaitOne(5000), "No event raised when the timer fired"); _mockDownload.VerifyAll(); _mockTimer.VerifyAll(); }
public void If_no_max_graph_y_is_specified_then_the_presenter_indicates_the_graph_should_auto_scale() { // Given var configuration = new InformationRadiatorItemConfiguration(); CreateMockFactory(); // When var target = new TeamCityMetricsPresenter(configuration); // Then Assert.IsTrue(target.AutoscaleGraphYAxis); }
public void No_server_and_login_details_in_the_configuration() { // Given string expectedUserName = "******"; string expectedPassword = "******"; var configuration = new InformationRadiatorItemConfiguration(); CreateMockFactory(); // When var target = new TeamCityMetricsPresenter(configuration); // Then Assert.AreEqual(expectedUserName, _factory._metricsUserName); Assert.AreEqual(expectedPassword, _factory._metricsPassword); Assert.AreEqual(10 * 60 * 1000, _factory._interval); }
public void Setting_the_server_and_login_details_via_the_configuration() { // Given string expectedUserName = "******"; string expectedPassword = "******"; var configuration = CreateConfiguration("http://boo", expectedUserName, expectedPassword); CreateMockFactory(); // When var target = new TeamCityMetricsPresenter(configuration); // Then Assert.AreEqual(expectedUserName, _factory._metricsUserName); Assert.AreEqual(expectedPassword, _factory._metricsPassword); Assert.AreEqual(10 * 60 * 1000, _factory._interval); }
public void If_a_max_graph_y_is_specified_then_the_presenter_indicates_the_graph_should_not_auto_scale_and_reports_the_required_may_y() { // Given var configuration = new InformationRadiatorItemConfiguration(); configuration.Add(new InformationRadiatorItemConfigurationField() { ID = "MaxY", Value = "10" }); CreateMockFactory(); // When var target = new TeamCityMetricsPresenter(configuration); // Then Assert.IsFalse(target.AutoscaleGraphYAxis); Assert.AreEqual(10m, target.GraphYAxisMax); }
public void The_view_is_updated_when_the_timer_fires_and_a_single_data_series_is_downloaded() { // Given const string uRL = @"http://hello.world/boo"; CreateMockFactory(); var target = new TeamCityMetricsPresenter(CreateConfiguration(uRL: uRL)); _mockDownload.Setup(m => m.DownloadMetrics(uRL)) .Returns(SingleMetricResult); TeamCityMetricsEventArgs actualArguments = null; var wait = new System.Threading.AutoResetEvent(false); target.MetricsUpdated += (s, e) => { actualArguments = e; wait.Set(); }; // When _mockTimer.Raise(m => m.Tick += null, _mockTimer.Object, EventArgs.Empty); // Then Assert.IsTrue(wait.WaitOne(5000), "No event raised when the timer fired"); Assert.AreEqual(1, actualArguments.Series.Count); var series = actualArguments.Series[0]; Assert.AreEqual("OpenCppCoverage", series.Name); Assert.AreEqual(7, series.Points.Count); Assert.AreEqual(new DateTime(2015, 11, 12, 9, 59, 0), series.Points[0].X); Assert.AreEqual(82.352941, series.Points[0].Y, 0.00001); Assert.AreEqual(new DateTime(2015, 11, 12, 10, 2, 0), series.Points[1].X); Assert.AreEqual(82.352941, series.Points[1].Y, 0.00001); Assert.AreEqual(new DateTime(2015, 11, 12, 10, 11, 0), series.Points[3].X); Assert.AreEqual(51.851852, series.Points[3].Y, 0.00001); _mockDownload.VerifyAll(); _mockTimer.VerifyAll(); }
public void The_view_is_updated_when_the_timer_fires_and_multiple_data_series_are_downloaded_from_multiple_urls() { // Given const string uRL = @"http://hello.world/boo"; const string uRL2 = @"http://hello.world/hoo"; CreateMockFactory(); var target = new TeamCityMetricsPresenter(CreateConfiguration(uRL: uRL, uRL2: uRL2)); _mockDownload.Setup(m => m.DownloadMetrics(uRL)) .Returns(MultiMetricResult); _mockDownload.Setup(m => m.DownloadMetrics(uRL2)) .Returns(MultiMetricResult2); TeamCityMetricsEventArgs actualArguments = null; var wait = new System.Threading.AutoResetEvent(false); target.MetricsUpdated += (s, e) => { actualArguments = e; wait.Set(); }; // When _mockTimer.Raise(m => m.Tick += null, _mockTimer.Object, EventArgs.Empty); // Then Assert.IsTrue(wait.WaitOne(5000), "No event raised when the timer fired"); Assert.AreEqual(7, actualArguments.Series.Count); // Check the Average_Complexity series var series = actualArguments.Series.First(s => s.Name == "Average_Complexity"); Assert.AreEqual(6, series.Points.Count); // Check the Maximum_Complexity series series = actualArguments.Series.First(s => s.Name == "Maximum_Complexity"); Assert.AreEqual(6, series.Points.Count); // Check the Average_Block_Depth series series = actualArguments.Series.First(s => s.Name == "Average_Block_Depth"); Assert.AreEqual(6, series.Points.Count); // Check the Maximum_Block_Depth series series = actualArguments.Series.First(s => s.Name == "Maximum_Block_Depth"); Assert.AreEqual(6, series.Points.Count); // Check the Line series series = actualArguments.Series.First(s => s.Name == "Line"); Assert.AreEqual(4, series.Points.Count); // Check the Method series series = actualArguments.Series.First(s => s.Name == "Method"); Assert.AreEqual(4, series.Points.Count); // Check the Class series series = actualArguments.Series.First(s => s.Name == "Class"); Assert.AreEqual(4, series.Points.Count); _mockDownload.VerifyAll(); _mockTimer.VerifyAll(); }