16

automapperを使用して、ドメインからlinq、sqlクラスにクラスをマップするメソッドの単体テストを行っています。大まかに言って、クラスとマッピングは以下のとおりです(SupplierEligibilityAllocatedはL2S自動生成クラスです)。

public class SupplierEligibilityTransactionByQuantity
{
    public decimal Eligibility { get; private set; }
    public decimal CoreValue { get; private set; }
    public int? TransactionId { get; private set; }
    public SupplierTransactionStatus Status { get; private set; }
    public int? DebitId { get; set; }
    public int ManifestId { get; private set; }
}

public partial class SupplierEligibilityAllocated
{
 private int _SupplierEligibilityCreditId;
 private int _ManifestId;
 private System.Nullable<int> _QuantityApplied;
 private System.Nullable<decimal> _AmountApplied;
 private System.Nullable<decimal> _CoresReservedByAmount;
 private System.DateTime _InsertDate;
 private EntityRef<Manifest> _Manifest;
 private EntityRef<SupplierEligibilityCredit> _SupplierEligibilityCredit;
}

private static void Map_SupplierEligibilityTransactionByQuantity_To_SupplierEligibilityAllocated()
{
    Mapper.CreateMap<EligibilityTransactionByQuantity, SupplierEligibilityAllocated>()
        .ForMember(dest => dest.SupplierEligibilityCreditId, opt => opt.MapFrom(src => src.TransactionId))
        .ForMember(dest => dest.ManifestId, opt => opt.MapFrom(src => src.ManifestId))
        .ForMember(dest => dest.QuantityApplied, opt => opt.MapFrom(src => Convert.ToInt32(src.Eligibility)))
        .ForMember(dest => dest.AmountApplied, opt => opt.Ignore())
        .ForMember(dest => dest.CoresReservedByAmount, opt => opt.Ignore())
        .ForMember(dest => dest.InsertDate, opt => opt.MapFrom(src => DateTime.UtcNow))
        .ForMember(dest => dest.Manifest, opt => opt.Ignore())
        .ForMember(dest => dest.SupplierEligibilityCredit, opt => opt.Ignore());
}

ただし、メソッドがマッピングを実行すると、次の例外がスローされます。

Trying to map SupplierEligibilityTransactionByQuantity to SupplierEligibilityAllocated.
Missing type map configuration or unsupported mapping.
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.

at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
at AutoMapper.MappingEngine.Map(Object source, Type sourceType, Type destinationType)
at AutoMapper.MappingEngine.Map[TSource,TDestination](TSource source)
at AutoMapper.Mapper.Map[TSource,TDestination](TSource source)  

テストの前にマッピングを作成していることを確認し、Mapper.AssertConfigurationIsValid()問題なく電話をかけました。また、問題なく手動でマッピングを行いました。誰がこれを引き起こしている可能性があるかについての考えを持っていますか?

4

2 に答える 2

10

呼び出しで間違ったタイプを指定しているようですMapper.CreateMap

次のようなことを試してください。

Mapper.CreateMap<SupplierEligibilityTransactionByQuantity, SupplierEligibilityAllocated>()
于 2009-12-21T21:28:09.157 に答える
0

を使用している場合はMapper.Map()、マッピングクラスとテーブル/ストアドプロシージャを適切に確認してください。

public static CustomerLedgerViewModel ToModel(this DJBL_tblCustomerCurrentLedger obj)
{
    return Mapper.Map<DJBL_tblCustomerCurrentLedger, CustomerLedgerViewModel>(obj);
}

public static DJBL_tblCustomerCurrentLedger ToEntity(this CustomerLedgerViewModel model)
{
    return Mapper.Map<CustomerLedgerViewModel, DJBL_tblCustomerCurrentLedger>(model);
} 
于 2014-06-16T06:51:49.050 に答える