任何人都可以为我提供代码示例,以便使用Rhino Framework对工作流进行单元测试。更具体地说,我似乎无法存根CodeActivityContext
对象,它是workflow.execute
方法的参数。我是Rhino的新手,也没有任何帮助。
答案 0 :(得分:0)
我建议使用不同的单元测试方法,这与大多数博客和帖子不同。
我建议您获取IOrganizationService以及执行功能所需的任何数据或标识符。然后,我建议将执行繁重的功能(逻辑,CRUD操作等)放在一个单独的类中。这样,您只需要创建IOrganizationService的模拟。这是一个例子:
public class AccountContactManager
{
private IOrganizationService _service;
public AccountContactManager(IOrganizationService service)
{
_service = service;
}
public void UpdateAccountContacts(Guid accountId)
{
this._service.Execute();//do something here with the service
}
}
以下是如何从CodeActivityContext获取所需内容的示例:
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
var recordId = context.PrimaryEntityId;
var preImage = context.PreEntityImages["PreImage"];
var postImage = context.PostEntityImages["PostImage"];
var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var organizationService = result.Factory.CreateOrganizationService(context.UserId);
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
var userId = context.UserId;
var record = context.InputParameters["Target"];
if (record is Entity)
{
var entityRecord = (Entity)record;
}
else
{
var recordReference = (EntityReference)record;
}