コード例 #1
0
        public void GetOptionName_Null_ShouldThrowException()
        {
            var parser        = A.Fake <Parser>();
            var commandParser = A.Fake <CommandParser <Command1Options> >(ob => ob.WithArgumentsForConstructor(() => new CommandParser <Command1Options>(parser)));
            var parseResult   = A.Fake <ParseResult>();

            var context = new CommandValidatorContext <Command1Options>(commandParser, parseResult);

            context.Invoking(a => a.GetOptionName(null))
            .Should()
            .Throw <ArgumentNullException>();
        }
コード例 #2
0
        public void GetOptionName_UnmappedOption_ShouldThrowException()
        {
            var parser        = A.Fake <Parser>();
            var commandParser = A.Fake <CommandParser <Command1Options> >(ob => ob.WithArgumentsForConstructor(() => new CommandParser <Command1Options>(parser)));
            var parseResult   = A.Fake <ParseResult>();

            var targetProperty = typeof(Command1Options).GetProperty("OptionB");

            String optionName;

            A.CallTo(() => commandParser.TryGetOptionName(targetProperty, out optionName))
            .Returns(false);

            var context = new CommandValidatorContext <Command1Options>(commandParser, parseResult);

            context.Invoking(a => a.GetOptionName(b => b.OptionB))
            .Should()
            .Throw <ArgumentException>()
            .WithMessage(@"The property OptionB of the type ParseTheArgs.Tests.TestData.Command1Options is not mapped to any option.
Parameter name: optionSelector");
        }