我正在尝试针对更新请求引发异常的情况创建测试。使用 FakeXRMEasy 可以做到这一点吗?我曾尝试使用 AddFakeMessageExecutor,但目前它不起作用:
我的假消息执行器类:
public class UpdateExecutor : IFakeMessageExecutor
{
public bool CanExecute(OrganizationRequest request)
{
return request is UpdateRequest;
}
public OrganizationResponse Execute(
OrganizationRequest request,
XrmFakedContext ctx)
{
throw new Exception();
}
public Type GetResponsibleRequestType()
{
return typeof(UpdateRequest);
}
}
测试中使用:
fakeContext.Initialize(new Entity[] { agreement });
fakeContext.AddFakeMessageExecutor<UpdateRequest>(new UpdateExecutor());
fakeContext.ExecuteCodeActivity<AgreementConfirmationWorkflow>(fakeContext.GetDefaultWorkflowContext());
在工作流中调用更新请求:
var workflowContext = executionContext.GetExtension<IWorkflowContext>();
var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
/// some code to retrieve entity and change attributes ///
service.Update(entity);
我希望这会引发异常,但目前更新请求已成功完成。我怎样才能使这项工作?