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

Always on validation #318

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down Expand Up @@ -3376,7 +3376,7 @@ namespace Radical.Windows.Presentation
"Errors"})]
protected virtual System.ValueTuple<bool, System.Collections.Generic.IEnumerable<Radical.Validation.ValidationError>> 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void AbstractMementoViewModel_PropertyChanged_is_raised_GetErrors_should_
};

sut.ValidateUsing(
new DataAnnotationValidationService<SampleTestMementoViewModel>(sut));
new DataAnnotationValidationService<SampleTestMementoViewModel>(sut), false);
sut.NotNullNotEmpty = "";

Assert.IsNotNull(errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void AbstractViewModel_PropertyChanged_is_raised_GetErrors_should_contain
};

sut.ValidateUsing(
new DataAnnotationValidationService<SampleTestViewModel>(sut));
new DataAnnotationValidationService<SampleTestViewModel>(sut), false);
sut.NotNullNotEmpty = "";

Assert.IsNotNull(errors);
Expand Down
13 changes: 5 additions & 8 deletions src/Radical.Windows/Presentation/AbstractMementoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace Radical.Windows.Presentation
/// </summary>
public abstract class AbstractMementoViewModel :
MementoEntity,
IViewModel
IViewModel,
IRequireValidation
{
/// <summary>
/// Gets or sets the view. The view property is intended only for
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +129,7 @@ protected string GetPropertyDisplayName(string propertyName)
/// </returns>
protected virtual (bool IsValid, IEnumerable<ValidationError> Errors) ValidateProperty(string propertyName, ValidationBehavior behavior)
{
(bool IsValid, IEnumerable<ValidationError> Errors) validationResult = (true, new ValidationError[0]);
(bool IsValid, IEnumerable<ValidationError> Errors) validationResult = (true, Array.Empty<ValidationError>());
if (ValidationService.IsValidationSuspended)
{
return validationResult;
Expand Down Expand Up @@ -205,7 +202,7 @@ protected virtual (bool IsValid, IEnumerable<ValidationError> Errors) ValidatePr
{
if (ValidationService.IsValidationSuspended)
{
return (true, new ValidationError[0]);
return (true, Array.Empty<ValidationError>());
}

var wasValid = IsValid;
Expand Down
13 changes: 5 additions & 8 deletions src/Radical.Windows/Presentation/AbstractViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace Radical.Windows.Presentation
public abstract class AbstractViewModel :
Entity,
IViewModel,
ISupportInitialize
ISupportInitialize,
IRequireValidation
{
/// <summary>
/// Gets or sets the view. The view property is intended only for
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -129,7 +126,7 @@ protected string GetPropertyDisplayName(string propertyName)
/// </returns>
protected virtual (bool IsValid, IEnumerable<ValidationError> Errors) ValidateProperty(string propertyName, ValidationBehavior behavior)
{
(bool IsValid, IEnumerable<ValidationError> Errors) validationResult = (true, new ValidationError[0]);
(bool IsValid, IEnumerable<ValidationError> Errors) validationResult = (true, Array.Empty<ValidationError>());
if (ValidationService.IsValidationSuspended)
{
return validationResult;
Expand Down Expand Up @@ -223,7 +220,7 @@ public virtual (bool IsValid, IEnumerable<ValidationError> Errors) Validate(Vali
{
if (ValidationService.IsValidationSuspended)
{
return (true, new ValidationError[0]);
return (true, Array.Empty<ValidationError>());
}

var wasValid = IsValid;
Expand Down
6 changes: 3 additions & 3 deletions src/Radical.Windows/Validation/AbstractValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class AbstractValidationService : IValidationService
{
if (IsValidationSuspended)
{
return (true, new ValidationError[0]);
return (true, Array.Empty<ValidationError>());
}

var results = OnValidateProperty(propertyName);
Expand All @@ -41,7 +41,7 @@ protected virtual IEnumerable<ValidationError> OnValidateProperty(string propert
{
if (IsValidationSuspended)
{
return new ValidationError[0];
return Array.Empty<ValidationError>();
}

/*
Expand All @@ -64,7 +64,7 @@ protected virtual IEnumerable<ValidationError> OnValidateProperty(string propert
{
if (IsValidationSuspended)
{
return (true, new ValidationError[0]);
return (true, Array.Empty<ValidationError>());
}

//var wasValidBeforeValidation = IsValid;
Expand Down
4 changes: 2 additions & 2 deletions src/Radical.Windows/Validation/NullValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public sealed class NullValidationService : AbstractValidationService
private NullValidationService()
: base()
{

SuspendValidation();
}

private static readonly ValidationError[] emptyErrors = new ValidationError[0];
private static readonly ValidationError[] emptyErrors = System.Array.Empty<ValidationError>();

/// <summary>
/// Called in order to execute the concrete validation process.
Expand Down