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:

Regex obfuscate email

 Use this code in C# to obfuscate email using regex // Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compile...