示例#1
0
            public void TurnsTargetParameterCountExceptionIntoParameterCountMismatchException()
            {
                MethodInfo             method        = typeof(TestMethodCommandClass).GetMethod("ThrowsException");
                IMethodInfo            wrappedMethod = Reflector.Wrap(method);
                TestMethodCommandClass obj           = new TestMethodCommandClass();

                Exception ex = Record.Exception(() => wrappedMethod.Invoke(obj, "Hello world"));

                Assert.IsType <ParameterCountMismatchException>(ex);
            }
示例#2
0
            public void ThrowsTargetInvocationException()
            {
                MethodInfo             method        = typeof(TestMethodCommandClass).GetMethod("ThrowsTargetInvocationException");
                IMethodInfo            wrappedMethod = Reflector.Wrap(method);
                TestMethodCommandClass obj           = new TestMethodCommandClass();

                Exception ex = Record.Exception(() => wrappedMethod.Invoke(obj));

                Assert.IsType <TargetInvocationException>(ex);
            }
示例#3
0
        private static void RegisterSpecificationPrimitives(IMethodInfo method)
        {
            if (method.IsStatic)
            {
                method.Invoke(null, null);
            }
            else
            {
                ConstructorInfo defaultConstructor = method.MethodInfo.ReflectedType.GetConstructor(Type.EmptyTypes);

                if (defaultConstructor == null)
                {
                    throw new InvalidOperationException("Specification class does not have a default constructor");
                }

                object instance = defaultConstructor.Invoke(null);
                method.Invoke(instance, null);
            }
        }
示例#4
0
 private Exception Invoke(object testClass, TypeDefinition type)
 {
     try
     {
         _method.Invoke(testClass, type);
         return(null);
     }
     catch (Exception e)
     {
         return(e);
     }
 }
示例#5
0
 private Exception Invoke(object testClass, Tuple <MethodDefinition, Instruction, MethodReference> call)
 {
     try
     {
         _method.Invoke(testClass, call.Item1, call.Item2, call.Item3);
         return(null);
     }
     catch (Exception e)
     {
         return(e);
     }
 }
 protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
 {
     try
     {
         object obj = Activator.CreateInstance(method.MethodInfo.ReflectedType);
         method.Invoke(obj, null);
         return SpecificationContext.ToTestCommands(method);
     }
     catch (Exception ex)
     {
         return new ITestCommand[] { new ExceptionTestCommand(method, ex) };
     }
 }
示例#7
0
 protected override IEnumerable <ITestCommand> EnumerateTestCommands(IMethodInfo method)
 {
     try
     {
         object obj = Activator.CreateInstance(method.MethodInfo.ReflectedType);
         method.Invoke(obj, null);
         return(SpecificationContext.ToTestCommands(method));
     }
     catch (Exception ex)
     {
         return(new ITestCommand[] { new ExceptionTestCommand(method, ex) });
     }
 }
 protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
 {
     var specification = (Specification)method.CreateInstance();
     var builder = new ScenarioBuilder();
     specification.ScenarioBuilder = builder;
     method.Invoke(specification);
     foreach (var scenario in builder.GetScenarios())
     {
         foreach (var command in scenario.CreateTestCommands(method))
         {
             yield return command;
         }
     }
 }
示例#9
0
 public void Invoke(object testClass, params object[] parameters)
 {
     _originalMethodInfo.Invoke(testClass, parameters);
 }
示例#10
0
 public object Invoke(object fixture, params object[] args)
 {
     return(_baseInfo.Invoke(fixture, args));
 }
示例#11
0
 public void Invoke(object testClass, params object[] parameters)
 {
     _method.Invoke(testClass, parameters);
 }
 private static object InvokeMethod(IMethodInfo method, TestExecutionContext context)
 {
     return(method.Invoke(method.IsStatic ? null : context.TestObject, null));
 }