如何在 FakeXrmEasy 中创建一个实体并将另一个实体链接到它?
我正在尝试测试此代码:
public List<abc_OrderTask> GetTasks(Guid workOrderGuid)
{
var result = (from task in _xrmServiceContext.abc_OrderTaskSet
join workOrder in _xrmServiceContext.abc_workorderSet
on task.RegardingObjectId.Id equals workOrder.Id
where workOrder.Id == workOrderGuid
select task).ToList();
return result;
}
abc_OrderTask 和 abc_WorkOrder 的关系是 N:1
在我的测试中,我试图链接这两个实体:
[Test]
public void GetTasks_WorkOrderWithExistingTasks_ReturnsListOfTasks()
{
using (var xrmServiceContext = new XrmServiceContext(_fakeOrganizationService))
{
var workOrderGuid = Guid.NewGuid();
var taskGuid = Guid.NewGuid();
var workOrder = new abc_workorder { Id = workOrderGuid };
var task = new abc_OrderTask
{
Id = taskGuid,
Subject = "Required subject",
RegardingObjectId =
new EntityReference(abc_workorder.EntityLogicalName, workOrderGuid)
};
_fakeContext.Initialize(new List<Entity> { workOrder, task });
var sut = new WorkOrderService(xrmServiceContext);
// Act
// Assert
Assert.That(sut.GetTasks(workOrderGuid), Is.InstanceOf<List<abc_OrderTask>>());
Assert.That(sut.GetTasks(workOrderGuid).Count.Equals(1));
}
}
但是,结果集是空的。
如何在 FakeXrmEasy 中创建一个实体并将另一个实体链接到它?
下面是这个对象是如何被更新的:
private IOrganizationService _fakeOrganizationService;
[SetUp]
public void Init()
{
_fakeContext = new XrmFakedContext { ProxyTypesAssembly = Assembly.GetAssembly(typeof(abc_workorder)) };
_fakeOrganizationService = _fakeContext.GetFakedOrganizationService();
}