Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to convert type to same type or one of base types with StepArgumentTransformation #1110

Merged

Conversation

ChernyavskiyAlex
Copy link
Contributor

One of the key needs is to create keywords as "example" or "table" value and resolve it in runtime.
As example:
Suppose wit ha some scenario outline with example block like that:
Examples:
|date|
|#{uniq_id}|

and binding:
[StepArgumentTransformation]
public string KeywordTransformation(string value){
if (value == #{uniq_id})
return Guid.NewGuid.ToString();
}

as a result in test we get the transformed value.

@ChernyavskiyAlex ChernyavskiyAlex changed the title Allow to convert type to same type or one of base types with Allow to convert type to same type or one of base types with StepArgumentTransformation Apr 16, 2018
@SabotageAndi
Copy link
Contributor

@gasparnagy This is your PR to review.

Copy link
Contributor

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this generally, except the two smaller comment I made.


var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, false);
if (stepTransformation != null)
return true;

var convertToType = Type.GetType(typeToConvertTo.FullName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like above...

var stepTransformation = GetMatchingStepTransformation(value, typeToConvertTo, true);
if (stepTransformation != null)
return DoTransform(stepTransformation, value, cultureInfo);

var convertToType = Type.GetType(typeToConvertTo.FullName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using Type.GetType, please try to safely cast typeToConvertTo into RuntimeBindingType and if the cast is valid, get the runtime type from there.
(Type.GetType only works reliably if you pass an assembly-qualified type name to it.)

@ChernyavskiyAlex
Copy link
Contributor Author

Thanks, code by your remarks was added

@SabotageAndi
Copy link
Contributor

@ChernyavskiyAlex one small request from me: could you add an entry into the changelog? Thanks!

@SabotageAndi SabotageAndi added this to the SpecFlow 2.4/3.0 milestone Apr 18, 2018
@ChernyavskiyAlex
Copy link
Contributor Author

done

@ChernyavskiyAlex
Copy link
Contributor Author

@gasparnagy are you agree with changes i made?

@gasparnagy gasparnagy merged commit 6c3bfe8 into SpecFlowOSS:master Apr 28, 2018
@gasparnagy
Copy link
Contributor

@ChernyavskiyAlex Thx!

alexvv pushed a commit to alexvv/SpecFlow that referenced this pull request Apr 29, 2018
…mentTransformation (SpecFlowOSS#1110)

* Type to same or derived type conversion added

* Tests added

* Tests fixing

* Fixed by gasparnagy remartks

* Changelog updated
@ChernyavskiyAlex ChernyavskiyAlex deleted the transform_type_to_same_type branch July 31, 2018 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants