c# - Automapper and validate configuration with DDD -
i have simple domain model in ddd approach way create instance use constructor.
public cashcasedifference( double amount, double originalamount, double originalfcyamount, cashcasedifferencecurrency currency, cashcasedifferencesource source, cashcasedifferencetype type) { this.amount = amount; this.originalamount = originalamount; this.originalfcyamount = originalfcyamount; this.currency = currency; this.source = source; this.type = type; }
and have problem when i'am trying unit test configuration.
mapping profile:
this.createmap<cashcaseout, cashcasedifference>() .constructusing(source => new cashcasedifference( source.amount.getvalueordefault(), source.originalamount.getvalueordefault(), source.originalfcyamount.getvalueordefault(), (cashcasedifferencecurrency) source.currency.getvalueordefault(), (cashcasedifferencesource) source.sourceofdifference.getvalueordefault(), (cashcasedifferencetype) source.type.getvalueordefault()));
and unit test method:
mapper.initialize( cfg => { cfg.addprofile(new cashcaseouttocashcasedifference()); }); mapper.assertconfigurationisvalid(););
it return error properties not mapped:
unmapped members found. review types , members below.
"add custom mapping expression, ignore, add custom resolver, or modify source/destination type no matching constructor, add no-arg ctor, add optional arguments, or map of constructor parameters"
unmapped properties: source
edit:
construction not work well.
mapper.initialize(cfg => { cfg.addprofile(new cashcaseouttocashcasedifference()); }); mapper.assertconfigurationisvalid(); public cashcaseouttocashcasedifference() { this.createmap< cashdiffms.client.models.cashcaseout, core.cashcases.domain.differences.cashcasedifference>() .forctorparam("amount", opt => opt.mapfrom(src => src.amount)) .forctorparam("originalamount", opt => opt.mapfrom(src => src.originalamount)) .forctorparam("originalfcyamount", opt => opt.mapfrom(src => src.originalfcyamount)) .forctorparam("currency", opt => opt.mapfrom(src => src.currency)) .forctorparam("source", opt => opt.mapfrom(src => src.sourceofdifference)) .forctorparam("type", opt => opt.mapfrom(src => src.type)); } public cashcasedifference( double amount, double originalamount, double originalfcyamount, cashcasedifferencecurrency currency, cashcasedifferencesource source, cashcasedifferencetype type) { this.amount = amount; this.originalamount = originalamount; this.originalfcyamount = originalfcyamount; this.currency = currency; this.source = source; this.type = type; }
result same: unmapped properties: source
that's because you're mapping hand. should let it. docs here.
Comments
Post a Comment