CRM 2016 FakeXrmEasy N:N关系 [英] CRM 2016 FakeXrmEasy N:N relationships

查看:127
本文介绍了CRM 2016 FakeXrmEasy N:N关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



以下代码设置了一个包含2个实体的伪造上下文,并初始化了伪造组织服务:

  varentity1 = new New_entityOne(); 
varentity2 = new New_entityTwo();

var context = new XrmFakedContext();
context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(New_entityOne));
context.Initialize(new List< Entity>()
{
实体1,
实体2
});

var服务= context.GetFakedOrganizationService();

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

  var连接=新的AssociateRequest 
{
关系=新的关系
{
SchemaName = new_entityOne_new_entityTwo,
PrimaryEntityRole = EntityRole.Referenced
},
Target = entity1.ToEntityReference(),
RelatedEntities = new EntityReferenceCollection
{
Entity2.ToEntityReference()
}
};

服务。执行(加入);

当我执行此 Request 时,我期望在我的模拟数据中生成N:N联接记录,介于 entity1 entity2



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


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



其他信息:关系new_entityOne_new_entityTwo元数据缓存中不存在


还有其他人尝试过使用此单元框架吗?到目前为止,我一直在使用它获得非常好的效果。



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

解决方案

请尝试添加伪造的关系,如图所示此处



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

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



因此您可以删除此

  context.ProxyTypesAssembly =程序集。 GetAssembly(typeof(New_entityOne)); 

只要有机会,我就需要更新网站上的文档... )



编辑



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


I'm trying to use FakeXrmEasy to perform some unit tests for CRM Online (2016) and I'm having problems setting up one of my tests with an N:N relationship

The following code sets up a Faked Context with 2 entities in it and initializes a 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();

I then try to create an N:N relationship between these entities:

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);

When I execute this Request, I'm expecting a N:N-join record to be produced in my mock data, between entity1 and entity2

Instead I'm getting an error like this:

An exception of type 'System.Exception' occurred in FakeXrmEasy.dll but was not handled in user code

Additional information: Relationship new_entityOne_new_entityTwo does not exist in the metadata cache

Has anyone else tried using this unit framework in this way? Up until this point I have been getting really good results using it.

obviously, these are not my actual entity and relationship names

解决方案

Please try adding a fake relationship as shown here

This is because for N:1 there's no intersect table, joins are performed via an EntityReference and that's it, but for many to many, as there is an intersect table, we need to tell the framework how to deal with this scenario for now.

There was also an update where it is no longer mandatory to use ProxyTypesAssembly, as long as you use early bound types, the proxy types assembly will be "guessed" from your types.

So you could remove this

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

I'll need to update the documentation in the web site... whenever I have a chance :)

Edit

Web site updated: http://dynamicsvalue.com/get-started/nn-relationships

这篇关于CRM 2016 FakeXrmEasy N:N关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