private bool CanConvert(StepTransformationBinding stepTransformationBinding, object value, Type typeToConvertTo) { if (stepTransformationBinding.ReturnType != typeToConvertTo) return false; if (stepTransformationBinding.Regex != null && value is string) return stepTransformationBinding.Regex.IsMatch((string) value); return true; }
public void UserConverterShouldConvertStringToUser() { UserCreator stepTransformationInstance = new UserCreator(); var transformMethod = stepTransformationInstance.GetType().GetMethod("Create"); StepTransformationBinding stepTransformationBinding = new StepTransformationBinding(@"user (\w+)", transformMethod); Assert.True(stepTransformationBinding.Regex.IsMatch("user xyz")); var result = stepTransformationBinding.BindingAction.DynamicInvoke("xyz"); Assert.NotNull(result); Assert.That(result.GetType(), Is.EqualTo(typeof(User))); Assert.That(((User)result).Name, Is.EqualTo("xyz")); }
private bool CanConvert(StepTransformationBinding stepTransformationBinding, object value, Type typeToConvertTo) { if (stepTransformationBinding.ReturnType != typeToConvertTo) { return(false); } if (stepTransformationBinding.Regex != null && value is string) { return(stepTransformationBinding.Regex.IsMatch((string)value)); } return(true); }
private void BuildStepTransformationFromMethod(MethodInfo method, StepArgumentTransformationAttribute argumentTransformationAttribute) { StepTransformationBinding stepTransformationBinding = new StepTransformationBinding(argumentTransformationAttribute.Regex, method); stepTransformations.Add(stepTransformationBinding); }