public object Post(DeployStep deploymentStep)
		{
			if (string.IsNullOrEmpty(deploymentStep.Id))
			{
				switch(deploymentStep.ParentType)
				{
					case EnumDeployStepParentType.Component:
						return _projectManager.CreateComponentDeploymentStep(deploymentStep.ProjectId, deploymentStep.ParentId, deploymentStep.StepName, deploymentStep.TaskTypeName, deploymentStep.TaskOptionsJson);
					case EnumDeployStepParentType.Configuration:
						return _projectManager.CreateConfigurationDeploymentStep(deploymentStep.ProjectId, deploymentStep.ParentId, deploymentStep.StepName, deploymentStep.TaskTypeName, deploymentStep.TaskOptionsJson);
					default:
						throw new UnknownEnumValueException(deploymentStep.ParentType);
				}
			}
			else
			{
				switch(deploymentStep.ParentType)
				{
					case EnumDeployStepParentType.Component:
						return _projectManager.UpdateComponentDeploymentStep(deploymentStep.Id, deploymentStep.ProjectId, deploymentStep.ParentId, deploymentStep.StepName, deploymentStep.TaskTypeName, deploymentStep.TaskOptionsJson);
					case EnumDeployStepParentType.Configuration:
						return _projectManager.UpdateConfigurationDeploymentStep(deploymentStep.Id, deploymentStep.ProjectId, deploymentStep.ParentId, deploymentStep.StepName, deploymentStep.TaskTypeName, deploymentStep.TaskOptionsJson);
					default:
						throw new UnknownEnumValueException(deploymentStep.ParentType);
				}
			}
		}
		public DeploymentValidationResultItem AddResult(DeployStep deploymentStep, TaskDefinitionValidationResult validationItem)
		{
			var resultItem = new DeploymentValidationResultItem
			{
				DeploymentStep = deploymentStep,
				TaskValidationResult = validationItem
			};
			this.ResultList.Add(resultItem);
			return resultItem;
		}
 private void AssertStep(DeployStep expected, DeployStep actual)
 {
     Assert.IsNotNull(actual);
     Assert.AreEqual(expected.Id, actual.Id);
     Assert.AreEqual(expected.ProjectId, actual.ProjectId);
     Assert.AreEqual(expected.ParentType, actual.ParentType);
     Assert.AreEqual(expected.ParentId, actual.ParentId);
     Assert.AreEqual(expected.StepName, actual.StepName);
     Assert.AreEqual(expected.TaskTypeName, actual.TaskTypeName);
     Assert.AreEqual(expected.TaskOptionsJson, actual.TaskOptionsJson);
     Assert.AreEqual(expected.SharedDeploymentStepId, actual.SharedDeploymentStepId);
     AssertDateEqual(expected.CreatedDateTimeUtc, actual.CreatedDateTimeUtc);
     Assert.AreEqual(expected.CreatedByUserName, actual.CreatedByUserName);
     AssertDateEqual(expected.UpdatedDateTimeUtc, actual.UpdatedDateTimeUtc);
     Assert.AreEqual(expected.UpdatedByUserName, actual.UpdatedByUserName);
 }
 private void AssertUpdatedStep(DeployStep result, DeployStep original, string newStepName, string newTaskTypeName, string newTaskOptionsJson, string newUserName, IProjectRepository sut)
 {
     Assert.IsNotNull(result);
     Assert.IsNotNullOrEmpty(result.Id);
     Assert.AreEqual(original.ProjectId, result.ProjectId);
     Assert.AreEqual(original.ParentId, result.ParentId);
     Assert.AreEqual(original.ParentType, result.ParentType);
     Assert.AreEqual(newStepName, result.StepName);
     Assert.AreEqual(newTaskTypeName, result.TaskTypeName);
     Assert.AreEqual(newTaskOptionsJson, result.TaskOptionsJson);
     Assert.AreEqual(original.CreatedByUserName, result.CreatedByUserName);
     AssertDateEqual(original.CreatedDateTimeUtc, result.CreatedDateTimeUtc);
     Assert.AreEqual(newUserName, result.UpdatedByUserName);
     AssertIsRecent(result.UpdatedDateTimeUtc);
      
     var dbItem = sut.GetConfigurationDeploymentStep(result.Id, result.ProjectId);
     AssertStep(result, dbItem);
 }
        private void AssertCreatedStep(DeployStep result, DeployConfiguration component, string stepName, string taskTypeName, string taskOptionsJson, IProjectRepository sut)
        {
            Assert.IsNotNull(result);
            Assert.IsNotNullOrEmpty(result.Id);
            Assert.AreEqual(component.ProjectId, result.ProjectId);
            Assert.AreEqual(component.Id, result.ParentId);
            Assert.AreEqual(EnumDeployStepParentType.Configuration, result.ParentType);
            Assert.AreEqual(stepName, result.StepName);
            Assert.AreEqual(taskTypeName, result.TaskTypeName);
            Assert.AreEqual(taskOptionsJson, result.TaskOptionsJson);
            Assert.IsNull(result.SharedDeploymentStepId);
            Assert.AreEqual(this.UserName, result.CreatedByUserName);
            AssertIsRecent(result.CreatedDateTimeUtc);
            Assert.AreEqual(this.UserName, result.UpdatedByUserName);
            AssertIsRecent(result.UpdatedDateTimeUtc);

            var dbItem = sut.GetConfigurationDeploymentStep(result.Id, result.ProjectId);
            AssertStep(result, dbItem);
        }
		public object Get(DeployStep request)
		{
			if(request == null)
			{
				throw new ArgumentNullException("request is null");
			} 
			else if (string.IsNullOrEmpty(request.ParentId))
			{ 
				throw new ArgumentNullException("request.parentId is null");
			}
			else
			{
				if(!string.IsNullOrEmpty(request.Id))
				{
					switch(request.ParentType)
					{
						case EnumDeployStepParentType.Component:
							return _projectManager.GetComponentDeploymentStep(request.Id, request.ProjectId);
						case EnumDeployStepParentType.Configuration:
							return _projectManager.GetConfigurationDeploymentStepList(request.Id, request.ProjectId);
						default:
							throw new UnknownEnumValueException(request.ParentType);
					}
				}
				else
				{
					switch(request.ParentType)
					{
						case EnumDeployStepParentType.Component:
							return _projectManager.GetComponentDeploymentStepList(request.ParentId, request.ProjectId);
						case EnumDeployStepParentType.Configuration:
							return _projectManager.GetConfigurationDeploymentStepList(request.ParentId, request.ProjectId);
						default:
							throw new UnknownEnumValueException(request.ParentType);
					}
				}
			}
		}
 public DeployStep CreateConfigurationDeploymentStep(string projectId, string configurationId, string stepName, string taskTypeName, string taskOptionsJson)
 {
     if (string.IsNullOrEmpty(projectId))
     {
         throw new ArgumentNullException("Missing project ID");
     }
     if (string.IsNullOrEmpty(configurationId))
     {
         throw new ArgumentNullException("Missing configuration ID");
     }
     if (string.IsNullOrEmpty(stepName))
     {
         throw new ArgumentNullException("Missing step name");
     }
     if (string.IsNullOrEmpty(taskTypeName))
     {
         throw new ArgumentNullException("Missing task tpe name");
     }
     VerifyProjectExists(projectId);
     VerifyConfigurationExists(configurationId, projectId);
     var step = new DeployStep
     {
         Id = Guid.NewGuid().ToString(),
         ProjectId = projectId,
         ParentId = configurationId,
         ParentType = EnumDeployStepParentType.Configuration,
         StepName = stepName,
         TaskTypeName = taskTypeName,
         TaskOptionsJson = taskOptionsJson,
         SharedDeploymentStepId = null,
         CreatedByUserName = _userIdentity.UserName,
         CreatedDateTimeUtc = DateTime.UtcNow,
         UpdatedByUserName = _userIdentity.UserName,
         UpdatedDateTimeUtc = DateTime.UtcNow
     };
     using (var db = _sqlConnectionInfo.GetDB())
     {
         step.OrderNumber = db.ExecuteScalar<int>("SELECT COUNT(*) FROM DeployConfigurationStep WHERE DeployProjectID=@ProjectId AND DeployConfigurationID=@ParentId", step);
         var sql = PetaPoco.Sql.Builder
                     .Append("INSERT INTO DeployConfigurationStep (ID, DeployProjectID, DeployConfigurationID, StepName, TaskTypeName, TaskOptionsJson, OrderNumber, CreatedDateTimeUtc, CreatedByUserName, UpdatedDateTimeUtc, UpdatedByUserName)")
                     .Append("VALUES (@Id, @ProjectId, @ParentId, @StepName, @TaskTypeName, @TaskOptionsJson, @OrderNumber, @CreatedDateTimeUtc, @CreatedByUserName, @UpdatedDateTimeUtc, @UpdatedByUserName)", step);
         db.Execute(sql);
     }
     return step;
 }
		public void Delete(DeployStep deploymentStep)
		{
			if(deploymentStep == null)
			{
				throw new ArgumentNullException("request is null");
			}
			else if (string.IsNullOrEmpty(deploymentStep.Id))
			{
				throw new ArgumentNullException("request.id is null");
			}
			switch(deploymentStep.ParentType)
			{ 
				case EnumDeployStepParentType.Component:
					_projectManager.DeleteComponentDeploymentStep(deploymentStep.Id, deploymentStep.ProjectId);
					break;
				case EnumDeployStepParentType.Configuration:
					_projectManager.DeleteConfigurationDeploymentStep(deploymentStep.Id, deploymentStep.ProjectId);
					break;
				default:
					throw new UnknownEnumValueException(deploymentStep.ParentType);
			}
		}