public static IEnumerable<ITestCommand> ExtractCommands( MethodCall methodCall, IEnumerable<ITestCommand> commands, object continueOnFailureStepType) { Guard.AgainstNullArgument("methodCall", methodCall); Guard.AgainstNullArgument("commands", commands); try { try { var feature = methodCall.Method.IsStatic ? null : methodCall.Method.CreateInstance(); foreach (var command in commands) { var result = command.Execute(feature); if ((result as PassedResult) == null) { return new ITestCommand[] { new ReplayCommand(methodCall.Method, result) }; } } } catch (Exception ex) { return new ITestCommand[] { new ExceptionCommand(methodCall, ex) }; } var contexts = new ContextFactory().CreateContexts(methodCall, Steps).ToArray(); return contexts.SelectMany((context, index) => context.CreateCommands(index + 1, continueOnFailureStepType)); } finally { steps = null; } }
public Context(MethodCall methodCall, IEnumerable<Step> steps) { Guard.AgainstNullArgument("steps", steps); this.methodCall = methodCall; this.steps = steps.ToArray(); }
// TODO (adamralph): provide overload with out stepBeginsContinueOnFailure public StepCommand(MethodCall methodCall, int contextOrdinal, int stepOrdinal, Step step, bool stepBeginsContinueOnFailure) : base(methodCall, contextOrdinal, stepOrdinal) { Guard.AgainstNullArgument("methodCall", methodCall); Guard.AgainstNullArgument("step", step); if (step.Name == null) { throw new ArgumentException("The step name is null.", "step"); } this.step = step; this.stepBeginsContinueOnFailure = stepBeginsContinueOnFailure; var provider = CultureInfo.InvariantCulture; string stepName; try { stepName = string.Format(provider, step.Name, methodCall.Arguments.Select(argument => argument.Value ?? "null").ToArray()); } catch (FormatException) { stepName = step.Name; } this.Name = string.Format(provider, "{0} {1}", this.Name, stepName); this.DisplayName = string.Format(CultureInfo.InvariantCulture, "{0} {1}", this.DisplayName, stepName); }
public IEnumerable<Context> CreateContexts(MethodCall methodCall, IEnumerable<Step> steps) { Guard.AgainstNullArgument("steps", steps); var sharedContext = new List<Step>(); var pendingYield = false; foreach (var step in steps) { if (step.InIsolation) { yield return new Context(methodCall, sharedContext.Concat(new[] { step })); pendingYield = false; } else { sharedContext.Add(step); pendingYield = true; } } if (pendingYield) { yield return new Context(methodCall, sharedContext); } }
public TeardownCommand(MethodCall methodCall, int contextOrdinal, int stepOrdinal, IEnumerable<Action> teardowns) : base(methodCall, contextOrdinal, stepOrdinal) { Guard.AgainstNullArgument("teardowns", teardowns); this.teardowns = teardowns.ToArray(); this.Name = string.Format(CultureInfo.InvariantCulture, "{0} {1}", this.Name, "(Teardown)"); this.DisplayName = string.Format(CultureInfo.InvariantCulture, "{0} {1}", this.DisplayName, "(Teardown)"); }
public Command(MethodCall methodCall) : base(methodCall == null ? null : methodCall.Method, null, methodCall == null ? 0 : MethodUtility.GetTimeoutParameter(methodCall.Method)) { Guard.AgainstNullArgument("methodCall", methodCall); this.methodCall = methodCall; this.arguments = methodCall.Arguments.ToArray(); this.DisplayName = GetString(methodCall.Method, this.arguments, methodCall.TypeArguments.ToArray()); }
protected ContextCommand(MethodCall methodCall, int contextOrdinal, int commandOrdinal) : base(methodCall) { var provider = CultureInfo.InvariantCulture; this.Name = string.Format( provider, "[{0}.{1}.{2}]", methodCall.Ordinal.ToString("D2", provider), contextOrdinal.ToString("D2", provider), commandOrdinal.ToString("D2", provider)); this.DisplayName = string.Format(provider, "{0} {1}", this.DisplayName, this.Name); }
protected ContextCommand(MethodCall methodCall, int contextOrdinal, int commandOrdinal, bool omitArgumentsFromScenarioNames) : base(methodCall, omitArgumentsFromScenarioNames) { Guard.AgainstNullArgument("methodCall", methodCall); var provider = CultureInfo.InvariantCulture; this.Name = string.Format( provider, "[{0}.{1}.{2}]", methodCall.Ordinal.ToString("D2", provider), contextOrdinal.ToString("D2", provider), commandOrdinal.ToString("D2", provider)); this.DisplayName = string.Format(provider, "{0} {1}", this.DisplayName, this.Name); }
/// <summary> /// Enumerates the commands representing the scenarios defined by the <paramref name="method"/>. /// </summary> /// <param name="method">The scenario method.</param> /// <returns>An instance of <see cref="IEnumerable{ITestCommand}"/> representing the scenarios defined by the <paramref name="method"/>.</returns> /// <remarks>This method may be overridden.</remarks> protected virtual IEnumerable<ICommand> EnumerateScenarioCommands(IMethodInfo method) { Guard.AgainstNullArgument("method", method); Guard.AgainstNullArgumentProperty("method", "MethodInfo", method.MethodInfo); var parameters = method.MethodInfo.GetParameters(); if (!parameters.Any()) { return new[] { new Command(new MethodCall(method)) }; } var commands = new List<ICommand>(); var ordinal = 0; foreach (var arguments in GetArgumentCollections(method.MethodInfo)) { var closedTypeMethod = method; Type[] typeArguments = null; if (method.MethodInfo != null && method.MethodInfo.IsGenericMethodDefinition) { typeArguments = ResolveTypeArguments(method, arguments).ToArray(); closedTypeMethod = Reflector.Wrap(method.MethodInfo.MakeGenericMethod(typeArguments)); } var generatedArguments = new List<Argument>(); for (var missingArgumentIndex = arguments.Length; missingArgumentIndex < parameters.Length; ++missingArgumentIndex) { var parameterType = parameters[missingArgumentIndex].ParameterType; if (parameterType.IsGenericParameter) { Type concreteType = null; var typeParameters = method.MethodInfo.GetGenericArguments(); for (var typeParameterIndex = 0; typeParameterIndex < typeParameters.Length; ++typeParameterIndex) { if (typeParameters[typeParameterIndex] == parameterType) { concreteType = typeArguments[typeParameterIndex]; break; } } if (concreteType == null) { var message = string.Format( CultureInfo.CurrentCulture, "The type of parameter \"{0}\" cannot be resolved.", parameters[missingArgumentIndex].Name); throw new InvalidOperationException(message); } parameterType = concreteType; } generatedArguments.Add(new Argument(parameterType)); } var methodCall = new MethodCall(closedTypeMethod, arguments.Concat(generatedArguments).ToArray(), typeArguments, ++ordinal); commands.Add(new Command(methodCall)); } return commands; }
public ExceptionCommand(MethodCall methodCall, Exception exception) : base(methodCall) { this.exception = exception; }
public Command(MethodCall methodCall) : this(methodCall, false) { }
public ExceptionCommand(MethodCall methodCall, Exception exception, bool omitArgumentsFromScenarioNames) : base(methodCall, omitArgumentsFromScenarioNames) { this.exception = exception; }
public ExceptionCommand(MethodCall methodCall, Exception exception) : this(methodCall, exception, false) { }