Esempio n. 1
0
        private async Task BuildClientProject(ProjectGroupResource projectGroup, LifecycleResource normalLifecycle)
        {
            var clientProjectEditor = await Repository.Projects.CreateOrModify("Truck Tracker Client", projectGroup, normalLifecycle);

            clientProjectEditor.SetLogo(SampleImageCache.DownloadImage("http://b2bimg.bridgat.com/files/GPS_Camera_TrackerGPS_Camera_Tracking.jpg", "GPS_Camera_TrackerGPS_Camera_Tracking.jpg"));

            var variables = await clientProjectEditor.Variables;

            variables.AddOrUpdateVariableValue("TrackerUrl", "https://trucktracker.com/trucks/#{Octopus.Machine.Name}");

            var channel = await clientProjectEditor.Channels.CreateOrModify("1.x Normal", "The channel for stable releases that will be deployed to our production trucks.");

            channel.SetAsDefaultChannel();

            await clientProjectEditor.Channels.Delete("Default");

            var deploymentProcess = await clientProjectEditor.DeploymentProcess;

            deploymentProcess.AddOrUpdateStep("Deploy Application")
            .TargetingRoles("truck")
            .AddOrUpdateScriptAction("Deploy Application", new InlineScriptActionFromFileInAssembly("TrucksSample.Client.Deploy.fsx"), ScriptTarget.Target);

            await clientProjectEditor.Triggers.CreateOrModify("Auto-Deploy to trucks when available",
                                                              ProjectTriggerType.DeploymentTarget,
                                                              ProjectTriggerConditionEvent.ExistingDeploymentTargetChangesState,
                                                              ProjectTriggerConditionEvent.NewDeploymentTargetBecomesAvailable);

            await clientProjectEditor.Save();
        }
Esempio n. 2
0
        public async Task<ProjectEditor> CreateOrModify(string name, ProjectGroupResource projectGroup, LifecycleResource lifecycle, string description)
        {
            var existing = await repository.FindByName(name).ConfigureAwait(false);

            if (existing == null)
            {
                Instance = await repository.Create(new ProjectResource
                {
                    Name = name,
                    ProjectGroupId = projectGroup.Id,
                    LifecycleId = lifecycle.Id,
                    Description = description
                }).ConfigureAwait(false);
            }
            else
            {
                existing.Name = name;
                existing.ProjectGroupId = projectGroup.Id;
                existing.LifecycleId = lifecycle.Id;
                existing.Description = description;

                Instance = await repository.Modify(existing).ConfigureAwait(false);
            }

            return this;
        }
        private async Task <ProjectResource> BuildClientProject(ProjectGroupResource projectGroup, LifecycleResource normalLifecycle, LibraryVariableSetResource[] libraryVariableSets, Func <string, TagResource> getTag)
        {
            Log.Information("Setting up client project...");
            var clientProjectEditor = await Repository.Projects.CreateOrModify("Truck Tracker Client", projectGroup, normalLifecycle);

            await clientProjectEditor.SetLogo(SampleImageCache.DownloadImage("http://b2bimg.bridgat.com/files/GPS_Camera_TrackerGPS_Camera_Tracking.jpg", "GPS_Camera_TrackerGPS_Camera_Tracking.jpg"));

            clientProjectEditor.IncludingLibraryVariableSets(libraryVariableSets)
            .Customize(p => p.TenantedDeploymentMode = TenantedDeploymentMode.Tenanted);

            var channel = await clientProjectEditor.Channels.CreateOrModify("1.x Normal", "The channel for stable releases that will be deployed to our production trucks.");

            channel.SetAsDefaultChannel()
            .AddOrUpdateTenantTags(getTag("Canary"), getTag("Stable"));

            await clientProjectEditor.Channels.Delete("Default");

            var deploymentProcess = await clientProjectEditor.DeploymentProcess;

            deploymentProcess.AddOrUpdateStep("Deploy Application")
            .TargetingRoles("truck")
            .AddOrUpdateScriptAction("Deploy Application", new InlineScriptActionFromFileInAssembly("TrucksSample.Client.Deploy.fsx"), ScriptTarget.Target);

            var machineFilter = new MachineFilterResource();

            machineFilter.EventGroups.Add("MachineAvailableForDeployment");
            await clientProjectEditor.Triggers.CreateOrModify("Auto-Deploy to trucks when available",
                                                              machineFilter,
                                                              new AutoDeployActionResource());

            await clientProjectEditor.Save();

            return(clientProjectEditor.Instance);
        }
        public AddProjectTests()
        {
            _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", null, null)).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>(), It.IsAny <object>()))
            .Returns((ProjectResource p, object o) =>
            {
                _projects.Add(p);
                return(p);
            });

            octoRepo.Setup(o => o.Projects).Returns(repo.Object);
        }
