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);
        }
        public static FeedResource CustomExpressionFeedWithId(string id)
        {
            var feed = new NuGetFeedResource()
            {
                Id   = id,
                Name = FeedCustomExpressionHelper.CustomExpressionFeedName
            };

            return(feed);
        }
Пример #3
0
        public void CreateAndRemoveExternalFeed()
        {
            #region FeedCreate

            var resource = new NuGetFeedResource()
            {
                Name    = TestResourceName,
                FeedUri = "http://whatever.com"
            };

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

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

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