public void should_be_in_unknown_state_before_started() { var config = new TeamCityConfiguration { Uri = "http://dummy", PollingInterval = 60 }; var monitor = new TeamCityMonitor(null, config); Assert.AreEqual(BuildState.Unknown, monitor.CurrentState); }
public void should_fail_if_build_missing_in_config() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1" }; var monitor = new TeamCityMonitor(connection, configuration); Assert.Throws<IndexOutOfRangeException>(monitor.BeginMonitoring); }
public void should_ignore_calls_to_end_monitoring_if_not_currently_running() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); Assert.DoesNotThrow(monitor.EndMonitoring); }
public void should_fail_if_build_status_unknown() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); connection.SetBuildStatus("BuildName1", "XXX"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); Assert.Throws<NotSupportedException>(monitor.BeginMonitoring); }
public void should_run_update_when_started() { var config = new TeamCityConfiguration { Uri = teamCityUri, PollingInterval = 60 }; var monitor = new TeamCityMonitor(null, config); monitor.BeginMonitoring(); Assert.AreNotEqual(BuildState.Unknown, monitor.CurrentState); }
public void should_ignore_duplicate_builds() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1;ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(1, monitor.MonitoredBuilds.Count()); }
public void should_ignore_leading_spaces_for_projects() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName1:BuildName2"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1; ProjectName1:BuildName2" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.That(monitor.MonitoredBuilds.Contains("bt1")); Assert.That(monitor.MonitoredBuilds.Contains("bt2")); }
public void should_return_failure_if_any_build_failed() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName2:BuildName2"); connection.SetBuildStatus("BuildName1", "SUCCESS"); connection.SetBuildStatus("BuildName2", "FAILURE"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1;ProjectName2:BuildName2" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Failed, monitor.CurrentState); }
public void should_set_status_succeeded_if_single_build_succeeds() { var buildStatus = BuildState.Unknown; var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.StatusChanged += (s, e) => buildStatus = e.NewState; monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Succeeded, buildStatus); }
public void should_stop_polling_when_end_monitoring_called() { int buildChecks = 0; var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var mockConnection = new Mock<ITeamCityConnection>(); mockConnection.Setup(c => c.GetProjects()).Returns(connection.GetProjects); mockConnection.Setup(c => c.GetProject(It.IsAny<string>())).Returns<string>(connection.GetProject); mockConnection.Setup(c => c.GetBuild(It.IsAny<string>())).Callback(() => buildChecks++).Returns<string>(connection.GetBuild); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1", PollingInterval = 1 }; var monitor = new TeamCityMonitor(mockConnection.Object, configuration); monitor.BeginMonitoring(); var sw = new Stopwatch(); sw.Start(); do { Thread.Sleep(500); } while (buildChecks < 2 && sw.ElapsedMilliseconds < 5000); sw.Stop(); var numberOfChecks = buildChecks; monitor.EndMonitoring(); sw.Start(); do { Thread.Sleep(500); } while (sw.ElapsedMilliseconds < 5000); sw.Stop(); Assert.AreEqual(numberOfChecks, buildChecks); }
public void should_not_fail_if_no_builds_match() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "NotProjectName1:NotBuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); Assert.DoesNotThrow(monitor.BeginMonitoring); }
public void should_set_status_failed_if_any_build_fails() { var buildStatus = BuildState.Unknown; var connection = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName2:BuildName2;ProjectName3:BuildName3"); connection.SetBuildStatus("BuildName1", "FAILURE"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1;ProjectName2:BuildName2;ProjectName3:BuildName3" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.StatusChanged += (s, e) => buildStatus = e.NewState; monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Failed, buildStatus); }
public void should_return_unknown_if_build_is_removed() { int buildChecks = 0; var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var mockConnection = new Mock<ITeamCityConnection>(); mockConnection.Setup(c => c.GetProjects()).Returns(connection.GetProjects); mockConnection.Setup(c => c.GetProject(It.IsAny<string>())).Returns<string>(connection.GetProject); mockConnection.Setup(c => c.GetBuild(It.IsAny<string>())).Callback(() => buildChecks++).Returns<string>(connection.GetBuild); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1", PollingInterval = 1 }; var monitor = new TeamCityMonitor(mockConnection.Object, configuration); monitor.BeginMonitoring(); connection.RemoveAllBuilds(); var checksBeforeRemove = buildChecks; do { Thread.Sleep(100); } while (buildChecks == checksBeforeRemove); Assert.AreEqual(BuildState.Unknown, monitor.CurrentState); }
public void should_return_unknown_if_there_are_no_matching_builds() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName2" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Unknown, monitor.CurrentState); }
public void should_return_running_if_any_build_running_when_others_succeeded() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName2:BuildName2"); connection.SetBuildStatus("BuildName1", "SUCCESS", true); connection.SetBuildStatus("BuildName2", "SUCCESS"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1;ProjectName2:BuildName2" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Running, monitor.CurrentState); }
public void should_return_success_if_build_is_successful() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); connection.SetBuildStatus("BuildName1", "SUCCESS"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Succeeded, monitor.CurrentState); }
public void should_monitor_single_project() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Succeeded, monitor.CurrentState); }
public void should_not_fail_if_processing_time_longer_than_polling_interval() { var firstUpdate = true; var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var mockConnection = new Mock<ITeamCityConnection>(); mockConnection.Setup(c => c.GetProjects()).Returns(connection.GetProjects); mockConnection.Setup(c => c.GetProject(It.IsAny<string>())).Returns<string>(connection.GetProject); mockConnection.Setup(c => c.GetBuild(It.IsAny<string>())) .Callback(() => { if (!firstUpdate) { Thread.Sleep(1000); } firstUpdate = false; }) .Returns<string>(connection.GetBuild); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1", PollingInterval = 1 }; var monitor = new TeamCityMonitor(mockConnection.Object, configuration); var timerField = monitor.GetType().GetField("timer", BindingFlags.NonPublic | BindingFlags.Instance); var timer = (Timer)timerField.GetValue(monitor); timer.Interval = 1; monitor.BeginMonitoring(); var sw = new Stopwatch(); sw.Start(); do { Thread.Sleep(500); } while (sw.ElapsedMilliseconds < 5000); timer.Enabled = false; }
public void should_only_get_project_info_once_per_project() { int numberOfCalls = 0; var fakeValueProvider = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName1:BuildName2"); var connection = new Mock<ITeamCityConnection>(); connection.Setup(c => c.GetBuild(It.IsAny<string>())).Returns<string>(fakeValueProvider.GetBuild); connection.Setup(c => c.GetProjects()).Returns(fakeValueProvider.GetProjects); connection.Setup(c => c.GetProject(It.IsAny<string>())).Callback(() => numberOfCalls++).Returns<string>(fakeValueProvider.GetProject); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1;ProjectName1:BuildName2" }; var monitor = new TeamCityMonitor(connection.Object, configuration); monitor.BeginMonitoring(); Assert.AreEqual(1, numberOfCalls); }
public void should_return_error_if_all_builds_are_in_error() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName2:BuildName2"); connection.SetBuildStatus("BuildName1", "ERROR"); connection.SetBuildStatus("BuildName2", "ERROR"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1;ProjectName2:BuildName2" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Error, monitor.CurrentState); }
public void should_raise_event_when_a_build_status_changes() { bool statusChangedCalled = false; var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1", PollingInterval = 1 }; var monitor = new TeamCityMonitor(connection, configuration); monitor.StatusChanged += (s, e) => statusChangedCalled = true; monitor.BeginMonitoring(); var sw = new Stopwatch(); sw.Start(); do { Thread.Sleep(500); } while (!statusChangedCalled && sw.ElapsedMilliseconds < 5000); Assert.IsTrue(statusChangedCalled); }
public void should_only_monitor_matches_when_using_wildcard_for_projects_and_builds() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName2:BuildName2;NotProjectName:BuildName2;ProjectName3:NotBuildName;NotProjectName:NotBuildName"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName*:BuildName*" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.That(monitor.MonitoredBuilds.Contains("bt1")); Assert.That(monitor.MonitoredBuilds.Contains("bt2")); Assert.That(!monitor.MonitoredBuilds.Contains("bt3")); Assert.That(!monitor.MonitoredBuilds.Contains("bt4")); Assert.That(!monitor.MonitoredBuilds.Contains("bt5")); }
public void should_only_monitor_matching_projects() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1;ProjectName2:BuildName2;ProjectName3:BuildName3"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.That(monitor.MonitoredBuilds.Contains("bt1")); Assert.That(!monitor.MonitoredBuilds.Contains("bt2")); Assert.That(!monitor.MonitoredBuilds.Contains("bt3")); }
public void should_return_failure_if_build_is_still_running_but_has_failed() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); connection.SetBuildStatus("BuildName1", "FAILURE", true); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName1:BuildName1" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.AreEqual(BuildState.Failed, monitor.CurrentState); }
public void should_match_project_and_build_by_wildcard() { var connection = new MockTeamCityConnection("ProjectName1:BuildName1"); var configuration = new TeamCityConfiguration { BuildsToMonitor = "ProjectName*:BuildName*" }; var monitor = new TeamCityMonitor(connection, configuration); monitor.BeginMonitoring(); Assert.That(monitor.MonitoredBuilds.Contains("bt1")); }