[英]Dynamics 365 FakeXrm "usersettings" entity error
I have this piece of code in my Dynamics 365 plugin,我的 Dynamics 365 插件中有这段代码,
private int? RetrieveCurrentUsersSettings(IOrganizationService service)
{
var currentUserSettings = service.RetrieveMultiple(
new QueryExpression("usersettings")
{
ColumnSet = new ColumnSet("timezonecode"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("systemuserid", ConditionOperator.EqualUserId)
}
}
}).Entities[0].ToEntity<Entity>();
return (int?)currentUserSettings.Attributes["timezonecode"];
}
and I am writing a UnitTest for it with FakeXrm, and while debugging I am getting an error, in this query expression.我正在用 FakeXrm 为它编写一个 UnitTest,在调试时我在这个查询表达式中遇到错误。
Here is my fake Xrm code.这是我的假 Xrm 代码。
Entity systemUser = new Entity("systemuser");
systemUser.Id = Guid.NewGuid();
Entity userSettings = new Entity("usersettings");
userSettings.Id = Guid.NewGuid();
userSettings["timezonecode"] = 71;
userSettings["systemuserid"] = systemUser.ToEntityReference();
fakedContext.Initialize(new List<Entity>()
{
workOrder, owner, invoiceNote, userSettings
});
The question is, how to create usersettings entity in FakeXrm and provide proper attributes to it.问题是,如何在 FakeXrm 中创建usersettings实体并为其提供适当的属性。
I am glad that you followed my suggestion to ask the question on StackOverflow.我很高兴您按照我的建议在 StackOverflow 上提问。
Anyway you should have pointed out that you asked the same question on GitHub on the FakeXrmEasy repository and that the solution was provided there with this answer .无论如何,您应该指出您在 GitHub 上的FakeXrmEasy存储库上提出了相同的问题,并且在那里提供了此答案的解决方案。
Long story short, the problem with your UnitTest was that you were missing fakedContext.CallerId = systemUser.ToEntityReference();
长话短说,你的 UnitTest 的问题是你缺少fakedContext.CallerId = systemUser.ToEntityReference();
and that was needed because you were using ConditionOperator.EqualUserId
in your query.这是必需的,因为您在查询中使用了ConditionOperator.EqualUserId
。
Best Regards, Betim Beja.最好的问候,贝蒂姆贝贾。
I have found a solution我找到了解决办法
Entity systemUser = new Entity("systemuser");
systemUser.Id = Guid.NewGuid();
fakedContext.CallerId = systemUser.ToEntityReference();
IOrganizationService service = fakedContext.GetOrganizationService();
Entity userSettings = new Entity("usersettings");
userSettings.Id = Guid.NewGuid();
userSettings["timezonecode"] = 71;
userSettings["systemuserid"] = systemUser.ToEntityReference();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.