Exemplo n.º 1
0
        public object GetValue(ArgumentInfo argumentInfo)
        {
            PromptForValue(argumentInfo);

            //when user has provided a value
            if (argumentInfo.ValueInfo.HasValue && argumentInfo.ValueInfo.Value != null)
            {
                //parse value
                IParser parser = ParserFactory.CreateInstnace(argumentInfo.Type);
                return(parser.Parse(argumentInfo));
            }

            //when value not present but method parameter has a default value defined
            if (argumentInfo.DefaultValue != DBNull.Value && argumentInfo.DefaultValue != null)
            {
                //use default paramter or property value
                return(argumentInfo.DefaultValue);
            }

            //when there no value from inut and no default value, return default value of the type
            return(argumentInfo.Type.GetDefaultValue());
        }
Exemplo n.º 2
0
 public void CanWorkWithStrings()
 {
     ParserFactory.CreateInstnace(typeof(string)).Should().BeOfType <SingleValueParser>();
     ParserFactory.CreateInstnace(typeof(List <string>)).Should().BeOfType <ListParser>();
 }
Exemplo n.º 3
0
 public void CanWorkWithEnums()
 {
     ParserFactory.CreateInstnace(typeof(Time)).Should().BeOfType <SingleValueParser>();
     ParserFactory.CreateInstnace(typeof(Time?)).Should().BeOfType <NullableValueParser>();
     ParserFactory.CreateInstnace(typeof(List <Time>)).Should().BeOfType <ListParser>();
 }
Exemplo n.º 4
0
        public void CanCreateListParser()
        {
            IParser parser = ParserFactory.CreateInstnace(typeof(List <int>));

            parser.Should().BeOfType <ListParser>();
        }
Exemplo n.º 5
0
        public void CanCreateSingleValueParser()
        {
            IParser parser = ParserFactory.CreateInstnace(typeof(int));

            parser.Should().BeOfType <SingleValueParser>();
        }
Exemplo n.º 6
0
        public void CanCreateNullableParser()
        {
            IParser parser = ParserFactory.CreateInstnace(typeof(int?));

            parser.Should().BeOfType <NullableValueParser>();
        }