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"));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        private void BuildStepTransformationFromMethod(MethodInfo method, StepArgumentTransformationAttribute argumentTransformationAttribute)
        {
            StepTransformationBinding stepTransformationBinding = new StepTransformationBinding(argumentTransformationAttribute.Regex, method);

            stepTransformations.Add(stepTransformationBinding);
        }