public void AddDeployment(Deployment deployment) { if (deployment == null) { throw new ArgumentNullException("deployment"); } const string CommandText = @" INSERT INTO Deployment (Created, PipelineId, EnvironmentId) VALUES (@Created, @PipelineId, @EnvironmentId) SET @DeploymentId = @@IDENTITY"; var deploymentIdParameter = new SqlParameter("DeploymentId", SqlDbType.Int) { Direction = ParameterDirection.Output }; using (DbCommand command = CreateCommand()) { command.CommandText = CommandText; ModifyData( command, new SqlParameter("Created", deployment.Created), new SqlParameter("PipelineId", deployment.PipelineId), new SqlParameter("EnvironmentId", deployment.EnvironmentId), deploymentIdParameter); } deployment.ChangeId((int)deploymentIdParameter.Value); }
public void AddDeployment_WhenAdded_CanBeRetrieved() { const int pipelineId = 1; const int environmentId = 1; var deployment = new Deployment( pipelineId, environmentId); deploymentRepository.AddDeployment(deployment); IEnumerable<Deployment> result = deploymentRepository.GetDeployments(pipelineId); Assert.True(result.Count() >= 1); }
public void AddDeployment(Deployment deployment) { if (deployment == null) { throw new ArgumentNullException("deployment"); } int newId = 1; if (_deployments.Count > 0) { newId = _deployments.Max(d => d.Id.Value) + 1; } deployment.ChangeId(newId); _deployments.Add(deployment); }
public static Deployment Reconstruct( int id, DateTime created, int pipelineId, int environmentId, DateTime? started, DateTime? completed) { var deployment = new Deployment( pipelineId, environmentId); deployment.DeploymentId = id; deployment.Created = created; deployment.Started = started; deployment.Completed = completed; return deployment; }
public void UpdateDeployment_WhenStarted_StartedIsUpdated() { // Arrange: var added = new Deployment(1, 1); deploymentRepository.AddDeployment(added); Thread.Sleep(10); added.Start(); int deploymentId = added.Id.Value; // Act: deploymentRepository.UpdateDeployment(added); // Assert: Deployment updated = deploymentRepository.GetDeployment(deploymentId); Assert.NotNull(updated.Started); Assert.True(updated.Started > added.Created); }
public void AddDeployment(Deployment deployment) { if (deployment == null) { throw new ArgumentNullException("deployment"); } const string sql = @" INSERT INTO Deployment (Created, PipelineId, EnvironmentId) VALUES (@Created, @PipelineId, @EnvironmentId) SET @DeploymentId = Scope_Identity()"; var param = new {deployment.Created, deployment.PipelineId, deployment.EnvironmentId}; int deploymentId = _connection.ExecuteAndGetGeneratedId(sql, param, "DeploymentId"); deployment.ChangeId(deploymentId); }
public void DeployDueDeployments_WhenCalledSecondTime_DeploysNoneSecondTime() { // Arrange: int pipelineId = 1; int environmentId = 1; var deployment = new Deployment( pipelineId, environmentId); SetupRepositories(pipelineId, environmentId); deploymentRepository.AddDeployment(deployment); deploymentService.DeployDueDeployments(); deploymentUtilityMock.Verify( du => du.Deploy(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Environment>()), Times.Once()); // Act: deploymentService.DeployDueDeployments(); // Assert: deploymentUtilityMock.Verify( du => du.Deploy(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Environment>()), Times.Once()); }
public void UpdateDeployment(Deployment deployment) { }
public void UpdateDeployment(Deployment deployment) { if (deployment == null) { throw new ArgumentNullException("deployment"); } const string sql = @" UPDATE Deployment SET Started = @Started , Completed = @Completed WHERE DeploymentId = @DeploymentId"; var param = new {deployment.Started, deployment.Completed, deployment.DeploymentId}; _connection.Execute(sql, param); }
public ScheduleDeploymentResult(Deployment deployment) { Success = true; Deployment = deployment; }
public void DeployDueDeployments_WhenContainsOne_DeploysOne() { // Arrange: const int pipelineId = 1; const int environmentId = 1; var deployment = new Deployment( pipelineId, environmentId); SetupRepositories(pipelineId, environmentId); WithDeployments(deployment); // Act: deploymentService.DeployDueDeployments(); // Assert: deploymentUtilityMock.Verify( du => du.Deploy(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Environment>()), Times.Once()); }
public void GetDueDeployments_WhenScheduledNew_ContainsTheScheduled() { // Arrange: const int pipelineId = 1; const int environmentId = 1; SetupRepositories(pipelineId, environmentId); deploymentService.ScheduleDeployment( pipelineId, environmentId); var deployment = new Deployment( pipelineId, environmentId); WithDeployments(deployment); // Act: IEnumerable<Deployment> scheduledDeployments = deploymentService.GetDueDeployments(null); // Assert: Assert.NotNull(scheduledDeployments); Assert.True(scheduledDeployments.Count() > 0); Assert.True(scheduledDeployments.Any(d => d.PipelineId == pipelineId)); }
public void UpdateDeployment(Deployment deployment) { if (deployment == null) { throw new ArgumentNullException("deployment"); } const string CommandText = @" UPDATE Deployment SET Started = @Started , Completed = @Completed WHERE DeploymentId = @DeploymentId"; using (DbCommand command = CreateCommand()) { command.CommandText = CommandText; AddParameter(command, "Started", deployment.Started); AddParameter(command, "Completed", deployment.Completed); AddParameter(command, "DeploymentId", deployment.Id); ModifyData(command); } }
public ScheduleDeploymentResult ScheduleDeployment( int pipelineId, int environmentId) { var result = new ScheduleDeploymentResult(); Pipeline pipeline = pipelineRepository.GetPipeline(pipelineId); if (pipeline == null) { result.AddError(new ResultError("The id does not correspond to an existing pipeline.")); } Environment environment = environmentRepository.GetEnvironment(environmentId); if (environment == null) { result.AddError(new ResultError("The id does not correspond to an existing environment.")); } if (result.HasErrors) { return result; } var deployment = new Deployment( pipelineId, environmentId); deploymentRepository.AddDeployment(deployment); return new ScheduleDeploymentResult(deployment); }