public void ShouldThrowFormatExceptionOnArgumentTypeMismatch() { var args = new[] { "--key3=3.14" //Decimal value won't map to Integer property }; var target = ArgumentMapper.Map<TestTarget>(args); }
public void TestTableViewForListObject() { var mapper = new ArgumentMapper(); var maps = mapper.Map(new CommandTableView()); var table = TableView.ToTableView <ArgumentMap>(maps); table.Build(); this.Compare(table.ToString(), TestHelper.GetCurrentMethodName()); }
public void ShouldThrowArgumentExceptionWhenEnumValueIsInvalid() { var args = new[] { "--key6=Foo" }; var target = ArgumentMapper.Map<TestTarget>(args); }
public void ShouldSetDefaultWhenArgumentsNotProvided() { var args1 = new[] {"--key2=value2"}; var target1 = ArgumentMapper.Map<TestTarget>(args1); Assert.AreEqual("Foo", target1.Key1); var args2 = new[] { "--key1=value1" }; var target2 = ArgumentMapper.Map<TestTarget>(args2); Assert.AreEqual("Bar", target2.Key2); }
public void ShouldMapArgumentsToEnumProperties() { var args = new[] { "--key6=Enum3" }; var target = ArgumentMapper.Map<TestTarget>(args); Assert.AreEqual(TestArgumentEnum.Enum3, target.Key6); }
public void SingleCommandUsageTest() { var commandTestClass = new CommandTestClass(); var dictionary = new Dictionary <string, string> { { "Backup", "true" } }; var argumentMapper = new ArgumentMapper <CommandTestClass>(); var result = argumentMapper.Map(commandTestClass, dictionary); Assert.AreEqual(result.TheCommand, TestCommandType.Backup); }
public void ShouldMapArgumentsToIntegerProperties() { var args = new[] { "--key3=99" }; var target = ArgumentMapper.Map<TestTarget>(args); Assert.AreEqual(99, target.Key3); }
public void ShouldMapArgumentsToBooleanProperties() { var args = new[] { "--key8=True" }; var target = ArgumentMapper.Map<TestTarget>(args); Assert.IsTrue(target.Key8); }
public void ShouldMapArgumentsToDateTimeProperties() { var args = new[] { "--key7=7/4/1776" }; var target = ArgumentMapper.Map<TestTarget>(args); Assert.AreEqual(new DateTime(1776, 07, 4), target.Key7); }
public void ShouldMapArgumentsToDecimalProperties() { var args = new[] { "--key5=3.14" }; var target = ArgumentMapper.Map<TestTarget>(args); Assert.AreEqual(3.14M, target.Key5); }
public void NamedArgumentAliasTest() { var commandTestClass = new ArgumentTestClass(); var dictionary = new Dictionary <string, string> { { "AliasName1", "TheNameValue" }, { "RequiredArgument", "RequiredArgumentValue" } }; var argumentMapper = new ArgumentMapper <ArgumentTestClass>(); var result = argumentMapper.Map(commandTestClass, dictionary); Assert.AreEqual(result.NamedArgument, "TheNameValue"); }
public void TrimmedArgumentTest() { var commandTestClass = new ArgumentTestClass(); var dictionary = new Dictionary <string, string> { { "TrimmedArgument", "\"UntrimmedValue\"" }, { "RequiredArgument", "RequiredArgumentValue" } }; var argumentMapper = new ArgumentMapper <ArgumentTestClass>(); var result = argumentMapper.Map(commandTestClass, dictionary); Assert.AreEqual(result.TrimmedArgument, "UntrimmedValue"); }
public void ShouldMapArgumentsToStringProperties() { var args = new [] { "--key1=value1", "--key2=value2" }; var target = ArgumentMapper.Map<TestTarget>(args); Assert.AreEqual("value1", target.Key1); Assert.AreEqual("value2", target.Key2); }
public void CaseSensitiveArgumentTest() { var target = new ArgumentMapper <Arguments>(); var dictionary = new Dictionary <string, string>(StringComparer.InvariantCulture) { { "first", "45" } }; var result = target.Map(dictionary); result.First.Should().NotBe(45); dictionary.Count.Should().Be(1); }
public void EnsureUnsusedArgumentStaysInTheArgumentsDictionary() { var target = new ArgumentMapper <Arguments>(); var dictionary = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase) { { "First", "45" }, { "invalid", "45" } }; var result = target.Map(dictionary); result.First.Should().Be(45); dictionary.Count.Should().Be(1); dictionary.ContainsKey("invalid").Should().BeTrue(); }
public void EnsureOptionsAreMappedCorrectlyEvenForNullOrEmptyEntries() { var target = new ArgumentMapper <Options>(); var dictionary = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase) { { "First", null }, { "sec", string.Empty }, { "3rd", null } }; Options result = target.Map(dictionary); result.First.Should().BeTrue(); result.Second.Should().BeTrue(); result.Third.Should().BeTrue(); dictionary.Count.Should().Be(0); }
public void EnsureArgumentsAreMappedCorrectly() { var target = new ArgumentMapper <Arguments>(); var dictionary = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase) { { "First", "45" }, { "sec", "true" }, { "3rd", "Nick O'Teen" } }; var result = target.Map(dictionary); result.First.Should().Be(45); result.Second.Should().BeTrue(); result.Third.Should().Be("Nick O'Teen"); dictionary.Count.Should().Be(0); }
public void RegularUsageTest() { var commandTestClass = new ArgumentTestClass(); var dictionary = new Dictionary <string, string> { { "SimpleArgument", "\"SimpleArgumentValue\"" }, { "TheName", "TheNameValue" }, { "TrimmedArgument", "TrimmedArgumentValue" }, { "RequiredArgument", "RequiredArgumentValue" } }; var argumentMapper = new ArgumentMapper <ArgumentTestClass>(); var result = argumentMapper.Map(commandTestClass, dictionary); Assert.AreEqual(result.SimpleArgument, "\"SimpleArgumentValue\""); Assert.AreEqual(result.NamedArgument, "TheNameValue"); Assert.AreEqual(result.TrimmedArgument, "TrimmedArgumentValue"); Assert.AreEqual(result.RequiredArgument, "RequiredArgumentValue"); }
public void EnsureUnsusedOptionStaysInTheArgumentsDictionary() { var target = new ArgumentMapper <Options>(); var dictionary = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase) { { "First", null }, { "sec", string.Empty }, { "3rd", null }, { "unmaped", null } }; var result = target.Map(dictionary); result.First.Should().BeTrue(); result.Second.Should().BeTrue(); result.Third.Should().BeTrue(); dictionary.Count.Should().Be(1); dictionary.ContainsKey("unmaped").Should().BeTrue(); }
public static IEnumerable <ArgumentMap> GetArgumentsMapsFromProperties(object target, PropertyInfo[] properties, bool onlyWithAttribute = false) { var argumentMapper = new ArgumentMapper(); return(argumentMapper.Map(target, properties, onlyWithAttribute)); }