Esempio n. 5
0
        public ProjectEditor CreateOrModify(string name, ProjectGroupResource projectGroup, LifecycleResource lifecycle, string description, string cloneId)
        {
            var existing = repository.FindByName(name);

            if (existing == null)
            {
                Instance = repository.Create(new ProjectResource
                {
                    Name           = name,
                    ProjectGroupId = projectGroup.Id,
                    LifecycleId    = lifecycle.Id,
                    Description    = description
                }, new { clone = cloneId });
            }
            else
            {
                existing.Name           = name;
                existing.ProjectGroupId = projectGroup.Id;
                existing.LifecycleId    = lifecycle.Id;
                existing.Description    = description;

                Instance = repository.Modify(existing);
            }

            return(this);
        }
Esempio n. 6
0
 private ProjectGroup ConvertProjectGroup(ProjectGroupResource projectGroup)
 {
     return(new ProjectGroup()
     {
         Id = projectGroup.Id, Name = projectGroup.Name
     });
 }
        protected override void ProcessRecord()
        {
            object baseresource = null;

            switch (Resource)
            {
            case "Environment":
                baseresource = new EnvironmentResource();
                break;

            case "Project":
                baseresource = new ProjectResource();
                break;

            case "ProjectGroup":
                baseresource = new ProjectGroupResource();
                break;

            case "NugetFeed":
            case "ExternalFeed":
                baseresource = new NuGetFeedResource();
                break;

            case "LibraryVariableSet":
                baseresource = new LibraryVariableSetResource();
                break;

            case "Machine":
            case "Target":
                baseresource = new MachineResource();
                break;

            case "Lifecycle":
                baseresource = new LifecycleResource();
                break;

            case "Team":
                baseresource = new TeamResource();
                break;

            case "User":
                baseresource = new UserResource();
                break;

            case "Channel":
                baseresource = new ChannelResource();
                break;

            case "Tenant":
                baseresource = new TenantResource();
                break;

            case "TagSet":
                baseresource = new TagSetResource();
                break;
            }

            WriteObject(baseresource);
        }
Esempio n. 8
0
        public async Task <ProjectGroupResource> CreateGroupAsync(ProjectGroupResource group)
        {
            using (var client = await OctopusAsyncClient.Create(_endpoint))
            {
                var repo = client.CreateRepository();

                return(await repo.ProjectGroups.Create(group));
            }
        }
        /// <summary>
        /// Creates a Project Group
        /// </summary>
        /// <param name="octRepository">The repository to call against.</param>
        /// <param name="projectGroupName">Name of the new Project Group.</param>
        /// <returns>Newly Created ProjectGroup</returns>
        public static ProjectGroupResource CreateProjectGroup(OctopusRepository octRepository, string projectGroupName)
        {
            var newProjectGroup = new ProjectGroupResource()
            {
                Name = projectGroupName
            };

            return(octRepository.ProjectGroups.Create(newProjectGroup));
        }
