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); }
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); }
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); } }
private Exception Invoke(object testClass, TypeDefinition type) { try { _method.Invoke(testClass, type); return(null); } catch (Exception e) { return(e); } }
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) }; } }
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; } } }
public void Invoke(object testClass, params object[] parameters) { _originalMethodInfo.Invoke(testClass, parameters); }
public object Invoke(object fixture, params object[] args) { return(_baseInfo.Invoke(fixture, args)); }
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)); }