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 StringArgument(_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 StringArgument(_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 StringArgument(_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.Null);
        }
        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 StringArgument(_argument, _stringParser)
            {
                ArgumentNameStringComparison = StringComparison.CurrentCulture
            };
            var returnedStringComparison = testObject.ArgumentNameStringComparison;

            Assert.That(returnedStringComparison, Is.EqualTo(StringComparison.InvariantCulture));
        }
Beispiel #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 StringArgument(_argument, _stringParser);

            string 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.Null);
        }
        public void TrySetArgument_Returns_Success_And_Sets_Parsing_Related_Properties_When_No_Problems_Encountered()
        {
            const string argumentName = "someArg";
            const string argumentValue = "some argument";
            const string expectedArgumentValue = "some arg value";
            var testObject = new StringArgument(_argument, _stringParser);

            string 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));
        }
        public void ArgumentParser_Sets_Argument_Name_And_Value_When_Appropriate()
        {
            const string argumentName = "argumentName";
            const string argumentWithValueName = "SomeArgumentWithValueName";
            const string argumentValue = "some argument value";

            var argument = new Argument(new List<string> { argumentName });
            var stringArgument = new StringArgument(new List<string> { argumentWithValueName });
            var allowedArguments = new List<IArgument> {argument, stringArgument };

            var stringArgsArray = new string[]{};
            var argumentToValueMap = new Dictionary<string, string>
            {
                { argumentName, null },
                { argumentWithValueName, argumentValue}
            };
            var argumentMapResult = new ArgumentValueMapperResult { ArgumentToValueMap = argumentToValueMap};

            _argumentValueMapper.Expect(a => a.GetArgumentToValueMap(stringArgsArray, _testObject.ArgumentDelimeters, _testObject.ValueDelimeters)).Return(argumentMapResult);

            var actualResult = _testObject.Parse(stringArgsArray, allowedArguments);

            Assert.That(actualResult.ParsingSuccessful, Is.True);
            Assert.That(argument.ParsedArgumentName, Is.EqualTo(argumentName));
            Assert.That(argument.ParsedSuccessfully, Is.True);

            Assert.That(stringArgument.ParsedArgumentName, Is.EqualTo(argumentWithValueName));
            Assert.That(stringArgument.ParsedArgumentValue, Is.EqualTo(argumentValue));
            Assert.That(stringArgument.ParsedSuccessfully, Is.True);
        }