mercredi 17 juillet 2019

How to use REGEX in StepArgumentTransformation to find prefixed string

I want to use StepArgumentTransformation of SpecFlow to transform all strings prefixed with "key:" to something else. I don't get around on how to use the right regular expression.

Lets say I have the following step in my feature file:

Given a user is logged in with key:testkey and has password key:testpassword and username John

Which leads to this step definition:

[Given(@"a user is logged in with (.*) and has password (.*) and username (.*)")]
public void GivenUserIsLoggedIn(string key, string password, string username)
{
    // To stuff
}

Now I want to change the key values by using step argument transformation:

[StepArgumentTransformation(@"add correct regular expression here")]
public string TransformKeys(string value)
{
    // Do transformation
    return result;
}

I only want values prefixed with "key:" to enter the transformation method. How can I achieve this? I tried several stuff like

[StepArgumentTransformation(@"key:.*")
[StepArgumentTransformation(@"(key:.*)")
[StepArgumentTransformation(@"key:\w+")

But i either get error "parameter count mismatch" or the transformation method isn't entered at all.

Aucun commentaire:

Enregistrer un commentaire