Skip to content
Merged
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
fix #881
  • Loading branch information
alvaro-rivoir authored and Sergio0694 committed Aug 9, 2024
commit a2daea9d1a085452c79f7e9628911b04603d606d
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected ObservableValidator(ValidationContext validationContext)
}

/// <inheritdoc/>
[Display(AutoGenerateField = false)]
public bool HasErrors => this.totalErrors > 0;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,20 @@ public void Test_ObservableValidator_ValidateAllProperties_IncludeInheritedPrope
Assert.IsFalse(model.HasErrors);
Assert.IsTrue(events.Count == 1);

Assert.IsTrue(events.Any(e => e.PropertyName == nameof(DerivedModelWithValidatableProperties.Name))); }
Assert.IsTrue(events.Any(e => e.PropertyName == nameof(DerivedModelWithValidatableProperties.Name)));
}

// See https://github.com/CommunityToolkit/dotnet/issues/881
[TestMethod]
public void Test_ObservableValidator_HasErrors_IncludeNonAutogenerateAttribute()
{
DerivedModelWithValidatableProperties model = new();

DisplayAttribute? displayAttribute = model.GetType().GetProperty(nameof(ObservableValidator.HasErrors))?.GetCustomAttribute<DisplayAttribute>();

Assert.IsNotNull(displayAttribute);
Assert.IsFalse(displayAttribute.AutoGenerateField);
}

public class Person : ObservableValidator
{
Expand Down