private string Invoke(string id, string[] args) { try { StepDefinition stepDefinition = GetStepDefinition(id); if (stepDefinition == null) { return(FailResponse("Could not find step with id '" + id + "'")); } if (stepDefinition.Pending) { return(PendingResponse()); } stepDefinition.Invoke(_objectFactory, args); return(SuccessResponse()); } catch (TargetInvocationException x) { if (x.InnerException is TableAssertionException) { var ex = (TableAssertionException)x.InnerException; return(TableDiffResponse(ex.Expected, ex.Actual)); } return(FailResponse(x.InnerException)); } }
public virtual Repository Load() { var repository = new Repository(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (IsDesiredAssembly(assembly)) { foreach (var type in assembly.GetTypes()) { foreach (var method in type.GetMethods(StepDefinition.MethodFlags)) { if (StepDefinition.IsValidMethod(method)) { repository.StepDefinitions.Add(new StepDefinition(method)); _objectFactory.AddClass(method.ReflectedType); } if (BeforeHook.IsValidMethod(method)) { repository.BeforeHooks.Add(new BeforeHook(method)); _objectFactory.AddClass(method.ReflectedType); } if (AfterHook.IsValidMethod(method)) { repository.AfterHooks.Add(new AfterHook(method)); _objectFactory.AddClass(method.ReflectedType); } } } } } return(repository); }
public virtual Repository Load() { var repository = new Repository(); foreach (var assemblyPath in _assemblyPaths) { var assembly = Assembly.LoadFrom(assemblyPath); foreach (var type in assembly.GetTypes()) { foreach (var method in type.GetMethods(StepDefinition.MethodFlags)) { if (StepDefinition.IsValidMethod(method)) { repository.StepDefinitions.Add(new StepDefinition(method)); _objectFactory.AddClass(method.ReflectedType); } if (BeforeHook.IsValidMethod(method)) { repository.BeforeHooks.Add(new BeforeHook(method)); _objectFactory.AddClass(method.ReflectedType); } if (AfterHook.IsValidMethod(method)) { repository.AfterHooks.Add(new AfterHook(method)); _objectFactory.AddClass(method.ReflectedType); } } } } return(repository); }
static void Write(JsonWriter writer, StepDefinition stepDefinition) { WriteObject(writer, () => { WriteProperty(writer, "id", stepDefinition.Id); WriteProperty(writer, "regexp", stepDefinition.Pattern); }); }
public void Id_property_should_be_fully_qualified_method_name_with_parameter_types() { var fullNameForParameterlessMethod = typeof(ValidStepDefinitions).FullName + "." + _stepDefinition.Method.Name + "()"; Assert.That(_stepDefinition.Id, Is.EqualTo(fullNameForParameterlessMethod)); var parameterizedStepDefinition = new StepDefinition(Reflection.GetMethod(typeof(ValidStepDefinitions), "WithArguments")); var fullNameForParameterizedMethod = typeof(ValidStepDefinitions).FullName + "." + parameterizedStepDefinition.Method.Name + "(Int32)"; Assert.That(parameterizedStepDefinition.Id, Is.EqualTo(fullNameForParameterizedMethod)); }
void AssertAllMethodsLoaded(Type type) { var expectedMethods = StepDefinition_Specification.GetStepDefinitionMethods(type); foreach (var method in expectedMethods) { var stepDefinition = new StepDefinition(method); Assert.That(_stepDefinitions, Has.Member(stepDefinition)); } }
public void Load(string assemblyPath) { Assembly asm = Assembly.LoadFrom(assemblyPath); foreach (Type type in asm.GetTypes()) { foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { object[] attributes = method.GetCustomAttributes(typeof(StepDefinitionAttribute), true); if (attributes.Length == 1) { StepDefinitionAttribute attribute = attributes[0] as StepDefinitionAttribute; StepDefinition sd = new StepDefinition(attribute.Pattern, method); this.AddStepDefinition(sd); } } } }
public void Method_that_throws_should_result_in_a_TargetInvocationException_being_thrown() { try { var stepDefinition = new StepDefinition(_exceptionMethod); stepDefinition.Invoke(); Assert.Fail("Expected exception to be thrown"); } catch (TargetInvocationException) { } }
public void Id_property_of_equivalent_step_definitions_should_be_equal() { var _equivalentStepDefinition = new StepDefinition(_successMethod); Assert.That(_equivalentStepDefinition.Id, Is.EqualTo(_stepDefinition.Id)); }
public void SetUp() { _successMethod = Reflection.GetMethod(typeof(ValidStepDefinitions), "Succeeds"); _exceptionMethod = Reflection.GetMethod(typeof(ValidStepDefinitions), "ThrowsException"); _stepDefinition = new StepDefinition(_successMethod); }
public void SetUp() { _stepDefinition = new StepDefinition(Reflection.GetMethod(GetType(), "CheckMethodCalled")); _exceptionDefinition = new StepDefinition(Reflection.GetMethod(GetType(), "ThrowsException")); _stepDefinitionWithOneStringParameter = new StepDefinition(GetType().GetMethod("OneStringParameter")); _stepDefinitionWithMultipleStringParameters = new StepDefinition(GetType().GetMethod("MultipleStringParameters", new Type[] { typeof(string), typeof(string) })); _stepDefinitionWithMultipleStringParametersOverloaded = new StepDefinition(GetType().GetMethod("MultipleStringParameters", new Type[] { typeof(string), typeof(string), typeof(string) })); _stepDefinitionWithOneIntParameter = new StepDefinition(GetType().GetMethod("OneIntParameter")); _stepDefinitionWithOneDoubleParameter = new StepDefinition(GetType().GetMethod("OneDoubleParameter")); _stepDefinitionWithIntDoubleAndStringParameters = new StepDefinition(GetType().GetMethod("IntDoubleAndStringParameters")); _pendingStepDefinition = new StepDefinition(GetType().GetMethod("Pending")); _stepDefinitionWithTableDiff = new StepDefinition(GetType().GetMethod("TableDiff")); _stepDefinitions = new List<StepDefinition> { _stepDefinition, _exceptionDefinition, _stepDefinitionWithOneStringParameter, _stepDefinitionWithMultipleStringParameters, _stepDefinitionWithMultipleStringParametersOverloaded, _stepDefinitionWithOneIntParameter, _stepDefinitionWithOneDoubleParameter, _stepDefinitionWithIntDoubleAndStringParameters, _pendingStepDefinition, _stepDefinitionWithTableDiff }; var loader = new MockLoader(_stepDefinitions); var objectFactory = new ObjectFactory(); _processor = new Processor(loader, objectFactory); _methodCalled = false; _receivedParameters = null; }
public void Method_that_throws_should_result_in_a_TargetInvocationException_being_thrown() { var stepDefinition = new StepDefinition(_exceptionMethod); stepDefinition.Invoke(null); }
public void Successful_invocation_of_instance_should_not_throw() { var objectFactory = new ObjectFactory(); objectFactory.AddClass(typeof(ValidStepDefinitions)); objectFactory.CreateObjects(); var stepDefinition = new StepDefinition(GetValidMethod("Instance")); stepDefinition.Invoke(objectFactory); }
public void SetUp() { _formatter = new Formatter(); _stepDefinition = CreateStepDefinition(); _stepDefinitions = new List<StepDefinition>(); }
public void SetUp() { _stepDefinition = new StepDefinition(Reflection.GetMethod(GetType(), "Method")); _exceptionDefinition = new StepDefinition(Reflection.GetMethod(GetType(), "ThrowsException")); _stepDefinitionWithOneStringParameter = new StepDefinition(GetType().GetMethod("OneStringParameter")); _stepDefinitionWithMultipleStringParameters = new StepDefinition(GetType().GetMethod("MultipleStringParameters", new Type[] { typeof(string), typeof(string) })); _stepDefinitionWithOneIntParameter = new StepDefinition(GetType().GetMethod("OneIntParameter")); _stepDefinitionWithOneDoubleParameter = new StepDefinition(GetType().GetMethod("OneDoubleParameter")); _stepDefinitionWithIntDoubleAndStringParameters = new StepDefinition(GetType().GetMethod("IntDoubleAndStringParameters")); _stepDefinitions = new List<StepDefinition> { _stepDefinition, _exceptionDefinition, _stepDefinitionWithOneStringParameter, _stepDefinitionWithMultipleStringParameters, _stepDefinitionWithOneIntParameter, _stepDefinitionWithOneDoubleParameter, _stepDefinitionWithIntDoubleAndStringParameters }; var loader = new MockLoader(_stepDefinitions); _processor = new Processor(loader); _methodCalled = false; _receivedParameters = null; }
public void Pending_should_be_false_when_method_does_not_have_Pending_attribute() { var stepDefinition = new StepDefinition(GetValidMethod("Given")); Assert.That(stepDefinition.Pending, Is.False); }
public void AddStepDefinition(StepDefinition stepDefinition) { _stepDefinitions.Add(stepDefinition); }
public void Pending_should_be_true_when_method_has_Pending_attribute() { var stepDefinition = new StepDefinition(GetValidMethod("Pending")); Assert.That(stepDefinition.Pending, Is.True); }
public void SetUp() { _stepDefinition = new StepDefinition(Reflection.GetMethod(GetType(), "Method")); _exceptionDefinition = new StepDefinition(Reflection.GetMethod(GetType(), "ThrowsException")); _stepDefinitions = new List<StepDefinition> { _stepDefinition, _exceptionDefinition }; var loader = new MockLoader(_stepDefinitions); _processor = new Processor(loader); _methodCalled = false; }
public string Format(StepDefinition stepDefinition) { return Format(writer => Write(writer, stepDefinition)); }