我有一个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