我有一個asp.net webapi項目,其中我有一個控制器,我想單元測試。在那個控制器中我有一個映射。控制器繼承自一個基本控制器,其實施是:單元測試一個控制器與自動映射器映射它
public class BaseController : ApiController
{
/// <summary>
/// AutoMapper Mapper instance to handle all mapping.
/// </summary>
protected IMapper GlobalMapper => AutoMapperConfig.Mapper;
}
我現在想單元測試控制器。我的自動映射器配置如下所示:
public static class AutoMapperConfig
{
/// <summary>
/// Provides access to the AutoMapper configuration.
/// </summary>
public static MapperConfiguration MapperConfiguration { get; private set; }
/// <summary>
/// Provides access to the instance of the AutoMapper Mapper object to perform mappings.
/// </summary>
public static IMapper Mapper { get; private set; }
/// <summary>
/// Starts the configuration of the mapping.
/// </summary>
public static void Start()
{
MapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.AddProfile<MeldingProfiel>();
cfg.AddProfile<GebouwProfiel>();
cfg.AddProfile<AdresProfiel>();
});
MapperConfiguration.AssertConfigurationIsValid();
Mapper = MapperConfiguration.CreateMapper();
}
}
我該如何測試具有此自動映射器映射的控制器?
究竟你想測試什麼? –
如果我的控制器返回我希望它返回的事物的列表。 – AyatollahOfRockNRolla