public void Init() { _ps = Utilities.CreatePowerShell(CmdletName, typeof(AddProject)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); // Create a project group var groupResource = new ProjectGroupResource {Name = "Octopus", Id = "projectgroups-1"}; octoRepo.Setup(o => o.ProjectGroups.FindByName("Octopus")).Returns(groupResource); octoRepo.Setup(o => o.ProjectGroups.Get(It.IsIn(new[] { "projectgroups-1" }))) .Returns(groupResource); octoRepo.Setup(o => o.ProjectGroups.Get(It.IsNotIn(new[] { "projectgroups-1" }))) .Throws(new OctopusResourceNotFoundException("Not Found")); _projects.Clear(); var repo = new Mock<IProjectRepository>(); repo.Setup(e => e.Create(It.IsAny<ProjectResource>())) .Returns(delegate(ProjectResource p) { _projects.Add(p); return p; }); octoRepo.Setup(o => o.Projects).Returns(repo.Object); }
public void Init() { _ps = Utilities.CreatePowerShell(CmdletName, typeof (CopyProject)); var octoRepo = Utilities.AddOctopusRepo(_ps.Runspace.SessionStateProxy.PSVariable); // Create a project group var groupResource = new ProjectGroupResource {Name = "Octopus", Id = "projectgroups-1"}; octoRepo.Setup(o => o.ProjectGroups.FindByName("Octopus")).Returns(groupResource); octoRepo.Setup(o => o.ProjectGroups.FindByName("Gibberish")).Returns((ProjectGroupResource) null); // Create project var project = new ProjectResource { Name = "Source", Description = "Test Source", DeploymentProcessId = "deploymentprocesses-1", VariableSetId = "variablesets-1", DefaultToSkipIfAlreadyInstalled = true, IncludedLibraryVariableSetIds = new List<string> { "libraryvariablesets-1" }, VersioningStrategy = new VersioningStrategyResource(), AutoCreateRelease = false, ReleaseCreationStrategy = new ReleaseCreationStrategyResource(), IsDisabled = false, LifecycleId = "lifecycle-1" }; // Create projects _projects.Clear(); _projects.Add(project); octoRepo.Setup(o => o.Projects.FindByName("Source")).Returns(project); octoRepo.Setup(o => o.Projects.FindByName("Gibberish")).Returns((ProjectResource) null); octoRepo.Setup(o => o.Projects.Create(It.IsAny<ProjectResource>())).Returns( delegate(ProjectResource p) { p.VariableSetId = "variablesets-2"; p.DeploymentProcessId = "deploymentprocesses-2"; _projects.Add(p); return p; } ); // Create deployment process var action = new DeploymentActionResource {Name = "Action"}; action.Environments.Add("environments-1"); var step = new DeploymentStepResource { Id = "deploymentsteps-1", Name = "Database"}; step.Actions.Add(action); var process = new DeploymentProcessResource(); process.Steps.Add(step); octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-1" }))).Returns(process); _copyProcess = new DeploymentProcessResource(); octoRepo.Setup(o => o.DeploymentProcesses.Get(It.IsIn(new[] { "deploymentprocesses-2" }))).Returns(_copyProcess); // Create variable set var variable = new VariableResource { Name = "Name", Value = "Value" }; variable.Scope.Add(ScopeField.Action, "deploymentsactions-1"); variable.Scope.Add(ScopeField.Environment, "environments-1"); var sourceVariables = new VariableSetResource(); sourceVariables.Variables.Add(variable); octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-1" }))).Returns(sourceVariables); _copyVariables = new VariableSetResource(); octoRepo.Setup(o => o.VariableSets.Get(It.IsIn(new[] { "variablesets-2" }))).Returns(_copyVariables); }