public void PossibleArgumentNames_Get_Passes_Through_To_Internal_Argument()
        {
            var expectedArgumentNames = MockRepository.GenerateStub<List<string>>();
            _argument.Expect(a => a.PossibleArgumentNames).Return(expectedArgumentNames);

            var testObject = new DateTimeArgument(_argument, _stringParser);
            var actualArgumentNames = testObject.PossibleArgumentNames;

            Assert.That(actualArgumentNames, Is.EqualTo(expectedArgumentNames));
        }
        public void ParsedArgumentName_Get_Passes_Through_To_Internal_Argument()
        {
            const string expectedArgumentName = "some argument name";
            _argument.Expect(a => a.ParsedArgumentName).Return(expectedArgumentName);

            var testObject = new DateTimeArgument(_argument, _stringParser);
            var actualArgumentName = testObject.ParsedArgumentName;

            Assert.That(actualArgumentName, Is.EqualTo(expectedArgumentName));
        }
        public void TrySetArgument_Returns_InvalidArgumentName_When_Argument_Name_Is_Incorrect()
        {
            const string argumentName = "some arg";
            _argument.Expect(a => a.TrySetArgumentName(argumentName)).Return(SetArgumentDataResult.InvalidArgumentName);

            var testObject = new DateTimeArgument(_argument, _stringParser);
            var actual = testObject.TrySetArgumentName(argumentName);

            Assert.That(actual, Is.EqualTo(SetArgumentDataResult.InvalidArgumentName));
            Assert.That(testObject.ParsedSuccessfully, Is.False);
            Assert.That(testObject.ParsedArgumentValue, Is.EqualTo(default(DateTime)));
        }
        public void ArgumentNameStringComparison_Get_And_Set_Pass_Through_To_Internal_Argument()
        {
            _argument.Expect(a => a.ArgumentNameStringComparison).SetPropertyWithArgument(StringComparison.CurrentCulture);
            _argument.Expect(a => a.ArgumentNameStringComparison).Return(StringComparison.InvariantCulture);

            var testObject = new DateTimeArgument(_argument, _stringParser)
            {
                ArgumentNameStringComparison = StringComparison.CurrentCulture
            };
            var returnedStringComparison = testObject.ArgumentNameStringComparison;

            Assert.That(returnedStringComparison, Is.EqualTo(StringComparison.InvariantCulture));
        }
예제 #5
0
        public static void Main(string[] args)
        {
            var helpArgument = new Argument(new List<string> { "help", "h", "?" }) {IsRequired = false};
            var fileTypeArgument = new CharArgument(new List<string> { "fileType", "type" });
            var fileNameArgument = new StringArgument(new List<string> { "fileName", "file" });
            var refDateArgument = new DateTimeArgument("refdate") {IsRequired = false};
            var countArgument = new IntArgument(new List<string> { "argumentCount", "count" }) {IsRequired = false};
            var allowDuplicateArgument = new BoolArgument("allowduplicatefile")
            {
                ArgumentNameStringComparison = StringComparison.CurrentCulture, //Case-sensitive
                IsRequired = false,
                UsageDescription = "Indicates whether or not to allow duplicate files"
            };

            var argumentParser = new ArgumentParser();
            IList<IArgument> allowedArguments = new List<IArgument>
            {
                helpArgument,
                fileTypeArgument,
                fileNameArgument,
                refDateArgument,
                countArgument,
                allowDuplicateArgument
            };

            var allArgumentsParsingResult = argumentParser.Parse(args, allowedArguments);

            //Solely for testing
            Console.WriteLine(JsonConvert.SerializeObject(allArgumentsParsingResult, Formatting.Indented));

            if (helpArgument.ParsedSuccessfully || !allArgumentsParsingResult.ParsingSuccessful)
            {
                var usage = argumentParser.GetUsage(ProgramDescription, allowedArguments);
                Console.WriteLine(usage);
            }
        }
        public void TrySetArgument_Returns_InvalidArgumentValue_When_Value_Expected_But_Not_Set()
        {
            const string argumentName = "someArg";
            var testObject = new DateTimeArgument(_argument, _stringParser);

            DateTime parsedValue;
            _stringParser.Expect(s => s.TryParse(null, out parsedValue)).Return(false);
            _argument.Expect(a => a.TrySetArgumentName(argumentName)).Return(SetArgumentDataResult.Success);

            var actual = testObject.TrySetArgumentNameAndValue(argumentName, null);
            Assert.That(actual, Is.EqualTo(SetArgumentDataResult.InvalidArgumentValue));
            Assert.That(testObject.ParsedSuccessfully, Is.False);
            Assert.That(testObject.ParsedArgumentValue, Is.EqualTo(default(DateTime)));
        }
        public void TrySetArgument_Returns_Success_And_Sets_Parsing_Related_Properties_When_No_Problems_Encountered()
        {
            const string argumentName = "someArg";
            const string argumentValue = "some argument";
            var expectedArgumentValue = DateTime.Now;
            var testObject = new DateTimeArgument(_argument, _stringParser);

            DateTime parsedValue;
            _stringParser.Expect(s => s.TryParse(argumentValue, out parsedValue)).OutRef(expectedArgumentValue).Return(true);
            _argument.Expect(a => a.TrySetArgumentName(argumentName)).Return(SetArgumentDataResult.Success);

            var actual = testObject.TrySetArgumentNameAndValue(argumentName, argumentValue);
            Assert.That(actual, Is.EqualTo(SetArgumentDataResult.Success));
            Assert.That(testObject.ParsedSuccessfully, Is.True);
            Assert.That(testObject.ParsedArgumentValue, Is.EqualTo(expectedArgumentValue));
        }