Exemplo n.º 1
0
        public void GetDashboardByEnvironmentAndStatus()
        {
            var deploymentStatus = "Canceled";
            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 <List <OutputOctopusDashboardEntry> >()[0];

            Assert.Greater(results.Count, 0);

            foreach (var item in results)
            {
                Assert.AreEqual(item.EnvironmentName, environmentName);
                Assert.AreEqual(item.DeploymentStatus, deploymentStatus);
            }
        }
Exemplo n.º 2
0
        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 <List <OutputOctopusDashboardEntry> >()[0];

            Assert.Greater(results.Count, 0);

            foreach (var item in results)
            {
                Assert.AreEqual(item.ProjectName, projectName);
                Assert.AreEqual(item.EnvironmentName, environmentName);
            }
        }
Exemplo n.º 3
0
        public void GetLifecycleByNameUsingWildcard()
        {
            var namePattern = "LifecycleTests_*";

            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 <List <OutputOctopusLifecycle> >()[0];

            Assert.AreEqual(2, results.Count);
            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));
            }
            Console.WriteLine("Resources found match pattern [{0}]", namePattern);
        }
        public void GetProjectsByNameUsingWildcard()
        {
            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 <List <OutputOctopusProject> >();

            Assert.Greater(results[0].Count, 0);
            Console.WriteLine("Resources found: {0}", results[0].Count);

            foreach (var item in results[0])
            {
                Console.WriteLine("Resource name: {0}", item.Name);
                Assert.IsTrue(pattern.IsMatch(item.Name));
            }
        }
Exemplo n.º 5
0
        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 <List <OutputOctopusDeployment> >()[0];

            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]);
        }
Exemplo n.º 6
0
        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 <OutputOctopusChannel>();

            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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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 <List <OutputOctopusDeployment> >()[0];

            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);
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        public void GetMachineByMultipleNames()
        {
            var names = new[] { Machine1, Machine2 };

            var parameters = new List <CmdletParameter> {
                new CmdletParameter()
                {
                    Name          = "Name",
                    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 <List <OutputOctopusMachine> >()[0];

            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);
        }
Exemplo n.º 11
0
        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 <List <OutputOctopusMachine> >();

                if (results != null)
                {
                    foreach (var result in results[0])
                    {
                        Assert.AreEqual(result.CommunicationStyle, style);
                    }
                }
                else
                {
                    Assert.Inconclusive("No targets of the type [{0}] were found", style);
                }
            }
        }
        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 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 <List <OutputOctopusVariableSet> >()[0];

            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 <List <OutputOctopusVariableSet> >()[0];

            Assert.AreEqual(1, results.Count);

            Assert.IsTrue(results[0].Usage.Count != 0);

            Console.WriteLine("Project usage list for Library [{0}] is not empty", libraryName);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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 <List <OutputOctopusDeployment> >()[0];

            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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        //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 <List <OutputOctopusDeployment> >()[0];

            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);
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        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 <OutputOctopusChannel>();

            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);
        }
Exemplo n.º 21
0
        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]);
        }
Exemplo n.º 22
0
        public void GetLifecycleUsingResourceOnlyReturnsRawResource()
        {
            var lifecycleName = Lifecycle1;

            var parameters = new List <CmdletParameter>
            {
                new CmdletParameter()
                {
                    Name = "resourceOnly"
                },
                new CmdletParameter()
                {
                    Name        = "lifecycleName",
                    SingleValue = lifecycleName
                }
            };

            var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType, parameters);

            var results = powershell.Invoke <List <LifecycleResource> >();

            //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 GetTagSetByProjectNameUsingWildcard()
        {
            var namePattern = "ProjectTests_*";

            var parameters = new List <CmdletParameter> {
                new CmdletParameter()
                {
                    Name = "ProjectName", 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 <List <OutputOctopusVariableSet> >()[0];

            Assert.IsTrue(results.Count > 0);
            Console.WriteLine("Resources found: {0}", results.Count);

            foreach (var item in results)
            {
                Console.WriteLine("Variable set belongs to project: {0}", item.ProjectName);
                Assert.IsTrue(pattern.IsMatch(item.ProjectName));
            }
            Console.WriteLine("Resources found match pattern [{0}]", namePattern);
        }
Exemplo n.º 24
0
        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
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
        public void ThrowIfItToolsFolderDoesNotExist()
        {
            OctoposhEnvVariables.OctopusToolsFolder = Path.Combine(TestUtilities.TestsPath, FakePath);

            var powershell = new CmdletRunspace().CreatePowershellcmdlet(CmdletName, CmdletType);

            var ex = Assert.Throws <CmdletInvocationException>(() => powershell.Invoke <List <OctopusToolVersion> >());

            StringAssert.StartsWith("Could not find a part of the path", ex.Message);
        }
Exemplo n.º 28
0
        public void GetChannelByMultipleNamesAndSingleProject()
        {
            var  projectName = Project1;
            var  name1       = Channel1;
            var  name2       = Channel2;
            var  names       = new string[] { name1, name2 };
            bool isName1     = false;
            bool isName2     = false;

            var parameters = new List <CmdletParameter>
            {
                new CmdletParameter()
                {
                    Name          = "ChannelName",
                    MultipleValue = names
                },
                new CmdletParameter()
                {
                    Name        = "ProjectName",
                    SingleValue = projectName
                }
            };

            Console.WriteLine("Looking for a channels with names [{0}] and [{1}] in project", name1, name2, 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(names.Length, results.Count);

            foreach (var resource in results)
            {
                if (resource.Name == name1)
                {
                    isName1 = true;
                }
                else if (resource.Name == name2)
                {
                    isName2 = true;
                }
                else
                {
                    Console.WriteLine("Team found with name that was not expected: [{0}]", resource.Name);
                    throw new Exception();
                }

                Assert.AreEqual(projectName, resource.ProjectName);
            }

            Assert.IsTrue(isName1);
            Assert.IsTrue(isName2);

            Console.WriteLine("The [{0}] channels found have either the name [{1}] or [{2}] and belong to the project [{3}]", results.Count, name1, name2, projectName);
        }
Exemplo n.º 29
0
        public void CreateAndRemoveLifecycle()
        {
            #region LifecycleCreate

            var releaseRetention  = new RetentionPeriod(1, RetentionUnit.Items);
            var tentacleRetention = new RetentionPeriod(1, RetentionUnit.Items);

            var resource = new LifecycleResource()
            {
                Name                    = TestResourceName,
                Description             = String.Format("Lifecycle {0}", TestResourceName),
                ReleaseRetentionPolicy  = releaseRetention,
                TentacleRetentionPolicy = tentacleRetention
            };

            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 <LifecycleResource>().FirstOrDefault();

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

            #region LifecycleDelete
            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
        }
Exemplo n.º 30
0
        public void CreateAndRemoveProject()
        {
            #region ProjectCreate

            var projectGroupId = TestUtilities.Repository.ProjectGroups.FindAll().FirstOrDefault().Id;
            var lifecycleID    = TestUtilities.Repository.Lifecycles.FindAll().FirstOrDefault().Id;

            var resource = new ProjectResource()
            {
                Name           = TestResourceName,
                ProjectGroupId = projectGroupId,
                LifecycleId    = lifecycleID
            };

            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 <ProjectResource>().FirstOrDefault();

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

            #region ProjectDelete
            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
        }