小编jol*_*ice的帖子

Mapper未初始化,我的单元测试Core.Net 2.0出错

我在Core.net 2.0中使用UOW和automapper完成了WebApi.一切都运行正常,但现在我想用Nunit实现单元测试,我有自动缓冲区的这个错误

消息:System.InvalidOperationException:Mapper未初始化.使用适当的配置调用Initialize.如果您正试图通过容器或以其它方式使用映射器实例,请确保您不必静态Mapper.Map方法的任何电话,如果你使用ProjectTo或UseAsDataSource扩展方法,确保你在适当的IConfigurationProvider通实例.

我该怎么解决这个问题.提前致谢 .Jolynice

AutoMapperProfile.cs类

public class AutoMapperProfile : Profile
{
    public AutoMapperProfile()
    {
        CreateMap<Cars, CarsDTO>()
            .ReverseMap();
    }
}
Run Code Online (Sandbox Code Playgroud)

class Startup.cs

public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
    public void ConfigureServices(IServiceCollection services)
    {

        //removed configurations 

        // Add cors
        services.AddCors();

        // Add framework services.
        services.AddMvc();

        Mapper.Initialize(cfg =>
        {
            cfg.AddProfile<AutoMapperProfile>();
        });

        // Repositories
        services.AddScoped<IUnitOfWork, HttpUnitOfWork>();
        services.AddScoped<IAccountManager, AccountManager>();
    }
}
Run Code Online (Sandbox Code Playgroud)

class carsController.cs

[Authorize]
[Route("api/[controller]")]
public class CarsController : Controller
{
private …
Run Code Online (Sandbox Code Playgroud)

c# testing automapper .net-core

6
推荐指数
1
解决办法
6946
查看次数

假冒伪劣者如何设置字符串数组列表

我想请求您帮助使用Bogus Faker。

我有这个

private readonly Faker _faker;

_faker = new Faker("fr");

List<string> _randomString = (List<string>)_faker.Make(3, () => _faker.Random.Word()); // OK

List<string[]> _randomStrinArray = (List<string[]>)_faker.Make(3, () => _faker.Random.Word()); // KO
Run Code Online (Sandbox Code Playgroud)

c# string list faker bogus

5
推荐指数
2
解决办法
8049
查看次数

注销Aspnet Core后如何防止浏览器后退按钮

我有一个带有 cookie 身份验证的 aspnet 核心网站。当我注销,然后,当我单击浏览器的后退按钮时,我导航到最后一个网页,但我不希望那样,我不想将用户重定向到登录页面进行身份验证再次。

我的启动.cs

public void ConfigureServices(IServiceCollection services)
        {
          ....
            services.AddIdentity<ApplicationUser, ApplicationRole>(
            config =>
            {
                config.User.RequireUniqueEmail = true;
                config.SignIn.RequireConfirmedEmail = true;
                config.Password.RequiredLength = 8;
                config.Cookies.ApplicationCookie.LoginPath = "/Home/Login";
            })
            .AddEntityFrameworkStores<DbContext>()
            .AddDefaultTokenProviders();
        ......
        }
Run Code Online (Sandbox Code Playgroud)

我的控制器.cs

 public class HomeController : Controller
    {
        .....
        private readonly string _externalCookieScheme;
        ....


        public HomeController(
           .....
            IOptions<IdentityCookieOptions> identityCookieOptions,
            .....)
        {
            ....
            _externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme;
            ....

        }




        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> Login()
        {
            // Clear the existing external cookie to ensure a clean login process
            await …
Run Code Online (Sandbox Code Playgroud)

authentication cookies core logoff back

2
推荐指数
1
解决办法
5565
查看次数

标签 统计

c# ×2

.net-core ×1

authentication ×1

automapper ×1

back ×1

bogus ×1

cookies ×1

core ×1

faker ×1

list ×1

logoff ×1

string ×1

testing ×1