如何在C#中使用nunit在静态类中为私有静态方法编写单元测试

时间:2020-04-21 18:21:21

标签: c# unit-testing nunit static-methods static-classes

我正在使用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();
    }
}

0 个答案:

没有答案