Esempio n. 10
0
        private async Task BuildServerProject(ProjectGroupResource projectGroup, LifecycleResource normalLifecycle)
        {
            var serverProjectEditor = await Repository.Projects.CreateOrModify("Truck Tracker Server", projectGroup, normalLifecycle);

            serverProjectEditor.SetLogo(SampleImageCache.DownloadImage("http://blog.budgettrucks.com.au/wp-content/uploads/2015/08/tweed-heads-moving-truck-rental-map.jpg"));

            (await serverProjectEditor.Variables).AddOrUpdateVariableValue("DatabaseConnectionString", $"Server=trackerdb.com;Database=trackerdb;");
            (await serverProjectEditor.DeploymentProcess).AddOrUpdateStep("Deploy Application")
            .AddOrUpdateScriptAction("Deploy Application", new InlineScriptActionFromFileInAssembly("TrucksSample.Server.Deploy.fsx"), ScriptTarget.Server);

            await serverProjectEditor.Save();
        }
Esempio n. 11
0
        public async Task Request()
        {
            if (string.IsNullOrWhiteSpace(ProjectGroupName))
            {
                throw new CommandException("Please specify a project group name using the parameter: --projectGroup=XYZ");
            }
            if (string.IsNullOrWhiteSpace(ProjectName))
            {
                throw new CommandException("Please specify a project name using the parameter: --name=XYZ");
            }
            if (string.IsNullOrWhiteSpace(LifecycleName))
            {
                throw new CommandException("Please specify a lifecycle name using the parameter: --lifecycle=XYZ");
            }

            commandOutputProvider.Information("Finding project group: {Group:l}", ProjectGroupName);

            projectGroup = await Repository.ProjectGroups.FindByName(ProjectGroupName).ConfigureAwait(false);

            if (projectGroup == null)
            {
                commandOutputProvider.Information("Project group does not exist, it will be created");
                projectGroup = await Repository.ProjectGroups.Create(new ProjectGroupResource { Name = ProjectGroupName }).ConfigureAwait(false);

                projectGroupCreated = true;
            }

            commandOutputProvider.Information("Finding lifecycle: {Lifecycle:l}", LifecycleName);
            var lifecycle = await Repository.Lifecycles.FindOne(l => l.Name.Equals(LifecycleName, StringComparison.OrdinalIgnoreCase)).ConfigureAwait(false);

            if (lifecycle == null)
            {
                throw new CommandException($"The lifecycle {LifecycleName} does not exist.");
            }


            project = await Repository.Projects.FindByName(ProjectName).ConfigureAwait(false);

            if (project != null)
            {
                if (IgnoreIfExists)
                {
                    commandOutputProvider.Information("The project {Project:l} (ID {Id:l}) already exists", project.Name, project.Id);
                    return;
                }

                throw new CommandException($"The project {project.Name} (ID {project.Id}) already exists in this project group.");
            }

            commandOutputProvider.Information("Creating project: {Project:l}", ProjectName);
            project = await Repository.Projects.Create(new ProjectResource { Name = ProjectName, ProjectGroupId = projectGroup.Id, IsDisabled = false, LifecycleId = lifecycle.Id }).ConfigureAwait(false);
        }
Esempio n. 12
0
        private static ProjectGroupResource CreateProjectGroup(IOctopusRepository repository)
        {
            var projectGroupResource = new ProjectGroupResource
            {
                Name        = "SimpleTalk",
                Description = "Deploy SimpleTalk application and database schema"
            };

            var projectGroup = repository.ProjectGroups.FindByName("SimpleTalk") ??
                               repository.ProjectGroups.Create(projectGroupResource);

            return(projectGroup);
        }
Esempio n. 13
0
        private ProjectResource CreateProject(int variableSetSize, int numberOfCharsInVariableSetSizeInTitle,
                                              ProjectGroupResource projectGroupResource, LifecycleResource lifecycle)
        {
            var variableSizePadded = variableSetSize.ToString().PadLeft(numberOfCharsInVariableSetSizeInTitle, '0');

            var project = new ProjectResource()
            {
                LifecycleId    = lifecycle.Id,
                ProjectGroupId = projectGroupResource.Id,
                Name           = $"Variables (Size {variableSizePadded})"
            };

            Log.Information("Creating project {projectName}", project.Name);
            return(Repository.Projects.Create(project));
        }
