我有两个类,如下所示:
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; }
}
并且
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; }
}
正如您所看到的,它们是相同的(它们都实现了接口来确保这一点)。
接下来,我有以下映射:
Mapper.CreateMap<IEnumerable<SentEmailAttachmentItem>, IEnumerable<SentEmailAttachment>>();
Mapper.CreateMap<IEnumerable<SentEmailAttachment>, IEnumerable<SentEmailAttachmentItem>>();
然后我有以下单元测试:
//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));
这个失败了 - IEnumerable sentEmailAttachmentItems 是空的。 它没有将 SentEmailAttachments 的列表映射到它上面...
有任何想法是怎么回事吗?
我已经在单个对象上工作过(将每个对象映射到每个对象),但不能处理集合...