c# - 如何在c#中使用nunit为静态类中的私有静态方法编写单元测试
问题描述
我正在使用 nunit 进行单元测试,并且我想在静态类中测试私有方法。这是我的课:
public static class ServiceModuleExtentions
{
public static void RegisterCoreServices(this IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<ICourseService, CourseService>();
var automapper = RegisterAutoMapperService();
serviceCollection.AddSingleton(automapper);
}
private static IMapper RegisterAutoMapperService()
{
// Auto Mapper Configurations
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new MapperProfile());
});
IMapper mapper = mappingConfig.CreateMapper();
return mapper;
}
}
现在我的问题是如何为 RegisterAutoMapperService 方法编写单元测试?
这也是我的 MapperProfile 类:
public class MapperProfile : Profile
{
public MapperProfile()
{
CreateMap<Course, CourseVM>().ReverseMap();
}
}
解决方案
推荐阅读
- c# - 检查部分未知路径中的文件
- laravel - 有没有其他方法可以让 Laravel 重新加载环境变量?
- webpack - 在 babel-loader 中获取 webpack 块名称
- android - “打开”新活动后黑屏
- python - 将python OrderedDict隐蔽到数据框
- bazel - 需要帮助使用 Bazel + Linaro 交叉编译 nsync
- sql - Amazon Redshift 中的固定长度字符串比较
- asp.net - ASP.NET Core 等效于 OwinContext.Environment?
- ionic-framework - Jhipster Ionic 实体创建:没有这样的文件 _entity.html.ejs
- reactjs - 即使组件仍然被渲染,React props 也会被评估