I'm unit testing an ASP.Net Core API by asserting that my repo layer returns a DTO object. As I'm testing behavior, I don't exactly care what values my DTO object has, so I'm autogenerating them using AutoFixture. I'm also trying to satisfy my company's code smell check, which requires our PRs to have a near 100% test coverage. When I mock my ORM to return my DTO object when called and in turn the function under test returns that object, I end up with my actual being the same object as my expected. When asserting with fluent assertion, it sees the object reference are equal and passes my test. However for test coverage, I will not see a coverage over the DTO's properties' getters. If the object reference where different, fluent assertion calls the getters. How do I force fluent assertion to always check the value of all properties by calling all the getters?
I've tried using ComparingByValue<T>
and ComparingByMember<T>
. I've also tried IncludingProperties()
, IncludingMembers()
, IncludingAllDeclaredProperties()
, and IncludingAllRuntimeProperties()
.
[Fact]
public void GivenObjectReferenceIsTheSame_FluentAssertionDoesntCallTheGetters()
{
var someDTO = _fixture.Create<SomeDTO>();
var otherDTO = someDTO;
otherDTO.Should().BeEquivalentTo(someDTO);
}
[Fact]
public void GivenObjectReferenceIsDifferent_FluentAssertionCallsTheGetters()
{
var someDTO = _fixture.Create<SomeDTO>();
var otherDTO = JsonConvert.DeserializeObject<SomeDTO>(JsonConvert.SerializeObject(someDTO));
otherDTO.Should().BeEquivalentTo(someDTO);
}
I would like a way to always force fluent assertion to call the getters in order to get test coverage over the DTOs without having to explicitly write useless tests over the DTOs