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


C# XrmFakedContext.GetFakedOrganizationService方法代码示例

本文整理汇总了C#中XrmFakedContext.GetFakedOrganizationService方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.GetFakedOrganizationService方法的具体用法?C# XrmFakedContext.GetFakedOrganizationService怎么用?C# XrmFakedContext.GetFakedOrganizationService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XrmFakedContext的用法示例。


在下文中一共展示了XrmFakedContext.GetFakedOrganizationService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var assignRequest = (AssignRequest)request;

            var target = assignRequest.Target;
            var assignee = assignRequest.Assignee;

            if (target == null)
            {
                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not assign without target");
            }

            if (assignee == null)
            {
                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not assign without assignee");
            }

            var service = ctx.GetFakedOrganizationService();

            var assignment = new Entity
            {
                LogicalName = target.LogicalName,
                Id = target.Id,
                Attributes = new AttributeCollection
                {
                    { "ownerid", assignee }
                }
            };

            service.Update(assignment);

            return new AssignResponse();
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:33,代码来源:AssignRequestExecutor.cs

示例2: When_ordering_by_money_fields_descending_expected_result_is_returned

        public void When_ordering_by_money_fields_descending_expected_result_is_returned()
        {
            List<Entity> contactList = new List<Entity>();

            Entity contact1 = new Entity("contact");
            contact1.Id = Guid.NewGuid();
            contact1.Attributes["firstname"] = "Fred";
            contact1.Attributes["lastname"] = "Bloggs";
            contact1.Attributes["new_somefield"] = new Money(12345); // (decimal)678910 

            Entity contact2 = new Entity("contact");
            contact2.Id = Guid.NewGuid();
            contact2.Attributes["firstname"] = "Jo";
            contact2.Attributes["lastname"] = "Bloggs";
            contact2.Attributes["new_somefield"] = new Money(678910); // (decimal)678910 


            contactList.Add(contact2);
            contactList.Add(contact1);

            var context = new XrmFakedContext();
            context.Initialize(contactList);
            var service = context.GetFakedOrganizationService();

            QueryExpression qry = new QueryExpression("contact");
            qry.ColumnSet = new ColumnSet(true);
            qry.AddOrder("new_somefield", OrderType.Descending);
            var results = service.RetrieveMultiple(qry);

            var firstResultValue = results.Entities[0]["new_somefield"] as Money;

            Assert.Equal(678910M, firstResultValue.Value);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:33,代码来源:OrderByTests.cs

示例3: When_set_state_request_is_called_an_entity_is_updated

        public void When_set_state_request_is_called_an_entity_is_updated()
        {
            var context = new XrmFakedContext();
            context.ProxyTypesAssembly = Assembly.GetExecutingAssembly();
            var service = context.GetFakedOrganizationService();

            var c = new Contact() {
                Id = Guid.NewGuid()
            }; 
            context.Initialize(new[] { c });

            var request = new SetStateRequest
            {
                EntityMoniker = c.ToEntityReference(),
                State = new OptionSetValue(69), 
                Status = new OptionSetValue(6969),
            };

            var response = service.Execute(request);

            //Retrieve record after update
            var contact = (from con in context.CreateQuery<Contact>()
                           where con.Id == c.Id
                           select con).FirstOrDefault();

            Assert.Equal((int) contact.StateCode.Value, 69);
            Assert.Equal((int) contact.StatusCode.Value, 6969);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:28,代码来源:SetStateRequestTests.cs

示例4: When_ordering_by_datetime_fields_expected_result_is_returned

        public void When_ordering_by_datetime_fields_expected_result_is_returned()
        {
            List<Entity> contactList = new List<Entity>();

            var now = DateTime.UtcNow;
            Entity contact1 = new Entity("contact");
            contact1.Id = Guid.NewGuid();
            contact1.Attributes["firstname"] = "Fred";
            contact1.Attributes["new_orderbyfield"] = now;

            Entity contact2 = new Entity("contact");
            contact2.Id = Guid.NewGuid();
            contact2.Attributes["firstname"] = "Jo";
            contact2.Attributes["new_orderbyfield"] = now.AddDays(1);

            contactList.Add(contact2);
            contactList.Add(contact1);

            var context = new XrmFakedContext();
            context.Initialize(contactList);
            var service = context.GetFakedOrganizationService();

            QueryExpression qry = new QueryExpression("contact");
            qry.ColumnSet = new ColumnSet(true);
            qry.AddOrder("new_orderbyfield", OrderType.Ascending);
            var results = service.RetrieveMultiple(qry);

            var firstResultValue = (DateTime)results.Entities[0]["new_orderbyfield"];

            Assert.Equal(now, firstResultValue);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:31,代码来源:OrderByTests.cs

示例5: When_Executing_Assign_Request_New_Owner_Should_Be_Assigned

        public void When_Executing_Assign_Request_New_Owner_Should_Be_Assigned()
        {
            var oldOwner = new EntityReference("systemuser", Guid.NewGuid());
            var newOwner = new EntityReference("systemuser", Guid.NewGuid());

            var account = new Account
            {
                Id = Guid.NewGuid(),
                OwnerId = oldOwner
            };

            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            context.Initialize(new [] { account });

            var assignRequest = new AssignRequest
            {
                Target = account.ToEntityReference(),
                Assignee = newOwner
            };
            service.Execute(assignRequest);

            Assert.Equal(newOwner, account.OwnerId);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:25,代码来源:FakeContextTestExecute.cs

示例6: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var associateRequest = request as AssociateRequest;
            var service = ctx.GetFakedOrganizationService();

            if (associateRequest == null)
            {
                throw new Exception("Only associate request can be processed!");
            }

            var associateRelationship = associateRequest.Relationship;
            var relationShipName = associateRelationship.SchemaName;
            var fakeRelationShip = ctx.GetRelationship(relationShipName);

            if (fakeRelationShip == null)
            {
                throw new Exception(string.Format("Relationship {0} does not exist in the metadata cache", relationShipName));
            }

            if (associateRequest.Target == null)
            {
                throw new Exception("Association without target is invalid!");
            }

            foreach (var relatedEntityReference in associateRequest.RelatedEntities)
            {
                if (fakeRelationShip.RelationshipType == XrmFakedRelationship.enmFakeRelationshipType.ManyToMany)
                {
                    var association = new Entity(fakeRelationShip.IntersectEntity)
                    {
                        Attributes = new AttributeCollection
                        {
                            { fakeRelationShip.Entity1Attribute, associateRequest.Target.Id },
                            { fakeRelationShip.Entity2Attribute, relatedEntityReference.Id }
                        }
                    };

                    service.Create(association);
                }
                else
                {
                    //One to many
                    //Get entity to update
                    var entityToUpdate = new Entity(relatedEntityReference.LogicalName)
                    {
                        Id = relatedEntityReference.Id
                    };

                    entityToUpdate[fakeRelationShip.Entity2Attribute] = associateRequest.Target;
                    service.Update(entityToUpdate);
                }

            }

            return new AssociateResponse ();
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:56,代码来源:AssociateRequestExecutor.cs

示例7: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var createRequest = (CreateRequest)request;
            
            var service = ctx.GetFakedOrganizationService();

            service.Create(createRequest.Target);

            return new CreateResponse();
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:10,代码来源:CreateRequestExecutor.cs

示例8: When_calling_publish_xml_no_exception_is_raised

        public void When_calling_publish_xml_no_exception_is_raised()
        {
            var ctx = new XrmFakedContext();
            var service = ctx.GetFakedOrganizationService();

            var req = new PublishXmlRequest()
            {
                ParameterXml = "<somexml></somexml>"
            };

            Assert.DoesNotThrow(() => service.Execute(req));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:12,代码来源:PublishXmlRequestTests.cs

示例9: When_calling_publish_xml_exception_is_raised_if_parameter_xml_is_blank

        public void When_calling_publish_xml_exception_is_raised_if_parameter_xml_is_blank()
        {
            var ctx = new XrmFakedContext();
            var service = ctx.GetFakedOrganizationService();

            var req = new PublishXmlRequest()
            {
                ParameterXml = ""
            };

            Assert.Throws<Exception>(() => service.Execute(req));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:12,代码来源:PublishXmlRequestTests.cs

示例10: When_calling_insert_option_set_value_without_optionsetname_exception_is_thrown

        public void When_calling_insert_option_set_value_without_optionsetname_exception_is_thrown()
        {
            var ctx = new XrmFakedContext();
            var service = ctx.GetFakedOrganizationService();

            var req = new InsertOptionValueRequest()
            {
                Label = new Label("Yeah! This is a fake label!", 0)
            };

            Assert.Throws<Exception>(() => service.Execute(req));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:12,代码来源:OptionSetValueRequestsTests.cs

示例11: When_retrieve_attribute_request_is_called_an_exception_is_not_thrown

        public static void When_retrieve_attribute_request_is_called_an_exception_is_not_thrown()
        {
            var context = new XrmFakedContext();
            
            var service = context.GetFakedOrganizationService();
            RetrieveAttributeRequest req = new RetrieveAttributeRequest()
            {
                EntityLogicalName = "account",
                LogicalName = "name"
            };

            Assert.Throws<PullRequestException>(() => service.Execute(req));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:13,代码来源:RetrieveAttributeRequestTests.cs

示例12: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var createRequest = (CreateRequest)request;

            var service = ctx.GetFakedOrganizationService();

            var guid = service.Create(createRequest.Target);

            return new CreateResponse()
            {
                ResponseName = "Create",
                Results = new ParameterCollection { { "id", guid } }
            };
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:14,代码来源:CreateRequestExecutor.cs

示例13: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var deleteRequest = (DeleteRequest)request;

            var target = deleteRequest.Target;

            if (target == null)
            {
                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not delete without target");
            }

            var service = ctx.GetFakedOrganizationService();
            service.Delete(target.LogicalName, target.Id);

            return new DeleteResponse();
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:16,代码来源:DeleteRequestExecutor.cs

示例14: Should_Execute_Subsequent_Requests

        public static void Should_Execute_Subsequent_Requests()
        {
            var context = new XrmFakedContext();

            var service = context.GetFakedOrganizationService();

            var account1 = new Account
            {
                Id = Guid.NewGuid(),
                Name = "Acc1"
            };

            var account2 = new Account
            {
                Id = Guid.NewGuid(),
                Name = "Acc2"
            };

            var executeMultipleRequest = new ExecuteMultipleRequest
            {
                Settings = new ExecuteMultipleSettings
                {
                    ReturnResponses = true
                },
                Requests = new OrganizationRequestCollection
                {
                    new CreateRequest
                    {
                        Target = account1
                    },

                    new CreateRequest
                    {
                        Target = account2
                    }
                }
            };

            var response = service.Execute(executeMultipleRequest) as ExecuteMultipleResponse;
            
            Assert.False(response.IsFaulted);
            Assert.NotEmpty(response.Responses);

            Assert.NotNull(service.Retrieve(Account.EntityLogicalName, account1.Id, new ColumnSet(true)));
            Assert.NotNull(service.Retrieve(Account.EntityLogicalName, account2.Id, new ColumnSet(true)));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:46,代码来源:ExecuteMultipleRequestTests.cs

示例15: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var disassociateRequest = request as DisassociateRequest;
            var service = ctx.GetFakedOrganizationService();

            if (disassociateRequest == null)
            {
                throw new Exception("Only disassociate request can be processed!");
            }

            var relationShipName = disassociateRequest.Relationship.SchemaName;
            var relationShip = ctx.GetRelationship(relationShipName);

            if (relationShip == null)
            {
                throw new Exception(string.Format("Relationship {0} does not exist in the metadata cache", relationShipName));
            }

            if (disassociateRequest.Target == null)
            {
                throw new Exception("Disassociation without target is invalid!");
            }

            foreach (var relatedEntity in disassociateRequest.RelatedEntities)
            {
                var query = new QueryExpression(relationShip.IntersectEntity)
                {
                    ColumnSet = new ColumnSet(true),
                    Criteria = new FilterExpression(LogicalOperator.And)
                };

                query.Criteria.AddCondition(new ConditionExpression(relationShip.Entity1Attribute,
                    ConditionOperator.Equal, disassociateRequest.Target.Id));
                query.Criteria.AddCondition(new ConditionExpression(relationShip.Entity2Attribute,
                    ConditionOperator.Equal, relatedEntity.Id));

                var results = service.RetrieveMultiple(query);

                if (results.Entities.Count == 1)
                {
                    service.Delete(relationShip.IntersectEntity, results.Entities.First().Id);
                }
            }

            return new DisassociateResponse();
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:46,代码来源:DisassociateRequestExecutor.cs


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