Thursday, September 26, 2019

Unit test controller actions with automapper

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:

//auto mapper configuration
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyMapperProfile());
            });
            var mapper = mockMapper.CreateMapper();

No comments:

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...