question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation fails while ignoring class types.

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
GregFinzercommented, Dec 13, 2017

Implemented

0reactions
GregFinzercommented, Nov 14, 2017

Okay, I will implement. I will get back to this several months later after there are around 10 more issues logged.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found