I am trying to set unit tests for an N:N relationship in an Associate/Disassociate plugin but it fails in the “context.GetRelationship().SchemaName” statement. From what I can tell, that function is part of the FakeXrmEasy “context” but the plugin function is from its executeContext. So, how do I replicate the plugin call with that from FakeXrmEasy? Then again, the FakeXrmEasy function requires an argument when the plugin’s executionContext does not. What am I missing?
**Here is the FakeXrmEasy code.**
// Create the Team - INL Web Roles association
context.AddRelationship("inl_INLWebRole_Team_Association", new XrmFakedRelationship
{
IntersectEntity = inl_INLWebRole_Team.EntityLogicalName,
Entity1LogicalName = Team.EntityLogicalName,
Entity1Attribute = "teamid",
Entity2LogicalName = inl_INLWebRole.EntityLogicalName,
Entity2Attribute = "inl_inlwebroleid"
});
**and a call to the plugin**
var executionContext = new XrmFakedPluginExecutionContext()
{
MessageName = message.ToString(),
Stage = (int)StageEnum.PostOperation,
UserId = Guid.NewGuid(), // dummy user
PrimaryEntityName = (targetEntity != null ? targetEntity.LogicalName : "none"),
PrimaryEntityId = (targetEntity != null ? targetEntity.Id : Guid.Empty),
PreEntityImages = (imageType == ImageTypeEnum.PreImage ? images : null),
PostEntityImages = (imageType == ImageTypeEnum.PostImage ? images : null),
InputParameters = inputParameters,
};
// Execute the plugin
context.ExecutePluginWith<TeamMembershipPlugin>(executionContext);
**And here is a code snippet of the plugin.**
protected override void ExecutePlugin(IExtendedPlugin executeContext)
{
InitializeContext(executeContext);
tracer.Trace("Beginning execution of Team Membership Plugin");
// Get the action to process
var processAction = ActionCall.None;
if (this.context.MessageName == MessageNameEnum.Associate.ToString())
{
processAction = ActionCall.AddRole;
}
else if (this.context.MessageName == MessageNameEnum.Disassociate.ToString())
{
processAction = ActionCall.RemoveRole;
}
else
{
return;
}
// Process either the team membership (team or queue)
// or the web Role association. Otherwise quit.
var relationshipName = executionContext.GetRelationship().SchemaName;
The process fails on that last line because there is no relationship in that context.