我正在尝试通过包含 AutoMapper 使用的存储库测试从我的 ASP.NET Core 控制器到数据库的路径。
这是我的存储库:
using System;
using System.Linq;
using AutoMapper;
using DS.DTO.MasterData;
using DS.Utilities.DSExceptions;
using Microsoft.Extensions.Logging;
using Omu.ValueInjecter;
namespace DS.MasterData.Repositories
{
public class PersonFactRepository : IPersonFactRepository
{
private readonly Database.MasterDataContext dbContext;
private readonly ILogger<PersonFactRepository> logger;
private readonly IMapper mapper;
public PersonFactRepository(ILogger<PersonFactRepository> logger, Database.MasterDataContext dbcontext, IMapper mapper)
{
this.dbContext = dbcontext;
this.mapper = mapper;
this.logger = logger;
}
public PatientDto CreatePatient(CreatePatientDto inModel)
{
var dbPersonDim = mapper.Map<CreatePatientDto, Database.PersonDim>(inModel);
var dbAddressDim = mapper.Map<CreatePatientDto, Database.AddressDim>(inModel);
var dbPhoneDim = mapper.Map<CreatePatientDto, Database.PhoneDim>(inModel);
var dbPersonFact = new Database.PersonFact { FactId = Guid.NewGuid() };
dbPersonDim.PersonFact = dbPersonFact;
dbAddressDim.PersonFact = dbPersonFact;
dbPhoneDim.PersonFact = dbPersonFact;
}
}
}
我的问题是如何将我的 Mapper 配置放入我的 fakeMapper 中?
var inMemDB = Fakes.FakeDB.DB;
var loggerCntl = Substitute.For<ILogger<Controllers.PatientController>>();
var loggerPersonFactRepo = Substitute.For<ILogger<Repositories.PersonFactRepository>>();
AutoMapper.IMapper fakeMapper = ????
var personRepo = new PersonFactRepository(loggerPersonFactRepo, inMemDB, fakeMapper);
我有意进行集成测试,因为我希望我的测试能够将数据发布到控制器并测试正确的数据是否最终出现在正确的表中。
摇曳的蔷薇
相关分类