Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Edited Unassigned: Equal and collections of generics = bad message description [12492]

$
0
0
If a Equal test fail on a collection containing generic types (Class<T>) the test failed message returns a generic error message, telling just the index of the collection were the test failed, instead with a normal object graph the message contains the full object text rapresentation that is really useful.

Class samples:

public class BaseStuff
{
public int StuffId { get; set; }
public string Description { get; set; }
}

public class Stuff<TChild> : BaseStuff
{
public List<TChild> Childs { get; set; }
}

Testing with this code:

stuff.Should().NotBeNull()
.And.HaveCount(2)
.And.Equal(expectedStuff, (t1, t2) => t1.StuffId == t2.StuffId && t1.Description == t2.Description);

Case 1 (good message):

var stuff = new List<BaseStuff>();
var expectedStuff = new List<BaseStuff>();

Returned Message if fails:

Expected collection to be equal to {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "WRONG_DESCRIPTION"
StuffId = 2
}}, but {

UnitTestProject1.BaseStuff
{
Description = "Stuff_1"
StuffId = 1
},

UnitTestProject1.BaseStuff
{
Description = "Stuff_2"
StuffId = 2
}} differs at index 1.

Case 2 (bad message):

var stuff = new List<Stuff<int>>();
var expectedStuff = new List<Stuff<int>>();

Returned Message if fails:

Result Message: Expected collection to be equal to {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]}, but {UnitTestProject1.Stuff`1[System.Int32], UnitTestProject1.Stuff`1[System.Int32]} differs at index 1.


Is there possible to have the same fail message also for generics?

I've attached also the complete test class to test the behavior.

Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>