Esempio n. 1
0
        public void Run_should_throw_InvalidOperationException_if_Log_property_is_null()
        {
            //  arrange
            var cmd  = new MockCommand1();
            var args = new MockCommandArgs();

            //  act
            var ex = Assert.Throws <InvalidOperationException>(() => cmd.Run(args));

            Assert.AreEqual("ICommand.Log cannot be null.", ex.Message);
        }
        public void Parse_should_validate_properties()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "-v", "1" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.IsFalse(opts.IsValid);
        }
        public void Parse_should_set_property_values_to_matching_named_arguments()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "-connection", "joshua", "-v", "123" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual("joshua", opts.Connection);
            Assert.AreEqual(123, opts.TargetVersion);
        }
        public void Parse_should_set_property_values_by_position_of_anonymous_arguments()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "joshua", "2" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual("joshua", opts.Connection);
            Assert.AreEqual(2, opts.TargetVersion);
        }
        public void Parse_should_override_anonymous_arguments_with_named_arguments()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "joshua", "2", "-connection", "david", "-v", "123" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual("david", opts.Connection);
            Assert.AreEqual(123, opts.TargetVersion);
        }
        public void Parse_should_set_property_values_to_matching_named_arguments()
        {
            //  arrange
            OldArgumentSet args = OldArgumentSet.Parse(new[] {"-connection", "joshua", "-v", "123"});
            var opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.Equal("joshua", opts.Connection);
            Assert.Equal(123, opts.TargetVersion);
        }
        public void Parse_should_set_property_values_by_position_of_anonymous_arguments()
        {
            //  arrange
            OldArgumentSet args = OldArgumentSet.Parse(new[] {"joshua", "2"});
            var opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.Equal("joshua", opts.Connection);
            Assert.Equal(2, opts.TargetVersion);
        }
        public void Parse_should_override_anonymous_arguments_with_named_arguments()
        {
            //  arrange
            OldArgumentSet args = OldArgumentSet.Parse(new[] {"joshua", "2", "-connection", "david", "-v", "123"});
            var opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.Equal("david", opts.Connection);
            Assert.Equal(123, opts.TargetVersion);
        }
        public void Parse_should_validate_arguments_and_add_error_messages_to_collection()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "-v", "0" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual(2, opts.Errors.Count());
            Assert.AreEqual("Connection is required", opts.Errors.First());
            Assert.AreEqual("Target version must be between 1 and 5", opts.Errors.Last());
        }
Esempio n. 10
0
        public void Run_should_throw_InvalidOperationException_if_args_are_not_valid()
        {
            //  arrange
            var cmd = new MockCommand1();

            cmd.Log = new MockLog1();
            ArgumentSet argSet = ArgumentSet.Parse(new[] { "blah" });
            var         args   = new MockCommandArgs();

            args.Parse(argSet);

            //  act
            var ex = Assert.Throws <InvalidOperationException>(() => cmd.Run(args));

            Assert.AreEqual("Argument validation failed. Arguments are invalid.", ex.Message);
        }
        public void Parse_should_validate_arguments_and_add_error_messages_to_collection()
        {
            //  arrange
            OldArgumentSet args = OldArgumentSet.Parse(new[] {"-v", "0"});
            var opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.Equal(2, opts.Errors.Count());
            Assert.Equal("Connection is required", opts.Errors.First());
            Assert.Equal("Target version must be between 1 and 5", opts.Errors.Last());
        }
        public void Parse_should_validate_properties()
        {
            //  arrange
            OldArgumentSet args = OldArgumentSet.Parse(new[] {"-v", "1"});
            var opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.False(opts.IsValid);
        }