-
Notifications
You must be signed in to change notification settings - Fork 26
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
Feature/114 comparing two properties #131
Conversation
…Provider into Valitator
Issue 117: Altered ValitRuleError to support both a static string and a Func<string> - Updated ExtensionMethods to support both - Added tests to the new feature
Added Func as a suffix for the Func<string>
Set as string.Empty instead of null
Codecov Report
@@ Coverage Diff @@
## develop #131 +/- ##
======================================
Coverage 100% 100%
======================================
Files 38 38
Lines 784 815 +31
======================================
+ Hits 784 815 +31
Continue to review full report at Codecov.
|
selector.ThrowIfNull(); | ||
ruleFunc.ThrowIfNull(); | ||
|
||
var lastEnsureRule = new ValitRule<TObject, TProperty>(selector, _messageProvider, ruleFunc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should call AddEnsureRulesAccessors
here to get all rules from the chain. BTW this name is stupid :D We should change that to AddEnsureRules
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't call AddEnsureRuleAccessors
because it has different arguments. I did few changes to get all rules from the chain.
I cannot call ruleFunc()
to create ValitRule
, because we need @object
to do this. So basically we can do this when Valit
method is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my bad :D
I like this way of creating the rules. Now we need to decide what to do with that. @arekbal @dbarwikowski @tdeschryver what are your thoughts? We should not hurry with the decision, tommorow I'd like to release version 0.2.0 so this task will be scheduled for the 0.3.0 release (so before christmass). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I like the syntax which is introduced in this PR.
Just a couple remarks, @GooRiOn thoughts?
src/Valit/IValitRules.cs
Outdated
IValitRules<TObject> EnsureFor<TProperty>(Func<TObject, IEnumerable<TProperty>> selector, Func<IValitRule<TObject, TProperty>, IValitRule<TObject, TProperty>> ruleFunc); | ||
IValitRules<TObject> EnsureFor<TProperty>(Func<TObject, IEnumerable<TProperty>> selector, IValitRulesProvider<TProperty> valitRulesProvider) where TProperty : class; | ||
IValitRules<TObject> For(TObject @object); | ||
IEnumerable<IValitRule<TObject>> GetAllRules(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some extra whitespaces at the end of the line. (also an extra space for every property in this interface)
I don't know why, but I thought the .editorconfig
would fix these.
Can I ask which editor you're using? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visual Studio Code on macOS. I will take a look on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot this, but it seems I have this extension installed...
src/Valit/IValitRules.cs
Outdated
IValitRules<TObject> For(TObject @object); | ||
IEnumerable<IValitRule<TObject>> GetAllRules(); | ||
IEnumerable<IValitRule<TObject>> GetTaggedRules(); | ||
IEnumerable<IValitRule<TObject>> GetUntaggedRules(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
|
||
public IEnumerable<IValitRule<TObject>> GetEnsureRules(TObject @object) | ||
{ | ||
return new List<IValitRule<TObject>>{ this }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to initialize a List
here, we can do new []{ this };
.
Maybe also use a Expression-bodied member, since we're using it everywhere else?
@@ -52,5 +52,9 @@ IValitResult IValitRule<TObject>.Validate(TObject @object) | |||
return result; | |||
} | |||
|
|||
public IEnumerable<IValitRule<TObject>> GetEnsureRules(TObject @object) | |||
{ | |||
return new List<IValitRule<TObject>>{ this }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
|
||
public IEnumerable<IValitRule<TObject>> GetEnsureRules(TObject @object) | ||
{ | ||
return new List<IValitRule<TObject>>{ this }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/Valit/Rules/ValitRule.cs
Outdated
IEnumerable<IValitRule<TObject>> IValitRule<TObject>.GetEnsureRules(TObject @object) | ||
{ | ||
@object.ThrowIfNull(); | ||
if (_ruleFunc != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doens't change anything, but I think in the other places we're using an if
we're surrounding it with braces.
Personally I would also check if _ruleFunc
is null
instead of not null
, contradictory if
s are harder to read imo, @GooRiOn thoughts?
src/Valit/Rules/ValitRule.cs
Outdated
if (_ruleFunc != null) | ||
return _ruleFunc(this, @object).GetAllEnsureRules(); | ||
|
||
return new List<IValitRule<TObject>>{ this }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, no need to initialize a List
.
{ | ||
IValitResult result = ValitRules<Model> | ||
.Create() | ||
.Ensure(s => s.Value, (_, m) => _.IsEqualTo(m.Value).MinLength(3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check .MinLength(3)
here.
.For(@object) | ||
.Validate(); | ||
private IValitResult ValidatePropertyRules(IEnumerable<IValitRule<TObject>> propertyRules, TObject @object) | ||
=> ValitRules<TObject> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, these are tabs instead of spaces.
@GooRiOn Are you OK with checking these 'problems' during a PR?
Info
This Pull Request is related to issue no. #114
Guys, I added few lines of code to provide possibility to compare two properties. It's just a draft, so please take a look. I was not sure about it so I just added one Ensure method and one test to test if it's working.
I think that now we have two possibilities:
Ensure
methods. They can look like in this PREnsure
methods to have only one way of creatingValitRules
. This could be big change I guess. As @GooRiOn said, it could piss off all folks that use Valit.What do you think?
Changes
Ensure
method to provide functionality of comparing two properties