C# 无法转换列表<;最小起订量模拟<;System.Web.HttpPostedFileBase>&燃气轮机;列出<;System.Web.HttpPostedFileBase>;
我有一个单元测试,模拟HttpPostedFileBase文件并将它们放在一个列表中。然后,单元测试调用一个类似这样的邮件服务(省略了与to、from、subject等无关的参数) uploadedFiles变量如下:C# 无法转换列表<;最小起订量模拟<;System.Web.HttpPostedFileBase>&燃气轮机;列出<;System.Web.HttpPostedFileBase>;,c#,asp.net-mvc,C#,Asp.net Mvc,我有一个单元测试,模拟HttpPostedFileBase文件并将它们放在一个列表中。然后,单元测试调用一个类似这样的邮件服务(省略了与to、from、subject等无关的参数) uploadedFiles变量如下:列出uploadedFiles mailService(单元测试调用)如下所示: public static bool SendMailWithFile(List<HttpPostedFileBase> uploadedFiles) publicstaticbools
列出uploadedFiles
mailService(单元测试调用)如下所示:
public static bool SendMailWithFile(List<HttpPostedFileBase> uploadedFiles)
publicstaticboolsendmailWithFile(列出上载的文件)
现在一切都应该正常了,模拟列表确实包含文件(这意味着它不是空的),但我得到了这个错误
无法从转换
System.Collections.Generic.List<Moq.Mock<System.Web.HttpPostedFileBase>
System.Collections.Generic.List您必须使用Object
属性从Mock
对象中获取模拟对象(HttpPostedFileBase
)
这应该做到:
bool result = Services.Mail.MailService.SendMailWithFile(
uploadedFiles.Select(x => x.Object).ToList());
谢谢你,雅库布。我没想到。
System.Collections.Generic.List<System.Web.HttpPostedFileBase>
bool result = Services.Mail.MailService.SendMailWithFile(
uploadedFiles.Select(x => x.Object).ToList());