• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# XrmFakedContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



XrmFakedContext类属于命名空间,在下文中一共展示了XrmFakedContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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_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


示例3: 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


示例4: When_execute_is_called_with_a_null_target_exception_is_thrown

 public void When_execute_is_called_with_a_null_target_exception_is_thrown()
 {
     var context = new XrmFakedContext();
     var executor = new AssignRequestExecutor();
     AssignRequest req = new AssignRequest() { Target = null };
     Assert.Throws<FaultException<OrganizationServiceFault>>(() => executor.Execute(req, context));
 }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:7,代码来源:AssignRequestTests.cs


示例5: ProjectAttributes

        public static void ProjectAttributes(Entity e, Entity projected, LinkEntity le, XrmFakedContext context)
        {
            var sAlias = string.IsNullOrWhiteSpace(le.EntityAlias) ? le.LinkToEntityName : le.EntityAlias;

            if (le.Columns.AllColumns && le.Columns.Columns.Count == 0)
            {
                foreach (var attKey in e.Attributes.Keys)
                {
                    if(attKey.StartsWith(sAlias + "."))
                    {
                        projected[attKey] = e[attKey];
                    }
                }
            }
            else
            {
                foreach (var attKey in le.Columns.Columns)
                {

                    var linkedAttKey = sAlias + "." + attKey;
                    if (e.Attributes.ContainsKey(linkedAttKey))
                        projected[linkedAttKey] = e[linkedAttKey];
                }
            }
            

            foreach (var nestedLinkedEntity in le.LinkEntities)
            {
                ProjectAttributes(e, projected, nestedLinkedEntity, context);
            }
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:31,代码来源:EntityExtensions.cs


示例6: 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


示例7: When_translating_a_fetch_xml_attribute_node_must_have_a_name_attribute

        public void When_translating_a_fetch_xml_attribute_node_must_have_a_name_attribute()
        {
            var ctx = new XrmFakedContext();

            Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><attribute></attribute></entity></fetch>"));
            Assert.DoesNotThrow(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><attribute name='firstname'></attribute></entity></fetch>"));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:7,代码来源:FakeContextTestFetchXmlTranslation.cs


示例8: 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


示例9: When_execute_is_called_with_a_null_request_exception_is_thrown

 public void When_execute_is_called_with_a_null_request_exception_is_thrown()
 {
     var context = new XrmFakedContext();
     var executor = new AssociateRequestExecutor();
     AssociateRequest req = null;
     Assert.Throws<Exception>(() => executor.Execute(req, context));
 }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:7,代码来源:AssociateRequestTests.cs


示例10: When_execute_is_called_with_a_null_target_exception_is_thrown

 public void When_execute_is_called_with_a_null_target_exception_is_thrown()
 {
     var context = new XrmFakedContext();
     var executor = new AssociateRequestExecutor();
     var req = new AssociateRequest() { Target = null, Relationship = new Relationship("fakeRelationship") };
     context.AddRelationship("fakeRelationship", new XrmFakedRelationship());
     Assert.Throws<Exception>(() => executor.Execute(req, context));
 }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:8,代码来源:AssociateRequestTests.cs


示例11: XrmFakedContext

        public void When_translating_a_fetch_xml_expression_first_node_must_be_a_fetch_element_otherwise_exception_is_thrown()
        {
            var ctx = new XrmFakedContext();

            Assert.DoesNotThrow(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'></entity></fetch>"));
            Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<attribute></attribute>"));
            Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<entity></entity>"));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:8,代码来源:FakeContextTestFetchXmlTranslation.cs


示例12: When_translating_a_fetch_xml_order_node_must_have_2_attributes

        public void When_translating_a_fetch_xml_order_node_must_have_2_attributes()
        {
            var ctx = new XrmFakedContext();

            Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order></order></entity></fetch>"));
            Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order attribute=''></order></entity></fetch>"));
            Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order descending=''></order></entity></fetch>"));
            Assert.DoesNotThrow(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order attribute='firstname' descending='true'></order></entity></fetch>"));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:9,代码来源:FakeContextTestFetchXmlTranslation.cs


示例13: 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


示例14: 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


示例15: 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


示例16: Execute

        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var req = request as WhoAmIRequest;

            var response = new WhoAmIResponse
            {
                Results = new ParameterCollection
                                { { "UserId", ctx.CallerId.Id } }

            };
            return response;
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:12,代码来源:WhoAmIRequestExecutor.cs


示例17: When_translating_a_fetch_xml_expression_queryexpression_name_matches_entity_node

        public void When_translating_a_fetch_xml_expression_queryexpression_name_matches_entity_node()
        {
            var ctx = new XrmFakedContext();
            var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                              <entity name='contact'>
                              </entity>
                            </fetch>";

            var query = XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, fetchXml);

            Assert.True(query.EntityName.Equals("contact"));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:12,代码来源:FakeContextTestFetchXmlTranslation.cs


示例18: 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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XrmServiceContext类代码示例发布时间:2022-05-24
下一篇:
C# XpsDocument类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap