CRM 2016 FakeXrmEasy N: N relationship

I'm trying to use FakeXrmEasy to run some unit tests for CRM Online (2016), and I'm having trouble setting up one of my tests with an N: N ratio

The following code sets up a fake context with two objects in it and initializes the 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(); 

Then I try to create an N: N relation between these objects:

 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 expect that an N: N-join record will be created in my layout data between entity1 and entity2

Instead, I get an error message:

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

Additional Information: The relationship new_entityOne_new_entityTwo does not exist in the metadata cache

Has anyone else tried to use this device infrastructure this way? Until now, I have been getting really good results using it.

obviously these are not my actual names of entities and relationships

+5
unit-testing dynamics-crm-2016 dynamics-crm-online
source share
1 answer

Try adding fake relationships as shown here

This is because for N: 1 there is no intersecting table, joins are done through EntityReference and that is it, but for many, many, since there is an intersection table, we need to tell the structure how to handle this scenario so far.

There was also an update in which it is no longer necessary to use ProxyTypesAssembly, if you use early related types, the proxy type assembly will β€œguess” from your types.

So you can remove this

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

I need to update the documentation on the website ... whenever I have a chance :)

Edit

Updated website: http://dynamicsvalue.com/get-started/nn-relationships

+2
source share

All Articles