本文整理汇总了C#中FakeXrmEasy.XrmFakedContext.FindReflectedType方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.FindReflectedType方法的具体用法?C# XrmFakedContext.FindReflectedType怎么用?C# XrmFakedContext.FindReflectedType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FakeXrmEasy.XrmFakedContext
的用法示例。
在下文中一共展示了XrmFakedContext.FindReflectedType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FakeRetrieve
/// <summary>
/// A fake retrieve method that will query the FakedContext to retrieve the specified
/// entity and Guid, or null, if the entity was not found
/// </summary>
/// <param name="context">The faked context</param>
/// <param name="fakedService">The faked service where the Retrieve method will be faked</param>
/// <returns></returns>
protected static void FakeRetrieve(XrmFakedContext context, IOrganizationService fakedService)
{
A.CallTo(() => fakedService.Retrieve(A<string>._, A<Guid>._, A<ColumnSet>._))
.ReturnsLazily((string entityName, Guid id, ColumnSet columnSet) =>
{
if (string.IsNullOrWhiteSpace(entityName))
{
throw new InvalidOperationException("The entity logical name must not be null or empty.");
}
if (id == Guid.Empty)
{
throw new InvalidOperationException("The id must not be empty.");
}
if (columnSet == null)
{
throw new InvalidOperationException("The columnset parameter must not be null.");
}
// Don't fail with invalid operation exception, if no record of this entity exists, but entity is known
if (!context.Data.ContainsKey(entityName))
{
if (context.ProxyTypesAssembly == null)
{
throw new InvalidOperationException(string.Format("The entity logical name {0} is not valid.",
entityName));
}
if (!context.ProxyTypesAssembly.GetTypes().Any(type => context.FindReflectedType(entityName) != null))
{
throw new InvalidOperationException(string.Format("The entity logical name {0} is not valid.",
entityName));
}
}
//Entity logical name exists, so , check if the requested entity exists
if (context.Data.ContainsKey(entityName) && context.Data[entityName] != null
&& context.Data[entityName].ContainsKey(id))
{
//Entity found => return only the subset of columns specified or all of them
if (columnSet.AllColumns)
return context.Data[entityName][id];
else
{
//Return the subset of columns requested only
var foundEntity = context.Data[entityName][id];
Entity projected = foundEntity.ProjectAttributes(columnSet,context);
return projected;
}
}
else
{
//Entity not found in the context => return null
throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("{0} With Id = {1} Does Not Exist", entityName, id.ToString("D")));
}
});
}