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

Create duplicate invariant key validator #184

Merged
merged 6 commits into from
Sep 22, 2023

Conversation

mmsmits
Copy link
Member

@mmsmits mmsmits commented Aug 23, 2023

fixes #143

@mmsmits mmsmits requested a review from ewoutkramer August 23, 2023 14:51
@mmsmits mmsmits enabled auto-merge August 23, 2023 14:51
//this can be expanded with other validate functionality
evidence.AddRange(validateInvariantUniqueness(input, state));

return ResultReport.FromEvidence(evidence);
Copy link
Member

Choose a reason for hiding this comment

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

No need to create a list:

var evidence = validateInvariantUniqueness(input,state);
return ResultReport.FromEvidence(evidence);

If there are multiple steps in the future, you can just do

var evidence = validateInvariantUniqueness(input,state)
    .Concat(validateOtherInvariant(input,state));

.Distinct())) //Distinct to remove paths that are encountered multiple times per invariant
.Where(kv => kv.Paths.Count() > 1); //Remove entries that only have a single path. These are not incorrect.

return PathsPerDuplicateInvariantKey.Select(c => new IssueAssertion(Issue.PROFILE_ELEMENTDEF_INCORRECT, $"Duplicate key '{c.Key}' in paths: {string.Join(", ", c.Paths)}"));
Copy link
Member

Choose a reason for hiding this comment

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

I would, because in the end this enumeration will need to be fully evaluated, call ToList() on the end-result. This way, callers of our functions can never shoot themselves in the foot by enumerating this (expensive) LINQ statement multiple times by accident. Also, it makes the debugging more clear, since, if we don't do the ToList()), you will only get an exception deep inside the ResultReport.FromEvidence() (that's the function finally triggering the evaluation of the IEnumerable) - and you will have no clue what's going on!

@ewoutkramer
Copy link
Member

BTW: Nice LINQ query ;-)

@mmsmits mmsmits requested a review from ewoutkramer September 19, 2023 15:30
//this can be expanded with other validate functionality
evidence.AddRange(validateInvariantUniqueness(input, state));
var evidence = validateInvariantUniqueness(input, state).ToList();
Copy link
Member

Choose a reason for hiding this comment

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

Your new function already returns a list now, so, this should not be necessary anymore!

@mmsmits mmsmits requested a review from ewoutkramer September 21, 2023 11:12
@mmsmits mmsmits merged commit 71b9d61 into develop Sep 22, 2023
2 checks passed
@mmsmits mmsmits deleted the feature/143-validate-constraint-uniqueness branch September 22, 2023 12:16
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.

Validator: validate that no two constraints should have the same id
2 participants