public object Post(DeployProjectBranch branch) { if (string.IsNullOrEmpty(branch.Id)) { return _projectManager.CreateBranch(branch.ProjectId, branch.BranchName); } else { return _projectManager.UpdateBranch(branch.Id, branch.ProjectId, branch.BranchName); } }
private void AssertCreatedBranch(DeployProjectBranch result, string projectId, string branchName, IProjectRepository sut) { Assert.IsNotNull(result); Assert.IsNotNullOrEmpty(result.Id); Assert.AreEqual(projectId, result.ProjectId); var dbProject = sut.GetProject(result.ProjectId); Assert.IsNotNull(dbProject); Assert.AreEqual(1, dbProject.BranchList.Count); Assert.AreEqual(result.Id, dbProject.BranchList[0].Id); Assert.AreEqual(projectId, dbProject.BranchList[0].ProjectId); Assert.AreEqual(branchName, dbProject.BranchList[0].BranchName); }
private void AssertUpdated(DeployProjectBranch result, DeployProjectBranch original, string newBranchName, string newUserName, IProjectRepository sut) { Assert.IsNotNull(result); Assert.AreEqual(original.Id, result.Id); Assert.AreEqual(original.ProjectId, result.ProjectId); Assert.AreEqual(newBranchName, result.BranchName); Assert.AreEqual(original.CreatedByUserName, result.CreatedByUserName); AssertDateEqual(original.CreatedDateTimeUtc, result.CreatedDateTimeUtc); Assert.AreEqual(newUserName, result.UpdatedByUserName); AssertIsRecent(result.UpdatedDateTimeUtc); var dbItem = sut.GetBranch(result.Id, result.ProjectId); AssertHelpers.AssertBranch(result, dbItem); }
public object Get(DeployProjectBranch request) { if(request == null || (string.IsNullOrEmpty(request.Id) && string.IsNullOrEmpty(request.ProjectId))) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(request.Id)) { return _projectManager.GetBranch(request.Id, request.ProjectId); } else { return _projectManager.GetBranchList(request.ProjectId); } }
public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId) { if (build == null) { throw new ArgumentNullException("Missing build"); } if (branch == null) { throw new ArgumentNullException("Missing branch"); } if (component == null) { throw new ArgumentNullException("Missing component"); } if (environment == null) { throw new ArgumentNullException("Missing environment"); } if (machineList == null) { throw new ArgumentNullException("Missing machineList"); } if (deployBatchRequestItemId == null) { throw new ArgumentNullException("Missing deployBatchRequestItemId"); } var deployState = new DeployState { Id = Guid.NewGuid().ToString(), ProjectId = environment.ProjectId, Build = build, Branch = branch, Environment = environment, Component = component, MachineList = machineList.ToList(), Status = EnumDeployStatus.NotStarted, SubmittedDateTimeUtc = DateTime.UtcNow, DeployBatchRequestItemId = deployBatchRequestItemId, CreatedDateTimeUtc = DateTime.UtcNow, CreatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName }; _documentSession.StoreSaveEvict(deployState); return deployState; }
public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId) { var deployState = new DeployState { Id = Guid.NewGuid().ToString(), ProjectId = environment.ProjectId, Build = build, Branch = branch, Environment = environment, Component = component, MachineList = machineList.ToList(), Status = EnumDeployStatus.NotStarted, SubmittedDateTimeUtc = DateTime.UtcNow, DeployBatchRequestItemId = deployBatchRequestItemId, CreatedDateTimeUtc = DateTime.UtcNow, CreatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName }; _offlineDataProvider.SaveDeployState(deployState); return deployState; }
public DeployProjectBranch CreateBranch(string projectId, string branchName) { if(string.IsNullOrEmpty(projectId)) { throw new ArgumentNullException("Missing project ID"); } if(string.IsNullOrEmpty(branchName)) { throw new ArgumentNullException("Missing branch name"); } var branch = new DeployProjectBranch { Id = Guid.NewGuid().ToString(), ProjectId = projectId, BranchName = branchName, CreatedByUserName = _userIdentity.UserName, CreatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow }; using(var db = _sqlConnectionInfo.GetDB()) { VerifyProjectExists(projectId); var sql = PetaPoco.Sql.Builder .Append("INSERT INTO DeployBranch (ID, DeployProjectID, BranchName, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)") .Append("VALUES (@Id, @ProjectId, @BranchName, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", branch); db.Execute(sql); } return branch; }
public void Delete(DeployProjectBranch branch) { _projectManager.DeleteBranch(branch.Id, branch.ProjectId); }
public void CanCreateProjectBranch() { var repository = new Mock<IProjectRepository>(); string projectId = Guid.NewGuid().ToString(); var branch = new DeployProjectBranch { Id = Guid.NewGuid().ToString(), ProjectId = Guid.NewGuid().ToString(), BranchName = Guid.NewGuid().ToString() }; repository.Setup(i=>i.CreateBranch(branch.ProjectId, branch.BranchName)).Returns(branch); IProjectManager sut = new ProjectManager(repository.Object, new Mock<IDeployTaskFactory>().Object); var result = sut.CreateBranch(branch.ProjectId, branch.BranchName); Assert.AreEqual(branch, result); repository.Verify(i=>i.CreateBranch(branch.ProjectId, branch.BranchName), Times.Once()); }
public DeployState CreateDeployState(DeployBuild build, DeployProjectBranch branch, DeployEnvironment environment, DeployComponent component, IEnumerable<DeployMachine> machineList, string deployBatchRequestItemId) { if (build == null) { throw new ArgumentNullException("Missing build"); } if (branch == null) { throw new ArgumentNullException("Missing branch"); } if (component == null) { throw new ArgumentNullException("Missing component"); } if (environment == null) { throw new ArgumentNullException("Missing environment"); } if (machineList == null) { throw new ArgumentNullException("Missing machineList"); } if (deployBatchRequestItemId == null) { throw new ArgumentNullException("Missing deployBatchRequestItemId"); } var sqlDeployState = new SqlDeployState { ID = Guid.NewGuid().ToString(), ProjectID = build.ProjectId, BranchID = branch.Id, BranchJson = branch.ToJson(), BuildID = build.Id, BuildJson = build.ToJson(), ComponentID = component.Id, ComponentJson = component.ToJson(), EnvironmentID = environment.Id, EnvironmentName = environment.EnvironmentName, EnvironmentJson = environment.ToJson(), DeployBatchRequestItemID = deployBatchRequestItemId, DeploymentCompleteDateTimeUtc = null, DeploymentStartedDateTimeUtc = null, ErrorDetails = null, SortableVersion = build.SortableVersion, EnumDeployStatusID = (int)EnumDeployStatus.NotStarted, CreatedByUserName = _userIdentity.UserName, CreatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, SubmittedDateTimeUtc = DateTime.UtcNow }; var branchJson = branch.ToJson(); var buildJson = build.ToJson(); var componentJson = component.ToJson(); var environmentJson = environment.ToJson(); using(var db = _sqlConnectionInfo.GetDB()) { var deployStateSql = PetaPoco.Sql.Builder .Append("INSERT INTO DeployState (ID, DeployBatchRequestItemID, EnumDeployStatusID, ProjectID, BranchID, BuildID, EnvironmentID, EnvironmentName, ComponentID,") .Append("BranchJson, BuildJson, EnvironmentJson, ComponentJson, SubmittedDateTimeUtc, DeploymentStartedDateTimeUtc, DeploymentCompleteDateTimeUtc, ") .Append("ErrorDetails, SortableVersion, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)") .Append("VALUES (@ID, @DeployBatchRequestItemID, @EnumDeployStatusID, @ProjectID, @BranchID, @BuildID, @EnvironmentID, @EnvironmentName, @ComponentID,", sqlDeployState) .Append("@BranchJson, @BuildJson, @EnvironmentJson, @ComponentJson, @SubmittedDateTimeUtc, @DeploymentStartedDateTimeUtc, @DeploymentCompleteDateTimeUtc,", sqlDeployState) .Append("@ErrorDetails, @SortableVersion, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", sqlDeployState); db.Execute(deployStateSql); foreach(var machine in machineList) { var sqlMachine = new SqlDeployStateMachine { ID = Guid.NewGuid().ToString(), DeployStateID = sqlDeployState.ID, MachineID = machine.Id, MachineName = machine.MachineName, MachineJson = machine.ToJson(), CreatedByUserName = _userIdentity.UserName, CreatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow }; var machineSql = PetaPoco.Sql.Builder .Append("INSERT INTO DeployStateMachine (ID, DeployStateID, MachineID, MachineName, MachineJson, CreatedByUserName, CreatedDateTimeUtc, UpdatedByUserName, UpdatedDateTimeUtc)") .Append("VALUES (@ID, @DeployStateID, @MachineID, @MachineName, @MachineJson, @CreatedByUserName, @CreatedDateTimeUtc, @UpdatedByUserName, @UpdatedDateTimeUtc)", sqlMachine); db.Execute(machineSql); } } return GetDeployState(sqlDeployState.ID); }