public void CreateAndRemoveMachine() { #region MachineCreate var environmentId = TestUtilities.Repository.Environments.FindAll().FirstOrDefault().Id; var resource = new MachineResource() { Name = TestResourceName, Endpoint = new OfflineDropEndpointResource() { ApplicationsDirectory = "SomePath", DropFolderPath = "SomePath", OctopusWorkingDirectory = "SomePath" }, EnvironmentIds = ReferenceCollection.One(environmentId), Roles = ReferenceCollection.One("WebServer"), }; 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 <MachineResource>().FirstOrDefault(); if (createResult != null) { Assert.AreEqual(createResult.Name, TestResourceName); Console.WriteLine("Created resource [{0}] of type [{1}]", createResult.Name, createResult.GetType()); } #endregion #region MachineDelete 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 }
private static List <LifecycleResource> CreateLifecycles() { CreateEnvironments();//Start by creating the environments that will be added to the repository //Create the rest of the lifecycles for test var lifecycleList = new List <LifecycleResource>(); foreach (var lifecycleName in LifecycleNames) { var lifecycle = _repository.Lifecycles.FindByName(lifecycleName).Result ?? new LifecycleResource(); lifecycle.Name = lifecycleName; lifecycle.Description = GeneralResourceProperty.ResourceDescription; if (lifecycle.Name == "Default Lifecycle") { lifecycle.Phases.Clear(); for (int i = 0; i < EnvironmentNames.Length; i++) { var environment = _repository.Environments.FindByName(EnvironmentNames[i]).Result; var phase = new PhaseResource() { Name = environment.Name, IsOptionalPhase = false, OptionalDeploymentTargets = ReferenceCollection.One(environment.Id) }; lifecycle.Phases.Insert(i, phase); } } try { Log.Information($"Creating/Modifying Lifecycle [{lifecycle.Name}]"); lifecycleList.Add(lifecycle.Id == null ? _repository.Lifecycles.Create(lifecycle).Result : _repository.Lifecycles.Modify(lifecycle).Result ); } catch (Exception e) { Console.WriteLine(e); throw; } } return(lifecycleList); }