public void RequiredShouldThrowExceptionIfNoValueGiven()
        {
            var parms = new CommandLineParameters();
            var version = parms.Required<string>("version");

            Assert.That(() => parms.ParseCommandLineArguments(new List<ParsedCommandLineParameter>()), Throws.InstanceOf(typeof(CommandLineParametersException)));
        }
Пример #2
0
        public void ShouldThrowIfParameterGivenButNoneRegistered()
        {
            var parms = new CommandLineParameters();

            var parsedCommandLineParameters = new List<ParsedCommandLineParameter>();
            parsedCommandLineParameters.Add(new ParsedCommandLineParameter {Name = "provided", Value = "value"});
            Assert.That(() => parms.ParseCommandLineArguments(parsedCommandLineParameters), Throws.InstanceOf(typeof(CommandLineParametersException)));
        }
        public void RequiredShouldReturnValueWhenGiven()
        {
            var parms = new CommandLineParameters();
            var version = parms.Required<string>("version");

            parms.ParseCommandLineArguments(new List<ParsedCommandLineParameter> {new ParsedCommandLineParameter {Name = "version", Value = "0.2"}});

            Assert.That(version.Value, Is.EqualTo("0.2"));
        }
Пример #4
0
        public void ShouldThrowIfParameterGivenButNoneRegistered()
        {
            var parms = new CommandLineParameters();

            var parsedCommandLineParameters = new List <ParsedCommandLineParameter>();

            parsedCommandLineParameters.Add(new ParsedCommandLineParameter {
                Name = "provided", Value = "value"
            });
            Assert.That(() => parms.ParseCommandLineArguments(parsedCommandLineParameters), Throws.InstanceOf(typeof(CommandLineParametersException)));
        }
Пример #5
0
        public void RequiredShouldThrowExceptionIfNoValueGiven()
        {
            var parms = new CommandLineParameters();

            var param1 = (IParameter) parms.Required<string>("provided");
            var param2 = (IParameter) parms.Required<int>("notprovided");

            var parsedCommandLineParameters = new List<ParsedCommandLineParameter>();
            parsedCommandLineParameters.Add(new ParsedCommandLineParameter {Name = "provided", Value = "value"});
            parms.ParseCommandLineArguments(parsedCommandLineParameters);

            Assert.That(() => parms.EnsureAllRequiredParametersHaveValues(new [] {param1, param2}), Throws.InstanceOf(typeof(CommandLineParametersException)));
        }
Пример #6
0
        public void RequiredShouldReturnValueWhenGiven()
        {
            var parms   = new CommandLineParameters();
            var version = parms.Required <string>("version");

            parms.ParseCommandLineArguments(new List <ParsedCommandLineParameter> {
                new ParsedCommandLineParameter {
                    Name = "version", Value = "0.2"
                }
            });

            Assert.That(version.Value, Is.EqualTo("0.2"));
        }
Пример #7
0
        public void RequiredShouldThrowExceptionIfNoValueGiven()
        {
            var parms = new CommandLineParameters();

            var param1 = (IParameter)parms.Required <string>("provided");
            var param2 = (IParameter)parms.Required <int>("notprovided");

            var parsedCommandLineParameters = new List <ParsedCommandLineParameter>();

            parsedCommandLineParameters.Add(new ParsedCommandLineParameter {
                Name = "provided", Value = "value"
            });
            parms.ParseCommandLineArguments(parsedCommandLineParameters);

            Assert.That(() => parms.EnsureAllRequiredParametersHaveValues(new [] { param1, param2 }), Throws.InstanceOf(typeof(CommandLineParametersException)));
        }