CRM 2016 FakeXrmEasy N:N 关系

2023-11-23

我正在尝试使用FakeXrmEasy为 CRM Online (2016) 执行一些单元测试,但我在设置具有 N:N 关系的测试之一时遇到问题

以下代码设置了一个包含 2 个实体的 Faked Context,并初始化了一个 Faked Organization Service:

var entity1 = new New_entityOne();
var entity2 = new New_entityTwo();

var context = new XrmFakedContext();
context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(New_entityOne));
context.Initialize(new List<Entity>()
{
    entity1,
    entity2
});

var service = context.GetFakedOrganizationService();

然后我尝试在这些实体之间创建 N:N 关系:

var join = new AssociateRequest
{
    Relationship = new Relationship
    {
        SchemaName = "new_entityOne_new_entityTwo",
        PrimaryEntityRole = EntityRole.Referenced
    },
    Target = entity1.ToEntityReference(),
    RelatedEntities = new EntityReferenceCollection
    {
        entity2.ToEntityReference()
    }
};

service.Execute(join);

当我执行这个Request,我期望在我的模拟数据中生成 N:N-join 记录,介于entity1 and entity2

相反,我收到这样的错误:

FakeXrmEasy.dll 中发生“System.Exception”类型的异常 但未在用户代码中处理

附加信息:关系 new_entityOne_new_entityTwo 确实 元数据缓存中不存在

有没有其他人尝试过以这种方式使用这个单元框架?到目前为止,我使用它已经得到了非常好的结果。

显然,这些不是我实际的实体和关系名称


请尝试添加如图所示的虚假关系here

这是因为对于 N:1 没有相交表,连接是通过 EntityReference 执行的,仅此而已,但对于多对多,由于有相交表,我们现在需要告诉框架如何处理这种情况。

还有一个更新,不再强制使用 ProxyTypesAssembly,只要您使用早期绑定类型,代理类型程序集就会从您的类型中“猜测”。

所以你可以删除这个

context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(New_entityOne));

我需要更新网站中的文档...只要有机会:)

Edit

网站已更新:http://dynamicsvalue.com/get-started/nn-relationships

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CRM 2016 FakeXrmEasy N:N 关系 的相关文章

随机推荐