Ho due classi in questo modo:Automapper non riuscendo a mappare l'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; }
}
E
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; }
}
Identico, come si può vedere (entrambi implementare l'interfaccia per garantire questo)
Ho quindi il seguente mapping:
Mapper.CreateMap<IEnumerable<SentEmailAttachmentItem>, IEnumerable<SentEmailAttachment>>();
Mapper.CreateMap<IEnumerable<SentEmailAttachment>, IEnumerable<SentEmailAttachmentItem>>();
Ho poi hanno il seguente test Unità:
//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));
questo viene a mancare - L'IEnumerable sentEmailAttachmentItems è vuoto. Non ha mappato la lista di SentEmailAttachments ad esso ...
Qualche idea su cosa sta succedendo ??
ce l'ho a lavorare su singoli oggetti (mappatura uno di ciascuno ad uno di ciascuno), ma non una collezione ...