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