Validation fails while ignoring class types.
See original GitHub issueThe following unittest I created, shows the bug I found. While having two list to compare with different object types in it, the validation fails when the ClassTypesToIgnore are having different ID’s.
If you copy the code below to ConfigTests.cs and run it you will see that the validation fails. But when you give both the Officers the same ID the test will succeed. (Please note that the officers names are also different.)
What do you think of it?
[Test]
public void ClassTypeInListIgnorePositive()
{
var comparisonConfig = new ComparisonConfig()
{
MaxDifferences = int.MaxValue,
MembersToIgnore = new List<string>() { "Type" },
ClassTypesToIgnore = new List<Type>() { typeof(Officer) },
CollectionMatchingSpec = new Dictionary<System.Type, IEnumerable<string>>()
{
{
typeof(Officer),
new List<string>() { "ID" }
},
{
typeof(Person),
new List<string>() { "ID" }
}
},
TreatStringEmptyAndNullTheSame = true,
IgnoreCollectionOrder = true
};
_compare.Config = comparisonConfig;
var list1 = new List<object>();
var list2 = new List<object>();
Officer p1 = new Officer();
p1.ID = 2;
p1.Name = "Greg";
p1.Type = Deck.AstroPhysics;
Officer p2 = new Officer();
p2.ID = 1;
p2.Name = "Leyla";
p2.Type = Deck.Engineering;
Person p3 = new Person();
p3.ID = 3;
p3.Name = "Henk";
p3.DateCreated = DateTime.Now;
Person p4 = new Person();
p4.ID = 3;
p4.Name = "Henk";
p4.DateCreated = p3.DateCreated;
list1.Add(p1);
list1.Add(p3);
list2.Add(p2);
list2.Add(p4);
var result = _compare.Compare(list1, list2);
Assert.IsTrue(result.AreEqual, result.DifferencesString);
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Conditionally failing validation using class-validator
That method only works to ignore validations i.e with your dto, you validate that the class ToolBox has a property woodScrews of type...
Read more >Constraint errors ignored with dry-validation type_specs
One way to ensure validation fails is to use the :type? predicate on the resulting value. However, the error message for this is...
Read more >Dealing with validation problems
This error indicates that an unsupported type is annotated as nested. Nested types are expected to either declare some annotated properties (which themselves ......
Read more >Validation - Laravel 10.x - The PHP Framework For Web ...
If validation fails during a traditional HTTP request, a redirect response to the previous URL will be generated. If the incoming request is...
Read more >Model Validation in ASP.NET Web API - ASP.NET 4.x
If model validation fails, this filter returns an HTTP response that contains the validation errors.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Implemented
Okay, I will implement. I will get back to this several months later after there are around 10 more issues logged.