Tôi có hai lớp học như vậy:Automapper thất bại trong việc lập bản đồ trên IEnumerable
public class SentEmailAttachment : ISentEmailAttachment
{
public SentEmailAttachment();
public string FileName { get; set; }
public string ID { get; set; }
public string SentEmailID { get; set; }
public string StorageService { get; set; }
public string StorageServiceFileID { get; set; }
}
Và
public class SentEmailAttachmentItem : ISentEmailAttachment
{
[ItemName]
public string ID { get; set; }
public string SentEmailID { get; set; }
public string FileName { get; set; }
public string StorageService { get; set; }
public string StorageServiceFileID { get; set; }
}
giống hệt, như bạn có thể nhìn thấy (cả hai đều thực hiện giao diện để đảm bảo điều này)
Sau đó tôi có bản đồ sau:
Mapper.CreateMap<IEnumerable<SentEmailAttachmentItem>, IEnumerable<SentEmailAttachment>>();
Mapper.CreateMap<IEnumerable<SentEmailAttachment>, IEnumerable<SentEmailAttachmentItem>>();
sau đó tôi có kiểm tra đơn vị sau đây:
//create a load of sent email attachments
var listOfSentEmailAttachments = new List<SentEmailAttachment>();
for (int i = 0; i < 10; i++)
listOfSentEmailAttachments.Add(new SentEmailAttachment { FileName = "testFileName", ID = Guid.NewGuid().ToString(), SentEmailID = Guid.NewGuid().ToString(), StorageService = "S3", StorageServiceFileID = "SomeFileID" });
var sentEmailAttachmentItems = Mapper.DynamicMap<IEnumerable<SentEmailAttachment>, IEnumerable<SentEmailAttachmentItem>>(listOfSentEmailAttachments);
var itemToTest = sentEmailAttachmentItems.First();
Assert.IsInstanceOfType(itemToTest, typeof(SentEmailAttachmentItem));
này thất bại - Các IEnumerable sentEmailAttachmentItems trống. Nó không lập bản đồ danh sách SentEmailAttachments cho nó ...
Bất kỳ ý tưởng gì đang xảy ra ??
Tôi có nó làm việc trên các đối tượng duy nhất (lập bản đồ một trong mỗi cho một trong mỗi) nhưng không phải là một bộ sưu tập ...