コード例 #1
0
        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));
                }
            });
        }
コード例 #2
0
        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));
                    }
                });
        }