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

Feature/114 comparing two properties #131

Closed
wants to merge 38 commits into from

Conversation

paw3lx
Copy link
Collaborator

@paw3lx paw3lx commented Dec 2, 2017

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:

  1. To have many Ensure methods. They can look like in this PR
  2. Replace Ensure methods to have only one way of creating ValitRules. This could be big change I guess. As @GooRiOn said, it could piss off all folks that use Valit.

What do you think?

Changes

  • Added Ensure method to provide functionality of comparing two properties

GooRiOn and others added 30 commits November 20, 2017 10:53
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
Copy link

codecov bot commented Dec 2, 2017

Codecov Report

Merging #131 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           develop   #131   +/-   ##
======================================
  Coverage      100%   100%           
======================================
  Files           38     38           
  Lines          784    815   +31     
======================================
+ Hits           784    815   +31
Impacted Files Coverage Δ
src/Valit/ValitRuleUInt64Extensions.cs 100% <ø> (ø) ⬆️
src/Valit/ValitStrategies.cs 100% <ø> (ø) ⬆️
src/Valit/ValitException.cs 100% <ø> (ø) ⬆️
src/Valit/ValitRuleUInt32Extensions.cs 100% <ø> (ø) ⬆️
src/Valit/ValitRuleInt32Extensions.cs 100% <ø> (ø) ⬆️
src/Valit/CompleteValitStrategy.cs 100% <ø> (ø) ⬆️
src/Valit/MessageProvider/EmptyMessageProvider.cs 100% <ø> (ø) ⬆️
src/Valit/Exceptions/ValitExceptionExtensions.cs 100% <ø> (ø) ⬆️
src/Valit/ValitRuleDoubleExtensions.cs 100% <ø> (ø) ⬆️
src/Valit/ValitStrategiesExtensions.cs 100% <ø> (ø) ⬆️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb68fc0...1eb3bfb. Read the comment docs.

selector.ThrowIfNull();
ruleFunc.ThrowIfNull();

var lastEnsureRule = new ValitRule<TObject, TProperty>(selector, _messageProvider, ruleFunc);
Copy link
Member

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.

Copy link
Collaborator Author

@paw3lx paw3lx Dec 3, 2017

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.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, my bad :D

@GooRiOn
Copy link
Member

GooRiOn commented Dec 2, 2017

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).

Copy link
Collaborator

@timdeschryver timdeschryver left a 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?

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();
Copy link
Collaborator

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? 😄

Copy link
Collaborator Author

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.

Copy link
Collaborator

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...

IValitRules<TObject> For(TObject @object);
IEnumerable<IValitRule<TObject>> GetAllRules();
IEnumerable<IValitRule<TObject>> GetTaggedRules();
IEnumerable<IValitRule<TObject>> GetUntaggedRules();
Copy link
Collaborator

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 };
Copy link
Collaborator

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 };
Copy link
Collaborator

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 };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

IEnumerable<IValitRule<TObject>> IValitRule<TObject>.GetEnsureRules(TObject @object)
{
@object.ThrowIfNull();
if (_ruleFunc != null)
Copy link
Collaborator

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 ifs are harder to read imo, @GooRiOn thoughts?

if (_ruleFunc != null)
return _ruleFunc(this, @object).GetAllEnsureRules();

return new List<IValitRule<TObject>>{ this };
Copy link
Collaborator

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))
Copy link
Collaborator

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>
Copy link
Collaborator

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?

@paw3lx paw3lx closed this Dec 5, 2017
@paw3lx paw3lx deleted the feature/114 branch December 5, 2017 13:03
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.

3 participants