本文整理汇总了C#中FakeXrmEasy.XrmFakedContext.ValidateEntity方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.ValidateEntity方法的具体用法?C# XrmFakedContext.ValidateEntity怎么用?C# XrmFakedContext.ValidateEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FakeXrmEasy.XrmFakedContext
的用法示例。
在下文中一共展示了XrmFakedContext.ValidateEntity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FakeUpdate
protected static void FakeUpdate(XrmFakedContext context, IOrganizationService fakedService)
{
A.CallTo(() => fakedService.Update(A<Entity>._))
.Invokes((Entity e) =>
{
context.ValidateEntity(e);
//Update specific validations: The entity record must exist in the context
if (context.Data.ContainsKey(e.LogicalName) &&
context.Data[e.LogicalName].ContainsKey(e.Id))
{
//Add as many attributes to the entity as the ones received (this will keep existing ones)
var cachedEntity = context.Data[e.LogicalName][e.Id];
foreach (var sAttributeName in e.Attributes.Keys.ToList())
{
cachedEntity[sAttributeName] = e[sAttributeName];
}
// Update ModifiedOn
cachedEntity["modifiedon"] = DateTime.UtcNow;
cachedEntity["modifiedby"] = context.CallerId;
}
else
{
//The entity record was not found, return a CRM-ish update error message
throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("{0} with Id {1} Does Not Exist", e.LogicalName, e.Id));
}
});
}