Esempio n. 14
0
        public void CreateAndRemoveProjectGroup()
        {
            #region ProjectGroupCreate
            var resource = new ProjectGroupResource()
            {
                Name = TestResourceName
            };

            var createParameters = new List <CmdletParameter>
            {
                new CmdletParameter()
                {
                    Name     = "Resource",
                    Resource = resource
                }
            };

            var createPowershell = new CmdletRunspace().CreatePowershellcmdlet(CreateCmdletName, CreateCmdletType, createParameters);

            //The fact that the line below doesn't throw is enough to prove that the cmdlet returns the expected object type really. Couldn't figure out a way to make the assert around the Powershell.invoke call
            var createResult = createPowershell.Invoke <ProjectGroupResource>().FirstOrDefault();

            if (createResult != null)
            {
                Assert.AreEqual(createResult.Name, TestResourceName);
                Console.WriteLine("Created resource [{0}] of type [{1}]", createResult.Name, createResult.GetType());
            }
            #endregion

            #region ProjectGroupDelete
            var removeParameters = new List <CmdletParameter>
            {
                new CmdletParameter()
                {
                    Name     = "Resource",
                    Resource = createResult
                }
            };

            var removePowershell = new CmdletRunspace().CreatePowershellcmdlet(RemoveCmdletName, RemoveCmdletType);

            var removeResult = removePowershell.Invoke <bool>(removeParameters).FirstOrDefault();

            Assert.IsTrue(removeResult);
            Console.WriteLine("Deleted resource [{0}] of type [{1}]", createResult.Name, createResult.GetType());
            #endregion
        }
Esempio n. 15
0
        private void CreateProjects(int prefix, ProjectGroupResource group, LifecycleResource lifecycle)
        {
            var numberOfProjects = ProjectsPerGroup.Get();

            Log.Information("Creating {n} projects for {group}", numberOfProjects, group.Name);
            Enumerable.Range(1, numberOfProjects)
            .AsParallel()
            .ForAll(p =>
            {
                var project = CreateProject(group, lifecycle, $"-{prefix:000}-{p:00}");
                UpdateDeploymentProcess(project);
                CreateChannels(project, lifecycle);
                SetVariables(project);
                Log.Information("Created project {name}", project.Name);
            }
                    );
        }
Esempio n. 16
0
        public void CreateVariables(params int[] variableSetSizes)
        {
            var projectGroupResource = new ProjectGroupResource()
            {
                Id          = Guid.NewGuid().ToString(),
                Name        = ProjectGroupName,
                Description = "Projects with variable sets of varying size, generted by SeaMonkey"
            };

            Log.Information("Creating containing project group");
            projectGroupResource = Repository.ProjectGroups.Create(projectGroupResource);

            var lifecycle = Repository.Lifecycles.FindAll().First();

            var numberOfChars = variableSetSizes.Select(s => s.ToString().Length).Max();

            foreach (var variableSetSize in variableSetSizes)
            {
                var project = CreateProject(variableSetSize, numberOfChars, projectGroupResource, lifecycle);
                PopulateVariableSet(project, variableSetSize);
            }
        }
Esempio n. 17
0
        private ProjectResource CreateProject(ProjectGroupResource group, LifecycleResource lifecycle, string postfix)
        {
            var project = Repository.Projects.Create(new ProjectResource()
            {
                Name           = "Project" + postfix,
                Description    = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?",
                ProjectGroupId = group.Id,
                LifecycleId    = lifecycle.Id,
            });

            //try
            //{
            //    using (var ms = new MemoryStream(CreateLogo(project.Name, "monsterid")))
            //        Repository.Projects.SetLogo(project, project.Name + ".png", ms);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine($"Failed to create logo for {project.Name}", ex);
            //}

            return(project);
        }
Esempio n. 18
0
        public ProjectEditor CreateOrModify(string name, ProjectGroupResource projectGroup, LifecycleResource lifecycle)
        {
            var existing = repository.FindByName(name);

            if (existing == null)
            {
                Instance = repository.Create(new ProjectResource
                {
                    Name           = name,
                    ProjectGroupId = projectGroup.Id,
                    LifecycleId    = lifecycle.Id,
                });
            }
            else
            {
                existing.Name           = name;
                existing.ProjectGroupId = projectGroup.Id;
                existing.LifecycleId    = lifecycle.Id;

                Instance = repository.Modify(existing);
            }

            return(this);
        }
        private async Task BuildProject(
            ProjectGroupResource projectGroup,
            LifecycleResource normalLifecycle,
            AccountResource account)
        {
            var projectEditor = await Repository.Projects.CreateOrModify("Azure Cloud Service Sample", projectGroup, normalLifecycle);

            await projectEditor.SetLogo(SampleImageCache.DownloadImage("https://azurecomcdn.azureedge.net/cvt-9c42e10c78bceeb8622e49af8d0fe1a20cd9ca9f4983c398d0b356cf822d8844/images/shared/social/azure-icon-250x250.png"));

            var variableEditor = await projectEditor.Variables;

            if (variableEditor.Instance.Variables.All(v => v.Name != "UniqueName"))
            {
                variableEditor.AddOrUpdateVariableValue("UniqueName", Guid.NewGuid().ToString("N"));
            }
            variableEditor
            .AddOrUpdateVariableValue("CloudService", "AzureCloudService#{UniqueName}")
            .AddOrUpdateVariableValue("StorageAccount", storageAccountName)
            .AddOrUpdateVariableValue("Location", location);

            var processEditor = await projectEditor.DeploymentProcess;
            var process       = processEditor.Instance;

            process.Steps.Add(new DeploymentStepResource
            {
                Name      = "Create Azure Cloud Service",
                Condition = DeploymentStepCondition.Success,
                RequiresPackagesToBeAcquired = false,
                Actions =
                {
                    new DeploymentActionResource
                    {
                        ActionType = "Octopus.AzurePowerShell",
                        Name       = "Create Azure Cloud Service",
                        Properties =
                        {
                            { "Octopus.Action.Script.ScriptBody", "New-AzureService -ServiceName #{CloudService} -Location \"#{Location}\""   },
                            { "Octopus.Action.Azure.AccountId",   account.Id                                                                  }
                        }
                    }
                }
            });

            process.Steps.Add(new DeploymentStepResource
            {
                Name      = "Deploy Azure Cloud Service",
                Condition = DeploymentStepCondition.Success,
                RequiresPackagesToBeAcquired = true,
                Actions =
                {
                    new DeploymentActionResource
                    {
                        ActionType = "Octopus.AzureCloudService",
                        Name       = "Deploy Azure Cloud Service",
                        Properties =
                        {
                            { "Octopus.Action.Azure.AccountId",               account.Id                                            },
                            { "Octopus.Action.Azure.CloudServiceName",        "#{CloudService}"                                     },
                            { "Octopus.Action.Azure.StorageAccountName",      "#{StorageAccount}"                                   },
                            { "Octopus.Action.Azure.Slot",                    "Staging"                                             },
                            { "Octopus.Action.Azure.SwapIfPossible",          "False"                                               },
                            { "Octopus.Action.Azure.UseCurrentInstanceCount", "False"                                               },
                            { "Octopus.Action.Package.PackageId",             "Octopus.Sample.AzureCloudService"                    },
                            { "Octopus.Action.Package.FeedId",                "feeds-builtin"                                       }
                        }
                    }
                }
            });

            process.Steps.Add(new DeploymentStepResource
            {
                Name      = "Remove Azure Cloud Service",
                Condition = DeploymentStepCondition.Always,
                RequiresPackagesToBeAcquired = false,
                Actions =
                {
                    new DeploymentActionResource
                    {
                        ActionType = "Octopus.AzurePowerShell",
                        Name       = "Remove Azure Cloud Service",
                        Properties =
                        {
                            { "Octopus.Action.Script.ScriptBody", "Remove-AzureService -ServiceName #{CloudService} -Force"   },
                            { "Octopus.Action.Azure.AccountId",   account.Id                                                  }
                        }
                    }
                }
            });


            await projectEditor.Save();
        }
 public ProjectEditor CreateOrModify(string name, ProjectGroupResource projectGroup, LifecycleResource lifecycle, string description, string cloneId = null)
 {
     return(new ProjectEditor(this, new ChannelRepository(Repository), new DeploymentProcessRepository(Repository), new ProjectTriggerRepository(Repository), new VariableSetRepository(Repository)).CreateOrModify(name, projectGroup, lifecycle, description, cloneId));
 }
Esempio n. 21
0
 public Task <ProjectEditor> CreateOrModify(string name, ProjectGroupResource projectGroup, LifecycleResource lifecycle)
 {
     return(new ProjectEditor(this, new ChannelRepository(Client), new DeploymentProcessRepository(Client), new ProjectTriggerRepository(Client), new VariableSetRepository(Client)).CreateOrModify(name, projectGroup, lifecycle));
 }
 private static ProjectGroup ReadProjectGroup(ProjectGroupResource resource)
 {
     Logger.Info($"Downloading {nameof(ProjectGroupResource)}: {resource.Name}");
     return(resource.ToModel());
 }
Esempio n. 23
0
 public ProjectGroup DownloadProjectGroup(ProjectGroupResource resource)
 {
     Logger.Trace($"Downloading {nameof(ProjectGroupResource)}: {resource.Name}");
     return(resource.ToModel());
 }
Esempio n. 24
0
 public ProjectEditor CreateOrModify(string name, ProjectGroupResource projectGroup, LifecycleResource lifecycle, string description)
 {
     throw new NotImplementedException();
 }
Esempio n. 25
0
 private async Task <ProjectGroup> ReadProjectGroup(ProjectGroupResource resource)
 {
     _logger.LogInformation($"Downloading {nameof(ProjectGroupResource)}: {resource.Name}");
     return(await Task.FromResult(resource.ToModel()));
 }
 public static ProjectGroup ToModel(this ProjectGroupResource resource)
 {
     return(new ProjectGroup(new ElementIdentifier(resource.Name), resource.Description));
 }
 public static ProjectGroupResource UpdateWith(this ProjectGroupResource resource, ProjectGroup model)
 {
     resource.Name        = model.Identifier.Name;
     resource.Description = model.Description;
     return(resource);
 }
        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);
        }
 /// <summary>
 /// Gathers a List of Projects in a ProjectGroup by ProjectGroup.
 /// </summary>
 /// <param name="octRepository">The repository to call against.</param>
 /// <param name="projectGroup"></param>
 /// <returns>Enumerable of ProjectResources</returns>
 public static IEnumerable <ProjectResource> GetProjectsByProjectGroup(OctopusRepository octRepository, ProjectGroupResource projectGroup)
 {
     return(octRepository.ProjectGroups.GetProjects(projectGroup));
 }
 /// <summary>
 /// Moves a Project to the Specified ProjectGroup.
 /// </summary>
 /// <param name="octRepository">The repository to call against.</param>
 /// <param name="projectToMove"></param>
 /// <param name="projectGroup"></param>
 public static void MoveProjectToProjectGroup(OctopusRepository octRepository, ProjectResource projectToMove, ProjectGroupResource projectGroup)
 {
     projectToMove.ProjectGroupId = projectGroup.Id;
     octRepository.Projects.Modify(projectToMove);
 }