public void GetReleaseBySingleVersion() { var projectName = Project1; var ReleaseVersion = "0.0.1"; var parameters = new List <CmdletParameter>() { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName }, new CmdletParameter() { Name = "ReleaseVersion", SingleValue = ReleaseVersion } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <OutputOctopusRelease> >()[0]; Assert.IsTrue(results.Count == 1); Assert.AreEqual(results[0].ReleaseVersion, ReleaseVersion); }
public void GetReleaseUsingResourceOnlyReturnsRawResource() { var projectName = Project1; var latest = 1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName }, new CmdletParameter() { Name = "Latest", SingleValue = latest.ToString() }, new CmdletParameter() { Name = "resourceOnly" } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <ReleaseResource> >()[0]; //If [results] has at least one item, It'll be of the base resource type meaning the test was successful. So no need to assert Resource.Type == ExectedType Assert.AreEqual(results.Count, latest); }
public void GetReleaseByMultipleVersions() { var projectName = Project1; var releaseVersions = new string[] { "0.0.1", "0.0.2" }; var parameters = new List <CmdletParameter>() { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName }, new CmdletParameter() { Name = "ReleaseVersion", MultipleValue = releaseVersions } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <OutputOctopusRelease> >()[0]; Console.WriteLine("Found [{0}] Releases", results.Count); Assert.IsTrue(results.Count == 2); foreach (var release in results) { Assert.IsTrue(releaseVersions.Contains(release.ReleaseVersion)); } Console.WriteLine("The [{0}] releases have the version numbers [{1}] and [{2}]", results.Count, releaseVersions[0], releaseVersions[1]); }
public void GetReleaseUsingLatestX() { var projectName = Project1; var randomMax = 31; //Setting 31 as the max cause in that particular case It'll force Octopus to paginate var latest = new Random().Next(1, randomMax); var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName }, new CmdletParameter() { Name = "Latest", SingleValue = latest.ToString() } }; Console.WriteLine("Looking for the last [{0}] releases for project [{1}]", latest, projectName); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <OutputOctopusRelease> >()[0]; Console.WriteLine("Found [{0}] releases", results.Count); Assert.IsTrue(results.Count == latest); Assert.That(results.Any(r => r.ProjectName == projectName)); Console.WriteLine("All releases found belong to the project [{0}]", projectName); }
public void GetDeploymentByLatestReleases() { var projectName = Project1; var rnd = new Random(); var latestAmount = rnd.Next(1, 6); //Getting latest 1-6 releases to reduce test time. var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName }, new CmdletParameter() { Name = "LatestReleases", SingleValue = latestAmount.ToString() } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusDeployment>(); Assert.Greater(results.Count, 0); Console.WriteLine("Found [{0}] deployments", results.Count); var releaseVersions = new HashSet <string>(results.Select(d => d.ReleaseVersion)); Assert.IsTrue(releaseVersions.Count <= latestAmount); Assert.IsTrue(results.Any(d => d.ProjectName == projectName)); Console.WriteLine("The [{0}] deployments belong to the latest [{1}] releases of project [{2}]", results.Count, latestAmount, projectName); }
public void GetChannelBySingleNameInAllProjects() { var channelName = DefaultChannel; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ChannelName", SingleValue = channelName } }; Console.WriteLine("Looking for channels with name [{0}] ", channelName); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <OutputOctopusChannel> >()[0]; Console.WriteLine("Found [{0}] channels", results.Count); Assert.Greater(results.Count, 1); foreach (var channel in results) { Assert.AreEqual(channel.Name, channelName); } Console.WriteLine("The [{0}] channels found have the name [{1}]", results.Count, channelName); }
public void GetDashboardByEnvironmentAndStatus() { var deploymentStatus = "Failed"; var environmentName = "Dev"; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "DeploymentStatus", SingleValue = deploymentStatus }, new CmdletParameter() { Name = "EnvironmentName", SingleValue = environmentName } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusDashboardEntry>(); Assert.Greater(results.Count, 0); foreach (var item in results) { Assert.AreEqual(item.EnvironmentName, environmentName); Assert.AreEqual(item.DeploymentStatus, deploymentStatus); } }
public void GetUserByNameUsingWildcard() { var namePattern = "UserTests_*"; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "Name", SingleValue = namePattern } }; Console.WriteLine("Looking for resources with name pattern: [{0}]", namePattern); var pattern = new WildcardPattern(namePattern); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusUser>(); Assert.AreEqual(2, results.Count); Console.WriteLine("Resources found: [{0}]", results.Count); foreach (var item in results) { Console.WriteLine("Resource name: [{0}]", item.UserName); Assert.IsTrue(pattern.IsMatch(item.UserName)); } Console.WriteLine("All resources found match pattern [{0}]", namePattern); }
public void GetDashboardByProjectAndEnvironment() { var environmentName = "Dev"; var projectName = project1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "EnvironmentName", SingleValue = environmentName }, new CmdletParameter() { Name = "ProjectName", SingleValue = projectName } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusDashboardEntry>(); Assert.Greater(results.Count, 0); foreach (var item in results) { Assert.AreEqual(item.ProjectName, projectName); Assert.AreEqual(item.EnvironmentName, environmentName); } }
public void GetDeploymentByMultipleProjects() { var environmentName = Environment1; var projects = new string[] { Project1, Project2 }; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "EnvironmentName", SingleValue = environmentName }, new CmdletParameter() { Name = "ProjectName", MultipleValue = projects //Passing project also to reduce test overall time. Otherwise it'll search on all projects. } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusDeployment>(); Assert.Greater(results.Count, 0); Console.WriteLine("Found [{0}] deployments", results.Count); Assert.IsTrue(results.Any(r => (projects.Contains(r.ProjectName)) && (r.EnvironmentName == environmentName))); Console.WriteLine("The [{0}] deployments found belong to the environment [{1}] on projects [{2}] or [{3}]", results.Count, environmentName, projects[0], projects[1]); }
public void GetVariableSetByLibraryNameUsingWildcard() { var namePattern = "VariableSetTests_*"; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "LibrarySetName", SingleValue = namePattern } }; Console.WriteLine("Looking for resources with name pattern: {0}", namePattern); var pattern = new WildcardPattern(namePattern); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusVariableSet>(); Assert.IsTrue(results.Count > 0); Console.WriteLine("Resources found: {0}", results.Count); foreach (var item in results) { Console.WriteLine("Library Variable set found: {0}", item.LibraryVariableSetName); Assert.IsTrue(pattern.IsMatch(item.LibraryVariableSetName)); } Console.WriteLine("Resources found match pattern [{0}]", namePattern); }
public void GetReleaseByMultipleVersionsWithUnexisting() { var projectName = Project1; var goodVersion = "0.0.1"; var badVersion = "whatever"; var releaseVersions = new string[] { goodVersion, badVersion }; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName }, new CmdletParameter() { Name = "ReleaseVersion", MultipleValue = releaseVersions } }; Console.WriteLine("Looking for releases with version numbers [{0}] and [{1}]. The test expects to find only 1 release with version [{1}] for the project [{2}]", badVersion, goodVersion, projectName); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <OutputOctopusRelease> >()[0]; Console.WriteLine("Found [{0}] releases", results.Count); Assert.IsTrue(results.Count == 1); Assert.AreEqual(results[0].ReleaseVersion, goodVersion); Assert.IsTrue(results[0].ProjectName == projectName); Console.WriteLine("The release found has the version [{0}] and belongs to the project [{1}]", results[0].ReleaseVersion, projectName); }
//Testing Single Environment and Project te reduce overhead of having 1 test for project and 1 test for environment. public void GetDeploymentBySingleEnvironmentAndProject() { var environment = "Dev"; var project = Project1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "EnvironmentName", SingleValue = environment }, new CmdletParameter() { Name = "ProjectName", SingleValue = project } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusDeployment>(); Assert.Greater(results.Count, 0); Console.WriteLine("Found [{0}] deployments", results.Count); foreach (var item in results) { Assert.AreEqual(item.EnvironmentName, environment); Assert.AreEqual(item.ProjectName, project); } Console.WriteLine("The [{0}] deployments found belong to the environment [{1}] on project [{2}]", results.Count, environment, project); }
public void GetProjectGroupsByNameUsingWildcard() { var namePattern = "*1"; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "Name", SingleValue = namePattern } }; Console.WriteLine("Looking for resources with name pattern: {0}", namePattern); var pattern = new WildcardPattern(namePattern); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusProjectGroup>(); Assert.Greater(results.Count, 0); Console.WriteLine("Resources found: {0}", results.Count); foreach (var item in results) { Console.WriteLine("Resource name: {0}", item.Name); Assert.IsTrue(pattern.IsMatch(item.Name)); } }
public void GetDeploymentBySingleRelease() { var projectName = Project1; var rnd = new Random(); var releaseVersion = $"0.0.{rnd.Next(1, 12)}"; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName }, new CmdletParameter() { Name = "ReleaseVersion", SingleValue = releaseVersion } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusDeployment>(); Assert.Greater(results.Count, 0); Console.WriteLine("Found [{0}] deployments", results.Count); Assert.IsTrue(results.Any(d => (d.ReleaseVersion == releaseVersion) && (d.ProjectName == projectName))); Console.WriteLine("The [{0}] deployments belong to release [{1}] and project [{2}]", results.Count, releaseVersion, projectName); }
public void GetMachineBySingleName() { var name = Machine1; //Here we are creating the cmdlet parameter "-MachineName 'MachineTests_Machine1'" that will be passed to the cmdlet var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "MachineName", SingleValue = name } }; Console.WriteLine("Looking for resource with name [{0}]", name); //Creating the powershell cmdlet. var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); //Running the powershell cmdlet and checking its results. var results = powershell.Invoke <OutputOctopusMachine>(); Assert.AreEqual(1, results.Count); Console.WriteLine("Found [{0}]"); foreach (var item in results) { Console.WriteLine(item.Name); } }
public void GetMachineByMultipleNames() { var names = new[] { Machine1, Machine2 }; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "MachineName", MultipleValue = names } }; Console.WriteLine("Looking for [{0}] machines with the names [{1}]", names.Length, names); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusMachine>(); Console.WriteLine("Found [{0}] resources", results.Count); Assert.AreEqual(2, results.Count); foreach (var item in results) { Console.WriteLine("Resource name: {0}", item.Name); Assert.IsTrue(names.Contains(item.Name)); } Console.WriteLine("The [{0}] resources have the expected names", names.Length); }
public void GetMachineByCommunicationStyle() { var communicationStyles = new string[] { "ListeningTentacle", "PollingTentacle", "SSHEndpoint", "CloudRegion", "OfflineDrop" }; foreach (var style in communicationStyles) { var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "CommunicationStyle", SingleValue = style } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusMachine>(); if (results != null) { foreach (var result in results) { Assert.AreEqual(result.CommunicationStyle, style); } } else { Assert.Inconclusive("No targets of the type [{0}] were found", style); } } }
public void VariableSetVariableScopeIsNotEmpty() { var projectName = Project1; var variableName = "VariableSetTests_Variable1"; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ProjectName", SingleValue = projectName } }; Console.WriteLine("Looking for library variable set [{0}]", projectName); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusVariableSet>(); Assert.AreEqual(1, results.Count); var variable = results[0].Variables.FirstOrDefault(v => v.Name == variableName); Assert.IsNotNull(variable); Assert.IsTrue(variable.Scope.Channels.Count != 0); Assert.IsTrue(variable.Scope.Actions.Count != 0); Assert.IsTrue(variable.Scope.Environments.Count != 0); Assert.IsTrue(variable.Scope.Machines.Count != 0); Assert.IsTrue(variable.Scope.Roles.Count != 0); Console.WriteLine("Scope of variable [{0}] of project [{1}] is not empty", variable.Name, projectName); }
public void PassingIncludeUsageSwitchReturnsLibraryProjectUsage() { var libraryName = Library1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "IncludeUsage" }, new CmdletParameter() { Name = "LibrarySetName", SingleValue = libraryName } }; Console.WriteLine("Looking for library variable set [{0}]", libraryName); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <OutputOctopusVariableSet>(); Assert.AreEqual(1, results.Count); Assert.IsTrue(results[0].Usage.Count != 0); Console.WriteLine("Project usage list for Library [{0}] is not empty", libraryName); }
public void GetDashboardWithoutParametersReturnsValues() { var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType); var results = powershell.Invoke <OutputOctopusDashboardEntry>(); Assert.Greater(results.Count, 0); }
public void GetUserUsingResourceOnlyReturnsRawResource() { var userName = User1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "resourceOnly" }, new CmdletParameter() { Name = "UserName", SingleValue = userName } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <UserResource> >()[0]; //If [results] has at least one item, It'll be of the resource type declared on the powershell.Invoke line, meaning the test passed Assert.AreEqual(1, results.Count); ; }
public void GetMachineBySingleName() { var name = Machine1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "Name", SingleValue = name } }; Console.WriteLine("Looking for resource with name [{0}]", name); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <OutputOctopusMachine> >(); Assert.AreEqual(1, results[0].Count); Console.WriteLine("Found [{0}]"); foreach (var item in results[0]) { Console.WriteLine(item.Name); } }
public void GetChannelBySingleNameAndSingleProject() { var channelName = DefaultChannel; var projectName = Project1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "ChannelName", SingleValue = channelName }, new CmdletParameter() { Name = "ProjectName", SingleValue = projectName } }; Console.WriteLine("Looking for a channel with name [{0}] in project [{1}]", channelName, projectName); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <OutputOctopusChannel> >()[0]; Console.WriteLine("Found [{0}] channels", results.Count); Assert.AreEqual(1, results.Count); Assert.AreEqual(results[0].Name, channelName); Assert.AreEqual(results[0].ProjectName, projectName); Console.WriteLine("The [{0}] channel found has the name [{1}] and belongs to the project [{2}]", results.Count, channelName, projectName); }
public void GetChannelUsingResourceOnlyReturnsRawResource() { var name = Channel1; var projectName = Project1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "resourceOnly" }, new CmdletParameter() { Name = "ChannelName", SingleValue = name }, new CmdletParameter() { Name = "ProjectName", SingleValue = projectName } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); var results = powershell.Invoke <List <ChannelResource> >(); //If [results] has at least one item, It'll be of the resource type declared on the powershell.Invoke line, meaning the test passed Assert.Greater(results[0].Count, 0); ; }
public void InstallToolByLatestAndDoNotSetAsDefault() { //Clearing temp directory at beginning of the test ClearTempDirectory(); //Setting the OctoExe environment variable to a fake path, to make sure that after running the cmdlet the faka path remains, meaning the recently downloaded Octo.exe wasn't set as default var fakeOctoExepath = @"Fake\path"; OctoposhEnvVariables.Octoexe = fakeOctoExepath; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "Latest" } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); Assert.DoesNotThrow(() => powershell.Invoke()); //Asserting that the OctoExe environment variable is still == fakeOctoExePath Assert.AreEqual(OctoposhEnvVariables.Octoexe, fakeOctoExepath); }
public void InstallToolByVersionAndSetAsDefault() { ClearTempDirectory(); var version = Version1; var parameters = new List <CmdletParameter> { new CmdletParameter() { Name = "Version", SingleValue = version }, new CmdletParameter() { Name = "SetAsDefault" } }; var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters); Assert.DoesNotThrow(() => powershell.Invoke()); var expectedpath = Path.Combine(TestUtilities.TestsPath, TempDirectory, String.Concat("OctopusTools.", version), "Octo.exe"); Assert.AreEqual(OctoposhEnvVariables.Octoexe, expectedpath); }
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 }
public void ThrowIfCantFindAnyOctoExeVersionsInFolder() { OctoposhEnvVariables.OctopusToolsFolder = Path.Combine(TestUtilities.TestsPath, EmptyPath); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType); var ex = Assert.Throws <CmdletInvocationException>(() => powershell.Invoke <List <OctopusToolVersion> >()); StringAssert.StartsWith("No version of [Octo.exe] was found", ex.Message); }
public void NotPassingAParameterReturnsMultipleVersions() { OctoposhEnvVariables.OctopusToolsFolder = Path.Combine(TestUtilities.TestsPath, AssetsPath); var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType); var results = powershell.Invoke <OctopusToolVersion>(); Assert.IsTrue(results.Count > 1); }