/// <summary> /// Executes the test method. Creates a new instance of the class /// under tests and passes it to the inner command. Also catches /// any exceptions and converts them into <see cref="FailedResult"/>s. /// </summary> /// <param name="testClass">The instance of the test class</param> /// <returns>Returns information about the test run</returns> public override MethodResult Execute(object testClass) { try { if (testClass == null) { testClass = method.CreateInstance(); } } catch (TargetInvocationException ex) { ExceptionUtility.RethrowWithNoStackTraceLoss(ex.InnerException); } try { return(InnerCommand.Execute(testClass)); } finally { IDisposable disposable = testClass as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method) { try { object obj = method.CreateInstance(); 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 object CreateInstance() { return(_originalMethodInfo.CreateInstance()); }
public object CreateInstance() { return(_method.CreateInstance()); }
/// <summary> /// Obtains all test commands to call all examples contained in a given <see cref="T:IMethodInfo"/>. /// </summary> /// <param name="method">The method to scan.</param> /// <returns>All test commands to call all examples contained in <paramref name="method"/>.</returns> internal static IEnumerable<ITestCommand> CreateForMethod(IMethodInfo method) { //create a new instance of our specification var instance = method.CreateInstance() as nspec; if (instance == null) //not a nspec instance, nothing for us here. { return Enumerable.Empty<ITestCommand>(); } var context = new MethodContext(method.MethodInfo); context.Build(instance); var commands = new List<ITestCommand>(); BuildCommandList(method, instance, context, commands); return commands; }
private static object GetReturnValue(IMethodInfo method) { if (method.Class.IsAbstract && method.Class.IsSealed) return method.MethodInfo.Invoke(null, null); return method.MethodInfo.Invoke(method.CreateInstance(), null); }