-
Notifications
You must be signed in to change notification settings - Fork 746
Allow RangeAttribute to be specified multiple times for the same argument #2469
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
Comments
As a workaround, you could use a I am going to mark as an idea for discussion. I can see your use-case and it is valid, but there are alternatives and I suspect the feature would be used so little that the added complexity to the code and potential for bugs would outweigh its usefulness. We also need to look at the |
@rprouse It may not be all that complicated.
OTOH, there would be no harm in allowing multiple instances of Another easy way out would be to stop deriving The key issue is whether multiple parameter data sources can be used on a single parameter, with NUnit combining the values from each source into a single list. The answer is "yes" - we already do that. I'd call this an easyfix and suggest sombody should just try one of the above approaches. |
@CharliePoole sounds good, thanks for looking at the code. I am going to switch this to easy-fix 'hoping' that it is. If anyone picks this up, please discuss if it becomes more difficult than expected. |
I'd like to tackle this one. |
Previously, `RangeAttribute` derived from `ValuesAttribute`. However, there are certain use cases which apply to the `RangeAttribute`, but not to the `ValuesAttribute`. For example, we may want specify multiple, distinct ranges for a parameter by adding the `RangeAttribute` multiple times, but there isn't really a corresponding use case for the values attribute. We could just specify all the desired values in on attribute. This change updates the `RangeAttribute` to no longer derive from the `ValuesAttribute`. Instead, it now derives from `DataAttribute` and implements `IParameterDataSource`. The `IParameterDataSource.GetData` method has been implemented in `RangeAttribute` to preserve the behavior of that method in the `ValuesAttribute`. However, certain cases that could not be hit in the `RangeAttribute` (e.g. when the internal data was non-numeric) were removed. Fixes nunit#2469
Previously, `RangeAttribute` derived from `ValuesAttribute`. However, there are certain use cases which apply to the `RangeAttribute`, but not to the `ValuesAttribute`. For example, we may want specify multiple, distinct ranges for a parameter by adding the `RangeAttribute` multiple times, but there isn't really a corresponding use case for the values attribute. We could just specify all the desired values in on attribute. This change updates the `RangeAttribute` to no longer derive from the `ValuesAttribute`. Instead, it now derives from `DataAttribute` and implements `IParameterDataSource`. The `IParameterDataSource.GetData` method has been implemented in `RangeAttribute` to preserve the behavior of that method in the `ValuesAttribute`. However, certain cases that could not be hit in the `RangeAttribute` (e.g. when the internal data was non-numeric) were removed. Fixes nunit#2469
The RangeAttribute (e.g. [Range(0, 20)]) is a way to define the value range to test for in a theory, but it's restricted to occur only once per parameter of the test method.
Sometimes the same test code should be tested for different intervals.
Therefore it would be good to allow multiple ranges to be specified for the same parameter:
The text was updated successfully, but these errors were encountered: