I am doing integrative xunit tests on a .NET Core web application. The result of a call can sometimes be a large object with different levels of hierarchy.
MainEntity
{
public decimal TotalTaxValue{ get; set; }
public decimal GrossPrice{ get; set; }
public List<Taxes> GroupedTotal { get; set; }
//..... 20 more properties
}
Taxes
{
public List<TaxCode> TaxCodes {get;set;}
public decimal TaxedAmount{get;set;}
}
TaxCode
{
public string TaxCodeType {get;set;} //VAT / EGAT
public string ApplicableRegion {get;set;}
}
Now when doing tests (using FluentAssertions) I end up with many lines of
item.PropertyName.Should().Be(output.PropertyName, because: "reason")
Also when going to compare the lists of objects inside the models, I found a few not nice to look at linq statements (which spread across multiple lines).
I should mention I don't have access to modify the original model and override the equals method.
Looking at how my code, with 10+ lines of assertions for a single test it can't be the best approach.
Another way I thought of approaching this would be to have a method to handle all of the assertions - but this only hides the issue. Also doing a test for each property, to avoid multiple assertions in a test, would be very time consuming, both in developing the tests and execution.
Question:
What are the best practices when comparing/(performing assertions on) larger objects in terms of assertions?