Automapper を試してみることにしました。
プロジェクトでいくつかの単体テストを作成しましたが、「すべて実行」すると、それらはすべて期待どおりに合格します。ただし、個々のテストを実行すると失敗します...では、不足している特別な設定はありますか?
これがコードです。これは、すべて実行するとテストに合格します。
[TestMethod]
public void Mappings_ConfigureMappings_pass()
{
Mapper.CreateMap<Address, AddressDTO>();
Mapper.AssertConfigurationIsValid();
}
しかし、実際のマッピング テストを実行すると、テストは失敗します。
[TestMethod]
public void Mappings_ViewModel_Address_ToDTO_pass()
{
var address = new Address()
{
Address1 = "Line1",
Address2 = "Line2",
Address3 = "Line3",
Country = "ROI",
County = "Co Dublin",
PostCode = "ABC",
TownOrCity = "Dublin"
};
AddressDTO addressDTO = Mapper.Map<Address, AddressDTO>(address);
Assert.IsNotNull(addressDTO);
Assert.AreEqual("ROI", addressDTO.Country);
Assert.AreEqual("Dublin", addressDTO.TownOrCity);
}
ここに関連するクラスがあります...ご覧のとおり、それらは同じですが、なぜテストが失敗するのですか? セットアップで見逃したものですか?
public class Address
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string PostCode { get; set; }
public string TownOrCity { get; set; }
}
public class AddressDTO
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string PostCode { get; set; }
public string TownOrCity { get; set; }
}
失敗メッセージは次のとおりです。
Missing type map configuration or unsupported mapping.
Mapping types:
Address -> AddressDTO
UI.Address -> Services.DataTransferObjects.AddressDTO
Destination path:
AddressDTO
Source value:
UI.Address