AllBeEquivalentTo not working with Generic Lists
See original GitHub issueDescription
Comparing two identical generic lists using AllBeEquivalentTo failing.
Complete minimal example reproducing the issue
class Dto
{
public string Name { get; set; }
public string Value { get; set; }
}
[TestMethod]
public void TestBug()
{
var list1 = new List<Dto>
{
new Dto() {Name = "ABC", Value = "123"}
};
var list2 = new List<Dto>
{
new Dto() {Name = "ABC", Value = "123"}
};
list1.Should().AllBeEquivalentTo(list2);
}
NOTE: This is fails if I do this.
list1.Should().AllBeEquivalentTo(list1);
Expected behavior:
I believe this should pass.
Actual behavior:
Fails with a message that looks like this.
Expected item[0] to be {Tdx.Puf.Conversion.Tests.Dto
{
Name = "ABC"
Value = "123"
}}, but found
Tdx.Puf.Conversion.Tests.Dto
{
Name = "ABC"
Value = "123"
}.
With configuration:
- Use declared types and members
- Compare enums by value
- Include all non-private properties
- Include all non-private fields
- Match member by name (or throw)
- Try conversion of all members.
- Try conversion of all members.
- Be strict about the order of items in byte arrays
Versions
- Fluent Assertions 5.3.2.0
- .Net 4.7.1
Additional Information
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# generic list subtype operations not working
Ignoring the fact that its almost never desirable to inherit from List<T> , you could create a copy constructor:
Read more >Collections
AllBeEquivalentTo (referenceObject);. In case if you need to perform individual assertions on all elements of a collection, you can assert each element ...
Read more >CA1002: Do not expose generic lists (code analysis) - .NET
To fix a violation of this rule, change the System. Collections. Generic. List<T> type to one of the generic collections that's designed for ......
Read more >List<T>.Count Property (System.Collections.Generic)
The following example demonstrates how to check the capacity and count of a List<T> that contains a simple business object, and illustrates using...
Read more >Generic List Collection in C# with Examples
In this article, I am going to discuss Generic List Collection Class in C# with Examples. List represents a strongly typed list of...
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 FreeTop 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
Top GitHub Comments
You’re using
List<BlockContentItem>
andList<InlineContentItem>
and insertTextBlock
s, andTextContentItem
s. Per defaultBeEquivalentTo
will use the compile-time types, so it will only compare the properties declared onBlockContentItem
andInlineContentItem
.To use the run-time types use
RespectingRuntimeTypes()
.That did the trick. Thanks so much for the quick reply. I’m going to close this.