我正在尝试使用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 确实
元数据缓存中不存在
有没有其他人尝试过以这种方式使用这个单元框架?到目前为止,我使用它已经得到了非常好的结果。
显然,这些不是我实际的实体和关系名称