From d7daf9fcb972d777afd3da4b267de218501b2ff4 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Tue, 29 Sep 2020 11:14:43 +0200 Subject: [PATCH 1/5] Make sure NullValidationService is always suspended --- src/Radical.Windows/Validation/NullValidationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Radical.Windows/Validation/NullValidationService.cs b/src/Radical.Windows/Validation/NullValidationService.cs index 1df39d0d..e43d42cb 100644 --- a/src/Radical.Windows/Validation/NullValidationService.cs +++ b/src/Radical.Windows/Validation/NullValidationService.cs @@ -20,7 +20,7 @@ public sealed class NullValidationService : AbstractValidationService private NullValidationService() : base() { - + SuspendValidation(); } private static readonly ValidationError[] emptyErrors = new ValidationError[0]; From e245902ff864237e12c3ee04879490575a235a8e Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Tue, 29 Sep 2020 11:15:13 +0200 Subject: [PATCH 2/5] Always enable validation by default --- .../Presentation/AbstractMementoViewModel.cs | 9 +++------ src/Radical.Windows/Presentation/AbstractViewModel.cs | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs b/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs index d433818d..43d64f71 100644 --- a/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs +++ b/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs @@ -19,7 +19,8 @@ namespace Radical.Windows.Presentation /// public abstract class AbstractMementoViewModel : MementoEntity, - IViewModel + IViewModel, + IRequireValidation { /// /// Gets or sets the view. The view property is intended only for @@ -76,11 +77,7 @@ protected virtual bool SkipPropertyValidation(string propertyName) [SkipPropertyValidation] protected virtual bool IsValidationEnabled { - get - { - return this is INotifyDataErrorInfo - || this is IRequireValidation; - } + get{ return true; } } IValidationService _validationService; diff --git a/src/Radical.Windows/Presentation/AbstractViewModel.cs b/src/Radical.Windows/Presentation/AbstractViewModel.cs index 884148ac..45b73299 100644 --- a/src/Radical.Windows/Presentation/AbstractViewModel.cs +++ b/src/Radical.Windows/Presentation/AbstractViewModel.cs @@ -19,7 +19,8 @@ namespace Radical.Windows.Presentation public abstract class AbstractViewModel : Entity, IViewModel, - ISupportInitialize + ISupportInitialize, + IRequireValidation { /// /// Gets or sets the view. The view property is intended only for @@ -76,11 +77,7 @@ protected virtual bool SkipPropertyValidation(string propertyName) [SkipPropertyValidation] protected virtual bool IsValidationEnabled { - get - { - return this is INotifyDataErrorInfo - || this is IRequireValidation; - } + get{ return true; } } IValidationService _validationService; From bfc5c181498059b30793343689e84b24258c4d73 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Tue, 29 Sep 2020 11:21:55 +0200 Subject: [PATCH 3/5] Use Array.Empty --- .../Presentation/AbstractMementoViewModel.cs | 4 ++-- src/Radical.Windows/Presentation/AbstractViewModel.cs | 4 ++-- src/Radical.Windows/Validation/AbstractValidationService.cs | 6 +++--- src/Radical.Windows/Validation/NullValidationService.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs b/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs index 43d64f71..c02b534d 100644 --- a/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs +++ b/src/Radical.Windows/Presentation/AbstractMementoViewModel.cs @@ -129,7 +129,7 @@ protected string GetPropertyDisplayName(string propertyName) /// protected virtual (bool IsValid, IEnumerable Errors) ValidateProperty(string propertyName, ValidationBehavior behavior) { - (bool IsValid, IEnumerable Errors) validationResult = (true, new ValidationError[0]); + (bool IsValid, IEnumerable Errors) validationResult = (true, Array.Empty()); if (ValidationService.IsValidationSuspended) { return validationResult; @@ -202,7 +202,7 @@ protected virtual (bool IsValid, IEnumerable Errors) ValidatePr { if (ValidationService.IsValidationSuspended) { - return (true, new ValidationError[0]); + return (true, Array.Empty()); } var wasValid = IsValid; diff --git a/src/Radical.Windows/Presentation/AbstractViewModel.cs b/src/Radical.Windows/Presentation/AbstractViewModel.cs index 45b73299..53d9da78 100644 --- a/src/Radical.Windows/Presentation/AbstractViewModel.cs +++ b/src/Radical.Windows/Presentation/AbstractViewModel.cs @@ -126,7 +126,7 @@ protected string GetPropertyDisplayName(string propertyName) /// protected virtual (bool IsValid, IEnumerable Errors) ValidateProperty(string propertyName, ValidationBehavior behavior) { - (bool IsValid, IEnumerable Errors) validationResult = (true, new ValidationError[0]); + (bool IsValid, IEnumerable Errors) validationResult = (true, Array.Empty()); if (ValidationService.IsValidationSuspended) { return validationResult; @@ -220,7 +220,7 @@ public virtual (bool IsValid, IEnumerable Errors) Validate(Vali { if (ValidationService.IsValidationSuspended) { - return (true, new ValidationError[0]); + return (true, Array.Empty()); } var wasValid = IsValid; diff --git a/src/Radical.Windows/Validation/AbstractValidationService.cs b/src/Radical.Windows/Validation/AbstractValidationService.cs index e45451f8..a1cb82fc 100644 --- a/src/Radical.Windows/Validation/AbstractValidationService.cs +++ b/src/Radical.Windows/Validation/AbstractValidationService.cs @@ -23,7 +23,7 @@ public abstract class AbstractValidationService : IValidationService { if (IsValidationSuspended) { - return (true, new ValidationError[0]); + return (true, Array.Empty()); } var results = OnValidateProperty(propertyName); @@ -41,7 +41,7 @@ protected virtual IEnumerable OnValidateProperty(string propert { if (IsValidationSuspended) { - return new ValidationError[0]; + return Array.Empty(); } /* @@ -64,7 +64,7 @@ protected virtual IEnumerable OnValidateProperty(string propert { if (IsValidationSuspended) { - return (true, new ValidationError[0]); + return (true, Array.Empty()); } //var wasValidBeforeValidation = IsValid; diff --git a/src/Radical.Windows/Validation/NullValidationService.cs b/src/Radical.Windows/Validation/NullValidationService.cs index e43d42cb..d8405679 100644 --- a/src/Radical.Windows/Validation/NullValidationService.cs +++ b/src/Radical.Windows/Validation/NullValidationService.cs @@ -23,7 +23,7 @@ private NullValidationService() SuspendValidation(); } - private static readonly ValidationError[] emptyErrors = new ValidationError[0]; + private static readonly ValidationError[] emptyErrors = System.Array.Empty(); /// /// Called in order to execute the concrete validation process. From 83565510b4726132ba3ae1d91c26efffec3195da Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Tue, 29 Sep 2020 11:31:58 +0200 Subject: [PATCH 4/5] Public API --- .../API/APIApprovals.Approve_API.approved.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Radical.Windows.Tests/API/APIApprovals.Approve_API.approved.txt b/src/Radical.Windows.Tests/API/APIApprovals.Approve_API.approved.txt index a1caa4d8..50306080 100644 --- a/src/Radical.Windows.Tests/API/APIApprovals.Approve_API.approved.txt +++ b/src/Radical.Windows.Tests/API/APIApprovals.Approve_API.approved.txt @@ -3312,7 +3312,7 @@ namespace Radical.Windows.Model } namespace Radical.Windows.Presentation { - public abstract class AbstractMementoViewModel : Radical.Model.MementoEntity, Radical.Windows.ComponentModel.IViewModel, System.ComponentModel.INotifyPropertyChanged + public abstract class AbstractMementoViewModel : Radical.Model.MementoEntity, Radical.Windows.ComponentModel.IRequireValidation, Radical.Windows.ComponentModel.IViewModel, System.ComponentModel.INotifyDataErrorInfo, System.ComponentModel.INotifyPropertyChanged { protected AbstractMementoViewModel() { } protected AbstractMementoViewModel(Radical.ComponentModel.ChangeTracking.ChangeTrackingRegistration registration) { } @@ -3376,7 +3376,7 @@ namespace Radical.Windows.Presentation "Errors"})] protected virtual System.ValueTuple> ValidateProperty(string propertyName, Radical.Windows.ComponentModel.ValidationBehavior behavior) { } } - public abstract class AbstractViewModel : Radical.Model.Entity, Radical.Windows.ComponentModel.IViewModel, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.ISupportInitialize + public abstract class AbstractViewModel : Radical.Model.Entity, Radical.Windows.ComponentModel.IRequireValidation, Radical.Windows.ComponentModel.IViewModel, System.ComponentModel.INotifyDataErrorInfo, System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.ISupportInitialize { protected AbstractViewModel() { } protected Radical.Windows.ComponentModel.ValidationBehavior DefaultValidationBehavior { get; set; } From 0c9720eb342dd7a7fcf94fe7ed2997913a4e596d Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Tue, 29 Sep 2020 11:32:17 +0200 Subject: [PATCH 5/5] force disable validation on tests --- .../Presentation/AbstractMementoViewModelTests.cs | 2 +- .../Presentation/AbstractViewModelTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Radical.Windows.Tests/Presentation/AbstractMementoViewModelTests.cs b/src/Radical.Windows.Tests/Presentation/AbstractMementoViewModelTests.cs index 88666a11..8c99a426 100644 --- a/src/Radical.Windows.Tests/Presentation/AbstractMementoViewModelTests.cs +++ b/src/Radical.Windows.Tests/Presentation/AbstractMementoViewModelTests.cs @@ -266,7 +266,7 @@ public void AbstractMementoViewModel_PropertyChanged_is_raised_GetErrors_should_ }; sut.ValidateUsing( - new DataAnnotationValidationService(sut)); + new DataAnnotationValidationService(sut), false); sut.NotNullNotEmpty = ""; Assert.IsNotNull(errors); diff --git a/src/Radical.Windows.Tests/Presentation/AbstractViewModelTests.cs b/src/Radical.Windows.Tests/Presentation/AbstractViewModelTests.cs index 082528ae..454171f3 100644 --- a/src/Radical.Windows.Tests/Presentation/AbstractViewModelTests.cs +++ b/src/Radical.Windows.Tests/Presentation/AbstractViewModelTests.cs @@ -200,7 +200,7 @@ public void AbstractViewModel_PropertyChanged_is_raised_GetErrors_should_contain }; sut.ValidateUsing( - new DataAnnotationValidationService(sut)); + new DataAnnotationValidationService(sut), false); sut.NotNullNotEmpty = ""; Assert.IsNotNull(errors);