[Fact]
        //[Theory]
        //[InlineData(new string[] { "--count","10" })]
        public int ValidateTest()
        {
            // Console.WriteLine("Sample debug output");    
            string[] args = new string[] { "--name", "10" };
            if (args == null || !args.Any())
            {
                return -1;
            }
            var nameValueIndex = -1;
            var countValueIndex = -1;
            int index = 0;
            bool ifHelp = false;
            foreach (var i in args)
            {
                Console.WriteLine(index + ":" + i);
                if (i.ToLower() == "--name")
                {
                    nameValueIndex = index + 1;
                }
                if (i.ToLower() == "--count")
                {
                    countValueIndex = index + 1;
                }
                if (i.ToLower() == "--help")
                {
                    ifHelp = true;
                }
                index++;
            }
            if (nameValueIndex >= 0)
            {
                Console.WriteLine("nameValueIndex:" + nameValueIndex);
                if (nameValueIndex > args.Length - 1)
                {
                    return -1;
                }
                var nameV = args.ElementAt(nameValueIndex);
                int nameConvertV;
                if (!int.TryParse(nameV, out nameConvertV))
                {
                    if (nameV.Length < 3 || nameV.Length > 10)
                    {
                        return -1;
                    }
                }
            }
            if (countValueIndex >= 0 )
            {
                Console.WriteLine("countValueIndex:" + countValueIndex);
                if (countValueIndex > args.Length - 1)
                {
                    return -1;
                }
                var countV = args.ElementAt(countValueIndex);
                int countConvertV ;
                if (!int.TryParse(countV,out countConvertV))
                {
                    return -1;
                }
                if(countConvertV<10 || countConvertV > 100)
                {
                    return -1;
                }
            }
            if(!ifHelp && countValueIndex<0 && nameValueIndex < 0)
            {
                return -1;
            }
            if (ifHelp)
            {
                if (args.Length > 1)
                {
                    if(countValueIndex < 0 && nameValueIndex < 0)
                    {
                        return -1;
                    }
                }
                Console.WriteLine("ifHelp:" + ifHelp);
                return 1;
            }
            return 0;
        }

  

相关文章:

  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2021-05-22
  • 2021-08-20
  • 2022-12-23
  • 2021-09-01
  • 2021-11-14
猜你喜欢
  • 2021-05-26
  • 2021-05-22
  • 2021-11-22
  • 2021-07-10
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案