Example #1
0
        public void HowToSetPropertyOnDynamicallyCreatedObject()
        {
            Type type = typeof(OperationWithSimpleProps);

            IOperation instance = (IOperation)Activator.CreateInstance(type);

            PropertyInfo arg1 = type.GetProperty("Arg1");

            arg1.SetValue(instance, "test value");

            OperationWithSimpleProps typed = (OperationWithSimpleProps)instance;

            Assert.AreEqual("test value", typed.Arg1);
        }
Example #2
0
        public void When_OperationWithArgs_PropertyValuesAreSet()
        {
            string[] args = new string[] { nameof(OperationWithSimpleProps), "Arg1=test", "Arg2=3", "Arg3=123.45" };

            IOperation[] operations = Executor.BuildOperations(args, typeof(ExecutorTests).Assembly, Options.Default);

            Assert.AreEqual(1, operations.Length);
            Assert.IsTrue(operations[0] is OperationWithSimpleProps);

            OperationWithSimpleProps Operation = (OperationWithSimpleProps)operations[0];

            Assert.AreEqual("test", Operation.Arg1);
            Assert.AreEqual(3, Operation.Arg2);
            Assert.AreEqual(123.45M, Operation.Arg3);
        }
Example #3
0
        public void When_OperationWithArgsInDifferentLocale_PropertyValuesAreSet()
        {
            string[] args = new string[] { nameof(OperationWithSimpleProps), "Arg1=test", "Arg2=3", "Arg3=123,45" };

            var formattingOptions = Options.Default;

            formattingOptions.Locale = new CultureInfo("pl-PL");

            IOperation[] operations = Executor.BuildOperations(args, typeof(ExecutorTests).Assembly, formattingOptions);

            Assert.AreEqual(1, operations.Length);
            Assert.IsTrue(operations[0] is OperationWithSimpleProps);

            OperationWithSimpleProps Operation = (OperationWithSimpleProps)operations[0];

            Assert.AreEqual("test", Operation.Arg1);
            Assert.AreEqual(3, Operation.Arg2);
            Assert.AreEqual(123.45M, Operation.Arg3);
        }