public void Create_MissingMandatory() { CommandLine commandLine = new CommandLine("ValidCommand -name 1"); IDangrCommandFactory factory = new DangrCommandFactory <ValidCommand>(); MissingCommandArgumentException exception = TestUtils.TestForError <MissingCommandArgumentException>( () => factory.Create(commandLine), "Expected exception not thrown."); Validate.Value.AreEqual("MandatoryArg", exception.ArgumentName, "Exception thrown for wrong argument."); }
public void Create_WrongTypeForFlag() { CommandLine commandLine = new CommandLine("ValidCommand -MandatoryArg 1 -name"); IDangrCommandFactory factory = new DangrCommandFactory <ValidCommand>(); InvalidCommandArgumentException exception = TestUtils.TestForError <InvalidCommandArgumentException>( () => factory.Create(commandLine), "Expected exception not thrown."); Validate.Value.AreEqual("name", exception.ArgumentName, "Exception thrown for wrong argument."); }
public void Create_UnknownPositionalParameter() { CommandLine commandLine = new CommandLine("ValidCommand -MandatoryArg 1 positional0 positional1 positional2"); IDangrCommandFactory factory = new DangrCommandFactory <ValidCommand>(); UnknownCommandArgumentException exception = TestUtils.TestForError <UnknownCommandArgumentException>( () => factory.Create(commandLine), "Expected exception not thrown."); Validate.Value.AreEqual("Positional parameter 2", exception.ArgumentName, "Exception thrown for wrong argument."); }
public void Parse_Bool() { CommandLine commandLine = new CommandLine($"Types -Bool"); IDangrCommandFactory factory = new DangrCommandFactory <TypeCommand>(); IDangrCommand command = factory.Create(commandLine); Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created."); TypeCommand typeCommand = (TypeCommand)command; Validate.Value.IsTrue(typeCommand.Bool, "Wrong value assigned arg."); }
public void Parse_String() { const string expected = "1234.5"; CommandLine commandLine = new CommandLine($"Types -String {expected}"); IDangrCommandFactory factory = new DangrCommandFactory <TypeCommand>(); IDangrCommand command = factory.Create(commandLine); Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created."); TypeCommand typeCommand = (TypeCommand)command; Validate.Value.AreEqual(expected, typeCommand.String, "Wrong value assigned arg."); }
public void Parse_Int() { const int expected = 12345; CommandLine commandLine = new CommandLine($"Types -Int {expected}"); IDangrCommandFactory factory = new DangrCommandFactory <TypeCommand>(); IDangrCommand command = factory.Create(commandLine); Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created."); TypeCommand typeCommand = (TypeCommand)command; Validate.Value.AreEqual(expected, typeCommand.Int, "Wrong value assigned arg."); }
public void Parse_Decimal() { const decimal expected = 12.345M; CommandLine commandLine = new CommandLine($"Types -Decimal {expected}"); IDangrCommandFactory factory = new DangrCommandFactory <TypeCommand>(); IDangrCommand command = factory.Create(commandLine); Validate.Value.IsType <TypeCommand>(command, "Wrong type of command created."); TypeCommand typeCommand = (TypeCommand)command; Validate.Value.AreEqual(expected, typeCommand.Decimal, "Wrong value assigned arg."); }
public void Create_WithNamedArg() { CommandLine commandLine = new CommandLine("ValidCommand -MandatoryArg 1 -Named0 named"); IDangrCommandFactory factory = new DangrCommandFactory <ValidCommand>(); IDangrCommand command = factory.Create(commandLine); Validate.Value.IsType <ValidCommand>(command, "Wrong type of command created."); ValidCommand validCommand = (ValidCommand)command; Validate.Value.AreEqual("1", validCommand.MandatoryArg, "Wrong value assigned for madatory arg."); Validate.Value.AreEqual("named", validCommand.Named0, "Wrong value assigned for named arg."); Validate.Value.IsNull(validCommand.Parameter0, "Value should not have been assigned for positional arg 0."); Validate.Value.IsNull(validCommand.Parameter1, "Value should not have been assigned for positional arg 1."); Validate.Value.IsFalse(validCommand.Flag0, "Flag0 should not have been set."); Validate.Value.IsNull(validCommand.SkipThisProperty, "Value should not have been assigned for non parameter property."); }