Plugin with precreate not querying as expected #65
-
Hi. I don't know if I have a problem with my code but when I perform a PreCreate plugin it doesn't exist in the CreateQuery after the plugin has acted. _context.Initialize(listEntities); //Initialised mysystemuser, account
var target = new Entity("new_manager")
{
Id = Guid.NewGuid(),
["new_systemuserid"] = mysystemuser.ToEntityReference(),
["new_accountid"] = account.ToEntityReference(),
["statecode"] = new OptionSetValue(0)
};
executionContext.MessageName = "Create";
executionContext.Stage = 20;
executionContext.PrimaryEntityId = target.Id;
executionContext.PrimaryEntityName = target.LogicalName;
executionContext.InputParameters = new ParameterCollection
{
new KeyValuePair<string, object>("Target", target)
};
var exception = Record.Exception(() => _context.ExecutePluginWithTarget<MyPlugin>(target));
//exception here is null
int managersinCrmCount = (from t in _context.CreateQuery("new_manager") select t).Count();
Xunit.Assert.Null(exception); //True
Xunit.Assert.Equal(1, managersinCrmCount); //here managersincrmcount is 0; // False and Assert error Is there anything I am missing or I am doing in the wrong way? Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@victorsolaya thanks for your comment. This is by design (also in v1). When you use ExecutePlugin* methods that make updates to the target entity, these won't be persisted into the In-Memory db if the plugin code doesn't make any explicit calls to .Update(), .Create() and so on... BUT, you can easily assert any modifications made to the target but just asserting on it directly (since the reference in memory is the same), and so there is no need to use .CreateQuery() for it. This is already covered in the docs: https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/plugins/overview/ Please see "Asserting on the Target entity and/or other PluginContext properties" section in that link above. |
Beta Was this translation helpful? Give feedback.
@victorsolaya thanks for your comment.
This is by design (also in v1).
When you use ExecutePlugin* methods that make updates to the target entity, these won't be persisted into the In-Memory db if the plugin code doesn't make any explicit calls to .Update(), .Create() and so on...
BUT, you can easily assert any modifications made to the target but just asserting on it directly (since the reference in memory is the same), and so there is no need to use .CreateQuery() for it.
This is already covered in the docs: https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/plugins/overview/
Please see "Asserting on the Target entity and/or other PluginContext properties" section in that lin…