Issue with mocking IOrganizationService.Execute in CRM 2011 plugin

偶尔善良 提交于 2019-12-06 01:41:44

Your approach is correct, but you use the wrong response type. The service returns the results as OrganizationResponse (which is the base class for all responses). You try to cast the base type into a specific type. This doesn't work.

You simply have to return an instance of SendEmailFromTemplateResponse to get your code working.

var orgService = new Mock<IOrganizationService>();

var idResults = new ParameterCollection
{
   {"Id", Guid.NewGuid()}
};

orgService.Setup(s => s.Execute(It.IsAny<SendEmailFromTemplateRequest>()))
                       .Returns(new SendEmailFromTemplateResponse
{
   Results = idResults,
   ResponseName = "SendEmailFromTemplate"
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!