本文整理汇总了C#中FakeXrmEasy.XrmFakedContext.AddEntity方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.AddEntity方法的具体用法?C# XrmFakedContext.AddEntity怎么用?C# XrmFakedContext.AddEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FakeXrmEasy.XrmFakedContext
的用法示例。
在下文中一共展示了XrmFakedContext.AddEntity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FakeCreate
/// <summary>
/// Fakes the Create message
/// </summary>
/// <param name="context"></param>
/// <param name="fakedService"></param>
protected static void FakeCreate(XrmFakedContext context, IOrganizationService fakedService)
{
A.CallTo(() => fakedService.Create(A<Entity>._))
.ReturnsLazily((Entity e) =>
{
if (e == null)
{
throw new InvalidOperationException("The entity must not be null");
}
if (string.IsNullOrWhiteSpace(e.LogicalName))
{
throw new InvalidOperationException("The LogicalName property must not be empty");
}
if (e.Id != Guid.Empty && context.Data.ContainsKey(e.LogicalName) &&
context.Data[e.LogicalName].ContainsKey(e.Id))
{
throw new InvalidOperationException(string.Format("There is already a record of entity {0} with id {1}, can't create with this Id.", e.LogicalName, e.Id));
}
//Add entity to the context
if (e.Id == Guid.Empty)
{
e.Id = Guid.NewGuid();
//Hack for Dynamic Entities where the Id property doesn't populate the "entitynameid" primary key
if (!e.GetType().IsSubclassOf(typeof(Entity)))
{
var primaryKeyAttribute = string.Format("{0}id", e.LogicalName);
e[primaryKeyAttribute] = e.Id;
}
}
context.AddEntity(e);
return e.Id;
});
}