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


C# XrmFakedContext.Initialize方法代码示例

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


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

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

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

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

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

示例5: Should_set_a_statecode_by_default_when_an_entity_record_is_added_to_the_context

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

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

            //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, 0); //Active
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:19,代码来源:SetStateRequestTests.cs

示例6: Should_Execute_Mock_For_OrganizationRequests

        public void Should_Execute_Mock_For_OrganizationRequests()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            var e = new Entity("Contact") { Id = Guid.NewGuid() };
            context.Initialize(new[] { e });
            context.AddExecutionMock<RetrieveEntityRequest>(RetrieveEntityMock);

            var inputs = new ParameterCollection
            {
                {"Target", e }
            };

            context.ExecutePluginWith<CustomMockPlugin>(inputs, new ParameterCollection(), new EntityImageCollection(), new EntityImageCollection());

            Assert.Equal("Successful", (string)e["response"]);
            Assert.DoesNotThrow(() => context.RemoveExecutionMock<RetrieveEntityRequest>());
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:19,代码来源:FakeContextMockTests.cs

示例7: When_executing_fetchxml_right_result_is_returned

        public void When_executing_fetchxml_right_result_is_returned()
        {
            //This will test a query expression is generated and executed

            var ctx = new XrmFakedContext();
            ctx.Initialize(new List<Entity>()
            {
                new Contact() {Id = Guid.NewGuid(), FirstName = "Leo Messi", Telephone1 = "123" }, //should be returned
                new Contact() {Id = Guid.NewGuid(), FirstName = "Leo Messi", Telephone1 = "234" }, //should be returned
                new Contact() {Id = Guid.NewGuid(), FirstName = "Leo", Telephone1 = "789" }, //shouldnt
                new Contact() {Id = Guid.NewGuid(), FirstName = "Andrés", Telephone1 = "123" }, //shouldnt
            });

            var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                              <entity name='contact'>
                                    <attribute name='fullname' />
                                    <attribute name='telephone1' />
                                    <attribute name='contactid' />
                                        <filter type='and'>
                                            <condition attribute='firstname' operator='like' value='%Leo%' />
                                                <filter type='or'>
                                                    <condition attribute='telephone1' operator='eq' value='123' />
                                                    <condition attribute='telephone1' operator='eq' value='234' />
                                                </filter>
                                        </filter>
                                  </entity>
                            </fetch>";

            var retrieveMultiple = new RetrieveMultipleRequest()
            {
                Query = new FetchExpression(fetchXml)
            };

            var service = ctx.GetFakedOrganizationService();
            var response = service.Execute(retrieveMultiple) as RetrieveMultipleResponse;

            Assert.Equal(2, response.EntityCollection.Entities.Count);

            //Executing the same via ExecuteMultiple returns also the same
            var response2 = service.RetrieveMultiple(retrieveMultiple.Query);
            Assert.Equal(2, response2.Entities.Count);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:42,代码来源:FakeContextTestFetchXmlTranslation.cs

示例8: When_a_query_expression_without_pagination_is_executed_all_records_are_returned

        public void When_a_query_expression_without_pagination_is_executed_all_records_are_returned()
        {
            var context = new XrmFakedContext();

            //Create 20 contacts
            var contactList = new List<Entity>();

            for (var i= 0; i < 20; i++) {
                contactList.Add(new Entity("contact") { Id = Guid.NewGuid() });
            }

            context.Initialize(contactList);

            var qe = new QueryExpression() { EntityName = "contact" };
            qe.ColumnSet = new ColumnSet(true);

            var result = XrmFakedContext.TranslateQueryExpressionToLinq(context, qe).ToList();

            Assert.True(result.Count == 20);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:20,代码来源:PaginationTests.cs

示例9: XrmFakedContext

        public void When_a_query_expression_with_topcount_is_executed_only_a_number_of_records_equals_to_the_page_size_is_returned()
        {
            var context = new XrmFakedContext();

            //Create 20 contacts
            var contactList = new List<Entity>();

            for (var i = 0; i < 20; i++)
            {
                contactList.Add(new Entity("contact") { Id = Guid.NewGuid() });
            }

            context.Initialize(contactList);

            var qe = new QueryExpression() { EntityName = "contact" };
            qe.ColumnSet = new ColumnSet(true);
            qe.TopCount = 10;
            var result = XrmFakedContext.TranslateQueryExpressionToLinq(context, qe).ToList();

            Assert.True(result.Count == 10);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:21,代码来源:PaginationTests.cs

示例10: Should_not_override_a_statecode_already_initialized

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

            var c = new Contact()
            {
                Id = Guid.NewGuid(),
            };

            c["statecode"] = new OptionSetValue(69); //As the StateCode is read only in the early bound entity, this is the only way of updating it
             
            context.Initialize(new[] { c });

            //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); //Set
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:22,代码来源:SetStateRequestTests.cs

示例11: When_filtering_by_an_enum_attribute_and_using_proxy_types_right_result_is_returned

        public void When_filtering_by_an_enum_attribute_and_using_proxy_types_right_result_is_returned()
        {
            var fakedContext = new XrmFakedContext { };

            var entityAccount = new Account { Id = Guid.NewGuid(), Name = "Test Account", LogicalName = "account" };
            var entityContact = new Contact { Id = Guid.NewGuid(), ParentCustomerId = entityAccount.ToEntityReference(), EMailAddress1 = "[email protected]" };

            var entityCase = new Incident
            {
                Id = Guid.NewGuid(),
                PrimaryContactId = entityContact.ToEntityReference(),
                CustomerId = entityAccount.ToEntityReference(),
                Title = "Unit Test Case"
            };

            entityCase["statecode"] = new OptionSetValue((int) IncidentState.Active);

            fakedContext.Initialize(new List<Entity>() {
               entityAccount,entityContact, entityCase
            });


            var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' >
              <entity name='incident' >
                <attribute name='incidentid' />
                <attribute name='statecode' /> 
                <order attribute='createdon' descending='true' /> 
                 <filter type='and' > 
                  <condition attribute='statecode' operator='neq' value='2' /> 
                </filter>
              </entity>
            </fetch>";

            var rows = fakedContext.GetFakedOrganizationService().RetrieveMultiple(new FetchExpression(fetchXml));
            Assert.Equal(rows.Entities.Count, 1);

        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:37,代码来源:FakeContextTestFetchXmlTranslation.cs

示例12: When_filtering_by_a_guid_attribute_and_using_proxy_types_right_result_is_returned

        public void When_filtering_by_a_guid_attribute_and_using_proxy_types_right_result_is_returned()
        {
            var context = new XrmFakedContext();
            context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account));

            var contactId1 = Guid.NewGuid();
            var contactId2 = Guid.NewGuid();

            var account1 = new Account();
            account1.Id = Guid.NewGuid();
            account1.PrimaryContactId = new EntityReference(Contact.EntityLogicalName, contactId1);

            var account2 = new Account();
            account2.Id = Guid.NewGuid();
            account2.PrimaryContactId = new EntityReference(Contact.EntityLogicalName, contactId2);

            context.Initialize(new List<Entity> { account1, account2 });

            var fetchXml =
                 "<fetch>" +
                 "  <entity name='account'>" +
                 "     <attribute name='name'/>" +
                 "     <filter type='and'>" +
                 "         <condition attribute='primarycontactid' operator='eq' value='{0}' />" +
                 "     </filter>" +
                 "  </entity>" +
                 "</fetch>";
            fetchXml = string.Format(fetchXml, contactId1);
            var rows = context.GetFakedOrganizationService().RetrieveMultiple(new FetchExpression(fetchXml));
            Assert.Equal(rows.Entities.Count, 1);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:31,代码来源:FakeContextTestFetchXmlTranslation.cs

示例13: When_filtering_by_a_guid_attribute_right_result_is_returned

        public void When_filtering_by_a_guid_attribute_right_result_is_returned()
        {
            var context = new XrmFakedContext();
            var accountId = Guid.NewGuid();
            var license1 = new Entity("pl_license");
            license1.Id = Guid.NewGuid();
            license1.Attributes["pl_no"] = 1;
            license1.Attributes["pl_accountid"] = new EntityReference("account", accountId);

            var license2 = new Entity("pl_license");
            license2.Id = Guid.NewGuid();
            license2.Attributes["pl_no"] = 2;
            license2.Attributes["pl_accountid"] = new EntityReference("account", accountId);

            context.Initialize(new List<Entity> { license1, license2 });

            var fetchXml =
                 "<fetch>" +
                 "  <entity name='pl_license'>" +
                 "     <attribute name='pl_no'/>" +
                 "     <filter type='and'>" +
                 "         <condition attribute='pl_accountid' operator='eq' value='{0}' />" +
                 "     </filter>" +
                 "  </entity>" +
                 "</fetch>";
            fetchXml = string.Format(fetchXml, accountId);
            var rows = context.GetFakedOrganizationService().RetrieveMultiple(new FetchExpression(fetchXml));
            Assert.Equal(rows.Entities.Count, 2);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:29,代码来源:FakeContextTestFetchXmlTranslation.cs

示例14: When_executing_fetchxml_with_count_attribute_only_that_number_of_results_is_returned

        public void When_executing_fetchxml_with_count_attribute_only_that_number_of_results_is_returned()
        {
            //This will test a query expression is generated and executed

            var ctx = new XrmFakedContext();

            //Arrange
            var contactList = new List<Entity>();
            for(var i=0; i < 20; i++)
            {
                contactList.Add(new Contact() { Id = Guid.NewGuid() });
            }
            ctx.Initialize(contactList);

            //Act
            var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='7'>
                              <entity name='contact'>
                                    <attribute name='fullname' />
                                    <attribute name='telephone1' />
                                    <attribute name='contactid' /> 
                                  </entity>
                            </fetch>";


            var retrieveMultiple = new RetrieveMultipleRequest()
            {
                Query = new FetchExpression(fetchXml)
            };

            var service = ctx.GetFakedOrganizationService();
            var response = service.Execute(retrieveMultiple) as RetrieveMultipleResponse;

            Assert.Equal(7, response.EntityCollection.Entities.Count);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:34,代码来源:FakeContextTestFetchXmlTranslation.cs

示例15: When_ordering_by_entity_reference_fields_expected_result_is_returned

        public void When_ordering_by_entity_reference_fields_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 EntityReference()
            {
                Id = Guid.NewGuid(),
                Name = "Jordi"
            };

            Entity contact2 = new Entity("contact");
            contact2.Id = Guid.NewGuid();
            contact2.Attributes["firstname"] = "Jo";
            contact2.Attributes["lastname"] = "Bloggs";
            contact2.Attributes["new_somefield"] = new EntityReference()
            {
                Id = Guid.NewGuid(),
                Name = "Skuba"
            };

            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.Ascending);
            var results = service.RetrieveMultiple(qry);

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

            Assert.Equal("Jordi", firstResultValue.Name);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:40,代码来源:OrderByTests.cs


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