-
-
Notifications
You must be signed in to change notification settings - Fork 364
fix(ValidateForm): compatible with custom validation classes not end with Attribute #5752
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
Conversation
Reviewer's Guide by SourceryThis pull request improves the Updated class diagram for ValidateFormclassDiagram
class ValidateForm {
-LocalizerFactory: IStringLocalizerFactory
+ValidateForm()
+OnInitialized()
+OnParametersSet()
+ValidateModel(): bool
+Reset()
-ValidateDataAnnotations(object? value, ValidationContext context, List<ValidationResult> results, ValidationAttribute rule, string memberName, ReadOnlySpan<char> attributeSpan)
}
note for ValidateForm "Refactored ValidateDataAnnotations method to streamline error message localization and improve readability."
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Pull Request Overview
This PR fixes issue #5745 by enhancing the ValidateForm component to support custom validation classes that do not end with "Attribute". The changes include refactoring error message localization in the ValidateDataAnnotations method, adding a new test case, and introducing a custom validation rule.
- Refactored error message retrieval logic in ValidateForm.
- Added a new test method and custom validation rule in the unit tests.
- Changed the visibility of an error constant in a test attribute class.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/UnitTest/Components/ValidateFormTest.cs | Added tests for custom validation rules and updated constant visibility |
| src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs | Refactored error message localization logic to support custom validation classes |
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.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider extracting the validation logic into a separate class for better reusability.
- The changes to ValidateDataAnnotations look good, but could use a comment explaining the order in which the localizers are checked.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5752 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 657 657
Lines 29923 29926 +3
Branches 4245 4248 +3
=========================================
+ Hits 29923 29926 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #5745
Summary By Copilot
This pull request includes changes to the
ValidateFormcomponent and its unit tests in order to improve validation logic and add new test coverage. The most important changes include refactoring theValidateDataAnnotationsmethod, adding a new test method, and introducing a custom validation rule.Improvements to validation logic:
src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs: Refactored theValidateDataAnnotationsmethod to streamline error message localization and improve readability. [1] [2]Enhancements to unit tests:
test/UnitTest/Components/ValidateFormTest.cs: Added a new test methodTestService_Okto verify custom validation rules without using the conventionalAttributesuffix.test/UnitTest/Components/ValidateFormTest.cs: Introduced a new private classTestValidateRulefor custom validation logic and updated theHasServiceclass to include a property using this new rule.Code cleanup:
test/UnitTest/Components/ValidateFormTest.cs: Changed the visibility of theErrorconstant in theHasServiceAttributeclass frompublictoprivate.Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Improve validation logic in ValidateForm to support custom validation classes that do not end with 'Attribute'
Bug Fixes:
Enhancements:
Tests:
Chores: