Пример #1
0
        public void CanCreateInstanceReturningSpecificType()
        {
            var type = new ReflectionType("Utility.Test.TestType");
              TestType result = type.CreateObject<TestType>();

              Assert.That(result, Is.InstanceOf<TestType>());
        }
Пример #2
0
        public void CanCreateInstanceReturningSpecificType()
        {
            var      type   = new ReflectionType("Utility.Test.TestType");
            TestType result = type.CreateObject <TestType>();

            Assert.That(result, Is.InstanceOf <TestType>());
        }
Пример #3
0
        public void CanCreateInstanceWith2Parameters()
        {
            var type = new ReflectionType("Utility.Test.TestType");
              var result = type.CreateObject("Parameter1", "Parameter2");

              Assert.IsInstanceOf(typeof(TestType), result);
              Assert.AreEqual("Parameter1", ((TestType)result).P1);
              Assert.AreEqual("Parameter2", ((TestType)result).P2);
        }
Пример #4
0
        public void CanCreateInstanceWith0Parameters()
        {
            var type = new ReflectionType("Utility.Test.TestType");
              var result = type.CreateObject();

              Assert.IsInstanceOf(typeof(TestType), result);
              Assert.IsNull(((TestType)result).P1);
              Assert.IsNull(((TestType)result).P2);
        }
Пример #5
0
        public void CanCreateInstanceWith2Parameters()
        {
            var type   = new ReflectionType("Utility.Test.TestType");
            var result = type.CreateObject("Parameter1", "Parameter2");

            Assert.IsInstanceOf(typeof(TestType), result);
            Assert.AreEqual("Parameter1", ((TestType)result).P1);
            Assert.AreEqual("Parameter2", ((TestType)result).P2);
        }
Пример #6
0
        public void CanCreateInstanceWith0Parameters()
        {
            var type   = new ReflectionType("Utility.Test.TestType");
            var result = type.CreateObject();

            Assert.IsInstanceOf(typeof(TestType), result);
            Assert.IsNull(((TestType)result).P1);
            Assert.IsNull(((TestType)result).P2);
        }
Пример #7
0
        public void Run(IDbConnectionInfo connectionInfo)
        {
            if (ScriptType != ScriptType.Runnable)
            {
                throw new ArgumentException(string.Format("ScriptType is not runnable : {0}", ScriptType), "ScriptType");
            }

            try
            {
                var rType     = new ReflectionType(ScriptValue);
                var runMethod = rType.CreateType().GetMethod("Run");
                if (runMethod == null)
                {
                    throw new ArgumentException(string.Format("Could not find a method named 'Run' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                }
                if (runMethod.ReturnType != typeof(void))
                {
                    throw new ArgumentException(string.Format("Run method does not have return type 'void' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                }
                var parameters = runMethod.GetParameters();
                if (parameters.Length != 1 || parameters[0].ParameterType != typeof(IDbConnectionInfo))
                {
                    throw new ArgumentException(
                              string.Format("Run method does not have a single parameter of type 'IDbConnectionInfo' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                }

                runMethod.Invoke(rType.CreateObject(), BindingFlags.InvokeMethod, null, new object[] { connectionInfo }, null);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(ArgumentException))
                {
                    throw;
                }
                throw new ArgumentException(string.Format("ScriptValue could not be run : {0} : {1} : {2}", ScriptValue, e.GetType(), e.Message), "ScriptValue", e);
            }
        }
Пример #8
0
        public void Run(IDbConnectionInfo connectionInfo)
        {
            if (ScriptType != ScriptType.Runnable) throw new ArgumentException(string.Format("ScriptType is not runnable : {0}", ScriptType), "ScriptType");

            try
            {
                var rType = new ReflectionType(ScriptValue);
                var runMethod = rType.CreateType().GetMethod("Run");
                if (runMethod == null)
                    throw new ArgumentException(string.Format("Could not find a method named 'Run' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                if (runMethod.ReturnType != typeof (void))
                    throw new ArgumentException(string.Format("Run method does not have return type 'void' for ScriptValue : {0}", ScriptValue), "ScriptValue");
                var parameters = runMethod.GetParameters();
                if (parameters.Length != 1 || parameters[0].ParameterType != typeof (IDbConnectionInfo))
                    throw new ArgumentException(
                        string.Format("Run method does not have a single parameter of type 'IDbConnectionInfo' for ScriptValue : {0}", ScriptValue), "ScriptValue");

                runMethod.Invoke(rType.CreateObject(), BindingFlags.InvokeMethod, null, new object[] {connectionInfo}, null);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof (ArgumentException)) throw;
                throw new ArgumentException(string.Format("ScriptValue could not be run : {0} : {1} : {2}", ScriptValue, e.GetType(), e.Message), "ScriptValue", e);
            }
        }