public void ResolvesDuplicatedDynamicParameterName()
        {
            string[] parameters        = { "Name", "Location", "Mode" };
            string[] parameterSetNames = { "__AllParameterSets" };
            string   key = "Name";
            TemplateFileParameterV1 value = new TemplateFileParameterV1()
            {
                AllowedValues = new List <object>()
                {
                    "Mode1", "Mode2", "Mode3"
                },
                MaxLength = "5",
                MinLength = "1",
                Type      = "bool"
            };
            KeyValuePair <string, TemplateFileParameterV1> parameter = new KeyValuePair <string, TemplateFileParameterV1>(key, value);

            RuntimeDefinedParameter dynamicParameter = TemplateUtility.ConstructDynamicParameter(parameters, parameter);

            Assert.Equal(key + "FromTemplate", dynamicParameter.Name);
            Assert.Equal(value.DefaultValue, dynamicParameter.Value);
            Assert.Equal(typeof(bool), dynamicParameter.ParameterType);
            Assert.Equal(2, dynamicParameter.Attributes.Count);

            ParameterAttribute parameterAttribute = (ParameterAttribute)dynamicParameter.Attributes[0];

            Assert.True(parameterAttribute.Mandatory);
            Assert.True(parameterAttribute.ValueFromPipelineByPropertyName);
            Assert.Equal(parameterSetNames[0], parameterAttribute.ParameterSetName);

            ValidateLengthAttribute validateLengthAttribute = (ValidateLengthAttribute)dynamicParameter.Attributes[1];

            Assert.Equal(int.Parse(value.MinLength), validateLengthAttribute.MinLength);
            Assert.Equal(int.Parse(value.MaxLength), validateLengthAttribute.MaxLength);
        }
        public void ConstructsObjectTypeDynamicParameter()
        {
            string[] parameters        = { "Name", "Location", "Mode" };
            string[] parameterSetNames = { "__AllParameterSets" };
            string   key = "appSku";
            TemplateFileParameterV1 value = new TemplateFileParameterV1()
            {
                AllowedValues = new List <object>()
                {
                    JObject.Parse("{\"code\" : \"F1\", \"name\" : \"Free\"}"),
                    JObject.Parse("{\"code\" : \"F2\", \"name\" : \"Shared\"}"),
                },
                DefaultValue = JObject.Parse("{\"code\" : \"F1\", \"name\" : \"Free\"}"),
                Type         = "object"
            };
            KeyValuePair <string, TemplateFileParameterV1> parameter = new KeyValuePair <string, TemplateFileParameterV1>(key, value);

            RuntimeDefinedParameter dynamicParameter = TemplateUtility.ConstructDynamicParameter(parameters, parameter);

            Assert.Equal("appSku", dynamicParameter.Name);
            Assert.Equal(value.DefaultValue, dynamicParameter.Value);
            Assert.Equal(typeof(Hashtable), dynamicParameter.ParameterType);
            Assert.Single(dynamicParameter.Attributes);

            ParameterAttribute parameterAttribute = (ParameterAttribute)dynamicParameter.Attributes[0];

            Assert.False(parameterAttribute.Mandatory);
            Assert.True(parameterAttribute.ValueFromPipelineByPropertyName);
            Assert.Equal(parameterSetNames[0], parameterAttribute.ParameterSetName);
        }
        public void ConstructsArrayTypeDynamicParameter()
        {
            string[] parameters        = { "Name", "Location", "Mode" };
            string[] parameterSetNames = { "__AllParameterSets" };
            string   key = "ranks";
            TemplateFileParameterV1 value = new TemplateFileParameterV1()
            {
                AllowedValues = new List <object>()
                {
                    JArray.Parse("[\"1\", \"3\", \"5\"]"),
                    JArray.Parse("[\"A\", \"D\", \"F\"]"),
                },
                DefaultValue = JArray.Parse("[\"A\", \"D\", \"F\"]"),
                Type         = "array"
            };
            KeyValuePair <string, TemplateFileParameterV1> parameter = new KeyValuePair <string, TemplateFileParameterV1>(key, value);

            RuntimeDefinedParameter dynamicParameter = TemplateUtility.ConstructDynamicParameter(parameters, parameter);

            Assert.Equal("ranks", dynamicParameter.Name);
            Assert.Equal(value.DefaultValue, dynamicParameter.Value);
            Assert.Equal(typeof(object[]), dynamicParameter.ParameterType);
            Assert.Single(dynamicParameter.Attributes);

            ParameterAttribute parameterAttribute = (ParameterAttribute)dynamicParameter.Attributes[0];

            Assert.False(parameterAttribute.Mandatory);
            Assert.True(parameterAttribute.ValueFromPipelineByPropertyName);
            Assert.Equal(parameterSetNames[0], parameterAttribute.ParameterSetName);
        }
        public void ConstructsDynamicParameterWithNullAllowedValues()
        {
            string[] parameters        = { "Name", "Location", "Mode" };
            string[] parameterSetNames = { "__AllParameterSets" };
            string   key = "computeMode";
            TemplateFileParameterV1 value = new TemplateFileParameterV1()
            {
                AllowedValues = null,
                DefaultValue  = "Mode1",
                Type          = "securestring"
            };
            KeyValuePair <string, TemplateFileParameterV1> parameter = new KeyValuePair <string, TemplateFileParameterV1>(key, value);

            RuntimeDefinedParameter dynamicParameter = TemplateUtility.ConstructDynamicParameter(parameters, parameter);

            Assert.Equal("computeMode", dynamicParameter.Name);
            Assert.Equal(value.DefaultValue, dynamicParameter.Value);
            Assert.Equal(typeof(SecureString), dynamicParameter.ParameterType);
            Assert.Single(dynamicParameter.Attributes);

            ParameterAttribute parameterAttribute = (ParameterAttribute)dynamicParameter.Attributes[0];

            Assert.False(parameterAttribute.Mandatory);
            Assert.True(parameterAttribute.ValueFromPipelineByPropertyName);
            Assert.Equal(parameterSetNames[0], parameterAttribute.ParameterSetName);
        }