Choice Build parameter. Allows selection of a build parameter from multiple options
Inheritance: BaseBuildParameter
        public void TestChoiceParameter()
        {
            var xml = @"<parameterDefinition>
                        <defaultParameterValue>
                        <value>ONE</value>
                        </defaultParameterValue>
                        <description>Select a choice</description>
                        <name>CHOICE.1</name>
                        <type>ChoiceParameterDefinition</type>
                        <choice>ONE</choice>
                        <choice>TWO</choice>
                        <choice>THREE</choice>
                        </parameterDefinition>";

            var xDoc = XDocument.Parse(xml).Descendants().First();
            var choice = new ChoiceParameter(xDoc);

            Assert.AreEqual(choice.Name, "CHOICE.1");
            Assert.AreEqual(choice.Description, "Select a choice");
            Assert.AreEqual(choice.ParameterType, BuildParameterType.ChoiceParameterDefinition);
            Assert.AreEqual(choice.DefaultValue, "ONE");

            CollectionAssert.AllItemsAreNotNull(choice.Options);
            CollectionAssert.AllItemsAreUnique(choice.Options);

            // Check the name/value pairs
            Assert.AreEqual(choice.Options.Length, 3);
            Assert.AreEqual(choice.Options[0].Value, "ONE");
            Assert.AreEqual(choice.Options[0].Name, "ONE");

            Assert.AreEqual(choice.Options[1].Value, "TWO");
            Assert.AreEqual(choice.Options[1].Name, "TWO");

            Assert.AreEqual(choice.Options[2].Value, "THREE");
            Assert.AreEqual(choice.Options[2].Name, "THREE");
        }
Esempio n. 2
0
        private List<ParameterBase> GetBuildParameters(XDocument xDoc)
        {
            // Construct the build parameters
            var buildParameters = new List<ParameterBase>();
            var parametersNodes = xDoc.Descendants("action").Elements("parameterDefinition");
            var supportedTypes = Enum.GetNames(typeof(BuildParameterType));
            foreach (var parameterNode in parametersNodes)
            {
                var type = (string)parameterNode.Element("type");
                if (!supportedTypes.Contains(type)) continue;

                switch ((BuildParameterType)Enum.Parse(typeof(BuildParameterType), type))
                {
                    case BuildParameterType.BooleanParameterDefinition:
                        var booleanBuildParamter = new BuildParameters.BooleanParameter(parameterNode);
                        buildParameters.Add(booleanBuildParamter.ToParameterBase());
                        break;

                    case BuildParameterType.ChoiceParameterDefinition:
                        var choiceBuildParameter = new ChoiceParameter(parameterNode);
                        buildParameters.Add(choiceBuildParameter.ToParameterBase());
                        break;

                    case BuildParameterType.StringParameterDefinition:
                        var stringBuildParameter = new StringParameter(parameterNode);
                        buildParameters.Add(stringBuildParameter.ToParameterBase());
                        break;
                }
            }

            return buildParameters;
        }