当前位置: 首页>>代码示例>>C#>>正文


C# XrmFakedContext.FindReflectedType方法代码示例

本文整理汇总了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")));
                    }
                });
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:65,代码来源:XrmFakedContext.Crud.cs


注:本文中的FakeXrmEasy.XrmFakedContext.FindReflectedType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。