- Discover how and why use an object-object mapper library
- Practice Approval testing approach and discover how powerful it can be with several Use Cases :
- Check mappings
- Check API results in Integration Tests
- Check non deterministic data
- Combination approvals
- .NET 6
- Your favorite IDE
- Access to nuget.org
- Object-object mapper :
AutoMapper
- Approval Testing :
Verify
- Test Framework :
xUnit
- Assertions :
FluentAssertions
- Fix the test
Should_Map_Employee_To_EmployeeEntity
by usingAuto-Mapper
- What is surprising you ?
- How could it be helpful in your current projects ?
- Add a new "feature" that brings mapping from
PersonAccount
toIndividualParty
- Discuss how easy it is to add new mappings
Also called : Characterization Tests OR Snapshot Tests or Golden Master
A picture’s worth a 1000 tests.
- Unit testing assertions can be difficult to use and long to write
- Approval tests simplify this by taking a snapshot of the results / confirming that they have not changed at each run
This technique can be used on :
- On any new code
- On legacy code
- Add a new test to check this mapping
PersonAccount -> IndividualParty
by using theVerify
library- What do you think about it ?
- Create a
Controller
containing a GET method returningIndividualParties
- Hardcoded once by using
DataBuilder
(Capone / Mesrine) - Check its behavior by using "classical" assertions
- Check it with
Verify
- Compare the effort needed in both cases
- Discuss the pros and cons of those 2 approaches
- Hardcoded once by using
- Create a new
Controller
containing a GET method returningMontana
- How do you handle non-deterministic data in your tests ?
- Use
Verify
to check your API result
We have an improvable piece of code in our code base :
public static Template FindTemplateFor(string documentType, string recordType)
{
foreach (var dtt in TemplateMappings())
{
if (dtt.DocumentType.ToString().Equals(documentType, StringComparison.InvariantCultureIgnoreCase) &&
dtt.RecordType.ToString().Equals(recordType, StringComparison.InvariantCultureIgnoreCase))
{
return dtt;
}
else if (dtt.DocumentType.ToString()
.Equals(documentType, StringComparison.InvariantCultureIgnoreCase) &&
dtt.RecordType.ToString().Equals("ALL"))
{
return dtt;
}
}
throw new ArgumentException("Invalid Document template type or record type");
}