When testing controller actions we frequently come across objects which are converted using AutoMapper. While this library is very convenient to use, some extra coding is required in unit tests to test such controller actions. The following article provides a solution for this scenario:
https://stackoverflow.com/questions/49934707/automapper-in-xunit-testing-and-net-core-2-0
In practice, I added a custom mapping profile like so:
https://stackoverflow.com/questions/49934707/automapper-in-xunit-testing-and-net-core-2-0
In practice, I added a custom mapping profile like so:
//auto mapper configuration
var mockMapper = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new MyMapperProfile());
});
var mapper = mockMapper.CreateMapper();
No comments:
Post a Comment