Feature request: Mark validation errors on visual element #83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is not production ready, it is more a proof-of-concept for a feature request.
The feature request originates from my PR in the MaterialDesignInXaml project. See the last paragraph regarding the TODOs left in the UI tests.
Idea
When writing a unit test for a control in isolation (as opposed to a test for some UI using the control), it would be cool to be able to force a validation error in order to assert that some conditions are met when a validation error is present. Ideally this could be done using the XAMLTest library instead of having to wire up a real
ValidationRule
on a binding in the XAML under test, and also having to "force" the UI into a state where the validation error occurs. All that is - IMO - simply boiler-plate code that I would rather not write in my UI tests.Proposed solution
Extend the XAMLTest library with
MarkInvalid(DP, string)
,ClearInvalid(DP)
, andGetValidationErrorContent(DP)
which can be used to bring an element into an "error state" (i.e.Validation.HasError = true
), clear the "error state" from an element, and get the error content from an element respectively.I must admit I do not have years of experience with the built-in validation scheme, so there may be some quirks/drawbacks to this approach that I am missing.
I have added some tests as well to illustrate the potential use for this.