public void RegularUsageTest() { var commandTestClass = new ArgumentTestClass(); var dictionary = new Dictionary <string, CommandLineArgument> { { "SimpleArgument", new CommandLineArgument { Value = "\"SimpleArgumentValue\"" } }, { "TheName", new CommandLineArgument { Value = "TheNameValue" } }, { "TrimmedArgument", new CommandLineArgument { Value = "TrimmedArgumentValue" } }, { "RequiredArgument", new CommandLineArgument { Value = "RequiredArgumentValue" } } }; var argumentMapper = Setup.ArgumentMapper().ForType <ArgumentTestClass>().Done(); var result = argumentMapper.Map(dictionary, commandTestClass); Assert.AreEqual(result.SimpleArgument, "\"SimpleArgumentValue\""); Assert.AreEqual(result.NamedArgument, "TheNameValue"); Assert.AreEqual(result.TrimmedArgument, "TrimmedArgumentValue"); Assert.AreEqual(result.RequiredArgument, "RequiredArgumentValue"); }
public void NotUsedRequiredArgumentErrorTest() { var commandTestClass = new ArgumentTestClass(); var dictionary = new Dictionary <string, CommandLineArgument>(); var argumentMapper = Setup.ArgumentMapper().ForType <ArgumentTestClass>().Done(); argumentMapper.Invoking(x => x.Map(dictionary, commandTestClass)).ShouldThrow <MissingCommandLineArgumentException>(); }
public void NamedArgumentAliasTest() { var commandTestClass = new ArgumentTestClass(); var dictionary = new Dictionary <string, CommandLineArgument> { { "AliasName1", new CommandLineArgument { Value = "TheNameValue" } }, { "RequiredArgument", new CommandLineArgument { Value = "RequiredArgumentValue" } } }; var argumentMapper = Setup.ArgumentMapper().ForType <ArgumentTestClass>().Done(); var result = argumentMapper.Map(dictionary, commandTestClass); Assert.AreEqual(result.NamedArgument, "TheNameValue"); }
public void EnsureMappedArgumentsRaiseMappedCommandLineArgumentEvent() { var args = new ArgumentTestClass(); var argument = new CommandLineArgument { Name = "RequiredArgument", Value = "Olla" }; var property = typeof(ArgumentTestClass).GetProperty(nameof(ArgumentTestClass.RequiredArgument)); var dictionary = new Dictionary <string, CommandLineArgument> { { argument.Name, argument } }; var target = Setup.ArgumentMapper() .ForType <ArgumentTestClass>() .Done(); target.MonitorEvents(); var result = target.Map(dictionary, args); result.RequiredArgument.Should().Be(argument.Value); target.ShouldRaise(nameof(IArgumentMapper <ArgumentTestClass> .MappedCommandLineArgument)) .WithArgs <MapperEventArgs>(e => e.Argument == argument) .WithArgs <MapperEventArgs>(e => e.PropertyInfo == property); }
public void EnsureUnmappedArgumentsRaiseUnmappedCommandLineArgumentEvent() { var args = new ArgumentTestClass(); var dictionary = new Dictionary <string, CommandLineArgument> { { "RequiredArgument", new CommandLineArgument { Value = "RequiredArgumentValue" } }, { "MisspelledArgument", new CommandLineArgument { Name = "MisspelledArgument", Value = "AnyValue" } } }; var target = Setup.ArgumentMapper() .ForType <ArgumentTestClass>() .Done(); target.MonitorEvents(); var result = target.Map(dictionary, args); Assert.AreEqual(result.RequiredArgument, "RequiredArgumentValue"); target.ShouldRaise(nameof(IArgumentMapper <ArgumentTestClass> .UnmappedCommandLineArgument)) .WithArgs <MapperEventArgs>(e => e.Argument.Name == "MisspelledArgument" && e.Argument.Value == "AnyValue"); }