Exemplo n.º 1
0
        public static IEnumerable <ActionMap> GetActionsMapsFromTargetObject(object target, bool onlyWithAttribute = false, bool usePrefixInAllMethods = false, string prefix = null)
        {
            var argumentMapper = new ArgumentMapper();
            var actionMapper   = new ActionMapper(argumentMapper);

            return(actionMapper.Map(target, onlyWithAttribute, usePrefixInAllMethods, prefix));
        }
Exemplo n.º 2
0
        public void NotUsedRequiredArgumentErrorTest()
        {
            var commandTestClass = new ArgumentTestClass();
            var dictionary       = new Dictionary <string, string>();
            var argumentMapper   = new ArgumentMapper <ArgumentTestClass>();

            argumentMapper.Invoking(x => x.Map(commandTestClass, dictionary)).ShouldThrow <MissingCommandLineArgumentException>();
        }
Exemplo n.º 3
0
        public void NoCommandUsageErrorTest()
        {
            var commandTestClass = new CommandTestClass();
            var dictionary       = new Dictionary <string, string>();
            var argumentMapper   = new ArgumentMapper <CommandTestClass>();

            argumentMapper.Invoking(x => x.Map(commandTestClass, dictionary)).ShouldThrow <CommandLineArgumentException>().WithMessage(
                "The command 'Backup|Init|Restore' must be used.");
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a new generic backend.
 /// </summary>
 /// <param name="context">The context to use.</param>
 /// <param name="backendType">The backend type.</param>
 /// <param name="backendFlags">The backend flags.</param>
 /// <param name="argumentMapper">The argument mapper to use.</param>
 protected Backend(
     Context context,
     BackendType backendType,
     BackendFlags backendFlags,
     ArgumentMapper argumentMapper)
     : base(context, backendType, backendFlags, argumentMapper)
 {
     IntrinsicProvider = context.IntrinsicManager.CreateProvider <TDelegate>(this);
 }
Exemplo n.º 6
0
        public void ShouldThrowFormatExceptionOnArgumentTypeMismatch()
        {
            var args = new[]
            {
                "--key3=3.14"   //Decimal value won't map to Integer property
            };

            var target = ArgumentMapper.Map<TestTarget>(args);
        }
Exemplo n.º 7
0
        public void ShouldThrowArgumentExceptionWhenEnumValueIsInvalid()
        {
            var args = new[]
            {
                "--key6=Foo"
            };

            var target = ArgumentMapper.Map<TestTarget>(args);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public void MultipleSameCommandUsageErrorTest()
        {
            var commandTestClass = new CommandTestClass();
            var dictionary       = new Dictionary <string, string> {
                { "Backup", "true" }, { "B", "true" }
            };
            var argumentMapper = new ArgumentMapper <CommandTestClass>();

            argumentMapper.Invoking(x => x.Map(commandTestClass, dictionary)).ShouldThrow <CommandLineArgumentException>().WithMessage(
                "Multiple aruments for 'Backup'-command is not allowed.");
        }
Exemplo n.º 11
0
 /// <summary>
 /// Constructs a new IL backend.
 /// </summary>
 /// <param name="context">The context to use.</param>
 /// <param name="warpSize">The current warp size.</param>
 /// <param name="argumentMapper">The argument mapper.</param>
 internal ILBackend(
     Context context,
     int warpSize,
     ArgumentMapper argumentMapper)
     : base(
         context,
         new ILABI(context.TypeContext, RuntimePlatform),
         argumentMapper)
 {
     WarpSize = warpSize;
 }
Exemplo n.º 12
0
        public void IntArgumentTest()
        {
            var unmapTestImnstance = new UnmapTestClass {
                IntArgument = 1234
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual(@"IntArgument=""1234""", unMap);
        }
Exemplo n.º 13
0
        public void CommandTest()
        {
            var unmapTestImnstance = new UnmapTestClass {
                TheCommand = TestCommandType.Restore
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual(@"-Restore", unMap);
        }
Exemplo n.º 14
0
        public void ShouldMapArgumentsToEnumProperties()
        {
            var args = new[]
            {
                "--key6=Enum3"
            };

            var target = ArgumentMapper.Map<TestTarget>(args);

            Assert.AreEqual(TestArgumentEnum.Enum3, target.Key6);
        }
Exemplo n.º 15
0
        public void NamedArgumentTest()
        {
            var unmapTestImnstance = new UnmapTestClass {
                NamedArgument = "dödl"
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual(@"MyArg=""dödl""", unMap);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        public void ShouldMapArgumentsToDecimalProperties()
        {
            var args = new[]
            {
                "--key5=3.14"
            };

            var target = ArgumentMapper.Map<TestTarget>(args);

            Assert.AreEqual(3.14M, target.Key5);
        }
Exemplo n.º 18
0
        public void ShouldMapArgumentsToIntegerProperties()
        {
            var args = new[]
            {
                "--key3=99"
            };

            var target = ArgumentMapper.Map<TestTarget>(args);

            Assert.AreEqual(99, target.Key3);
        }
Exemplo n.º 19
0
        public void ShouldMapArgumentsToBooleanProperties()
        {
            var args = new[]
            {
                "--key8=True"
            };

            var target = ArgumentMapper.Map<TestTarget>(args);

            Assert.IsTrue(target.Key8);
        }
Exemplo n.º 20
0
        public void NoOptionTest()
        {
            var unmapTestImnstance = new UnmapTestClass {
                SimpleOption = false
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual(@"", unMap);
        }
Exemplo n.º 21
0
        public void NullTest()
        {
            var unmapTestImnstance = new UnmapTestClass()
            {
                NamedArgument = null, SimpleOption = false, TheCommand = TestCommandType.None, SimpleArgument = null
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual("", unMap);
        }
Exemplo n.º 22
0
        public void ArgumentTest()
        {
            var unmapTestImnstance = new UnmapTestClass()
            {
                SimpleArgument = "TEstArg"
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual(@"SimpleArgument=""TEstArg""", unMap);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Constructs a new generic backend.
 /// </summary>
 /// <param name="context">The context to use.</param>
 /// <param name="backendType">The backend type.</param>
 /// <param name="backendFlags">The backend flags.</param>
 /// <param name="argumentMapper">The argument mapper to use.</param>
 protected CodeGeneratorBackend(
     Context context,
     BackendType backendType,
     BackendFlags backendFlags,
     ArgumentMapper argumentMapper)
     : base(
         context,
         backendType,
         backendFlags,
         argumentMapper)
 {
 }
Exemplo n.º 24
0
        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");
        }
Exemplo n.º 25
0
        public void FullArgumentsTest()
        {
            var unmapTestImnstance = new UnmapTestClass()
            {
                TheCommand = TestCommandType.Backup, SimpleArgument = "TheArgument", SimpleOption = true
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual(@"-Backup SimpleArgument=""TheArgument"" -so", unMap);
        }
Exemplo n.º 26
0
        public void LargeNumberTest()
        {
            var unmapTestImnstance = new UnmapTestClass()
            {
                LargeNumber = long.MaxValue
            };

            var argumentMapper = new ArgumentMapper <UnmapTestClass>();
            var unMap          = argumentMapper.UnMap(unmapTestImnstance);

            Assert.AreEqual(string.Format("LargeNumber=\"{0}\"", long.MaxValue), unMap);
        }
Exemplo n.º 27
0
        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");
        }
Exemplo n.º 28
0
 /// <summary>
 /// Constructs a new generic backend.
 /// </summary>
 /// <param name="context">The context to use.</param>
 /// <param name="capabilities">The supported capabilities.</param>
 /// <param name="backendType">The backend type.</param>
 /// <param name="argumentMapper">The argument mapper to use.</param>
 protected CodeGeneratorBackend(
     Context context,
     CapabilityContext capabilities,
     BackendType backendType,
     ArgumentMapper argumentMapper)
     : base(
         context,
         capabilities,
         backendType,
         argumentMapper)
 {
 }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        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);
        }