Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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>();
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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");
        }