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


C# XrmFakedContext.CreateQuery方法代码示例

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


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

示例1: When_the_create_task_activity_is_executed_a_task_is_created_in_the_context

        public void When_the_create_task_activity_is_executed_a_task_is_created_in_the_context()
        {
            var fakedContext = new XrmFakedContext();
            fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

            var guid1 = Guid.NewGuid();
            var account = new Account() { Id = guid1 };
            fakedContext.Initialize(new List<Entity>() {
                account
            });

            //Inputs
            var inputs = new Dictionary<string, object>() {
                { "inputEntity", account.ToEntityReference() }
            };

            var result = fakedContext.ExecuteCodeActivity<CreateTaskActivity>(inputs);

            //The wf creates an activity, so make sure it is created
            var tasks = (from t in fakedContext.CreateQuery<Task>()
                         select t).ToList();

            //The activity creates a taks
            Assert.True(tasks.Count == 1);

            var output = result["taskCreated"] as EntityReference;

            //Task created contains the account passed as the regarding Id
            Assert.True(tasks[0].RegardingObjectId != null && tasks[0].RegardingObjectId.Id.Equals(guid1));

            //Same task created is returned
            Assert.Equal(output.Id, tasks[0].Id);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:33,代码来源:FakeContextTestCodeActivities.cs

示例2: Querying_an_early_bound_entity_not_present_in_the_context_should_return_no_records

        public void Querying_an_early_bound_entity_not_present_in_the_context_should_return_no_records()
        {

            var context = new XrmFakedContext();
            context.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

            var service = context.GetFakedOrganizationService();

            //Find the contact
            var contact = (from c in context.CreateQuery<Contact>()
                           select c).ToList();

            Assert.Equal(contact.Count, 0);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:14,代码来源:FakeContextTestCreateQuery.cs

示例3: When_creating_a_record_using_dynamic_entities_primary_key_should_be_populated

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

            Entity e = new Entity("new_myentity");

            IOrganizationService service = context.GetFakedOrganizationService();
            var id = service.Create(e);

            //Retrieve the record created
            var record = (from r in context.CreateQuery("new_myentity")
                          select r).FirstOrDefault();

            Assert.True(record.Attributes.ContainsKey("new_myentityid"));
            Assert.Equal(id, record["new_myentityid"]);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:16,代码来源:FakeContextTestCreate.cs

示例4: When_the_followup_plugin_is_executed_for_an_account_it_should_create_a_new_task

        public void When_the_followup_plugin_is_executed_for_an_account_it_should_create_a_new_task()
        {
            var fakedContext = new XrmFakedContext();
            fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); //Needed to be able to return early bound entities

            var guid1 = Guid.NewGuid();
            var target = new Entity("account") { Id = guid1 };

            fakedContext.ExecutePluginWithTarget<FollowupPlugin>(target);

            //The plugin creates a followup activity, check that that one exists
            var tasks = (from t in fakedContext.CreateQuery<Task>()
                         select t).ToList();

            Assert.True(tasks.Count == 1);
            Assert.True(tasks[0]["subject"].Equals("Send e-mail to the new customer."));
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:17,代码来源:FakeContextTestPlugins.cs

示例5: After_querying_the_context_with_an_invalid_entity_name_exception_is_thrown

        public void After_querying_the_context_with_an_invalid_entity_name_exception_is_thrown()
        {
            var context = new XrmFakedContext();
            context.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

            var service = context.GetFakedOrganizationService();

            var guid = Guid.NewGuid();
            var data = new List<Entity>() {
                new Contact() { Id = guid }
            }.AsQueryable();

            context.Initialize(data);

            Assert.Throws<Exception>(() => {
                var query = (from c in context.CreateQuery("    ")
                             select c);
            });
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:19,代码来源:FakeContextTestCreateQuery.cs

示例6: Should_create_a_new_entity_when_calling_create

        public void Should_create_a_new_entity_when_calling_create()
        {
            var ctx = new XrmFakedContext();
            var logSystem = A.Fake<IDetailedLog>();
            var service = ctx.GetOrganizationService();

            //Arrange
            var actions = new Actions(logSystem, service);
            var contact = new Entity("contact");
            contact["fullname"] = "Lionel Messi";

            //Act
            actions.Create(contact);

            //Assert
            var contactCreated = ctx.CreateQuery("contact").FirstOrDefault();
            Assert.NotNull(contactCreated);
            Assert.Equal(contactCreated["fullname"], "Lionel Messi");
        }
开发者ID:bkanlica,项目名称:CubeXrmFramework,代码行数:19,代码来源:ActionTests.cs

示例7: Should_delete_an_entisting_record_when_calling_delete

        public void Should_delete_an_entisting_record_when_calling_delete()
        {
            var ctx = new XrmFakedContext();
            var logSystem = A.Fake<IDetailedLog>();
            var service = ctx.GetOrganizationService();

            //Arrange
            var contact = new Entity("contact") { Id = Guid.NewGuid() };
            contact["fullname"] = "Lionel Messi";

            ctx.Initialize(new Entity[]
            {
                contact
            });

            //Act
            var actions = new Actions(logSystem, service);
            actions.Delete(contact.Id, "contact");

            //Assert
            var contacts = ctx.CreateQuery("contact").ToList();
            Assert.Equal(0, contacts.Count);
        }
开发者ID:bkanlica,项目名称:CubeXrmFramework,代码行数:23,代码来源:ActionTests.cs

示例8: After_adding_a_contact_the_create_query_returns_it

        public void After_adding_a_contact_the_create_query_returns_it()
        {
            var context = new XrmFakedContext();
            context.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

            var service = context.GetFakedOrganizationService();

            var guid = Guid.NewGuid();
            var data = new List<Entity>() {
                new Contact() { Id = guid }
            }.AsQueryable();

            context.Initialize(data);
            
            //Find the contact
            var contact = (from c in context.CreateQuery<Contact>()
                           where c.ContactId == guid
                           select c).FirstOrDefault();

            
            Assert.False(contact == null);
            Assert.Equal(guid, contact.Id);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:23,代码来源:FakeContextTestCreateQuery.cs

示例9: When_updating_an_entity_using_organization_context_changes_should_be_saved

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

            var existingAccount = new Account() { Id = Guid.NewGuid(), Name = "Super Great Customer", AccountNumber = "69" };

            context.Initialize(new List<Entity>()
            {
                existingAccount
            });

            var service = context.GetFakedOrganizationService();

            using (var ctx = new OrganizationServiceContext(service))
            {
                existingAccount.Name = "Super Great Customer Name Updated!";

                ctx.Attach(existingAccount);
                ctx.UpdateObject(existingAccount);
                ctx.SaveChanges();
            }

            //Make other account wasn't updated
            var account = context.CreateQuery<Account>().Where(e => e.Id == existingAccount.Id).FirstOrDefault();
            Assert.Equal(account.Name, "Super Great Customer Name Updated!");
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:27,代码来源:FakeContextTestUpdate.cs

示例10: When_updating_an_entity_only_one_entity_is_updated

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

            var existingAccount = new Account() { Id = Guid.NewGuid(), Name = "Super Great Customer", AccountNumber = "69" };
            var otherExistingAccount = new Account() { Id = Guid.NewGuid(), Name = "Devil Customer", AccountNumber = "666" };

            context.Initialize(new List<Entity>()
            {
                existingAccount, otherExistingAccount
            });

            var service = context.GetFakedOrganizationService();

            //Create a new entity class to update the first account
            var accountToUpdate = new Account() { Id = existingAccount.Id };
            accountToUpdate.Name = "Super Great Customer Name Updated!";

            //Update the entity in the context
            service.Update(accountToUpdate);

            //Make other account wasn't updated
            var account = context.CreateQuery<Account>().Where(e => e.Id == otherExistingAccount.Id).FirstOrDefault();
            Assert.Equal(account.Name, "Devil Customer");
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:26,代码来源:FakeContextTestUpdate.cs

示例11: When_updating_an_entity_an_unchanged_attribute_remains_the_same

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

            var existingAccount = new Account() { Id = Guid.NewGuid(),  Name = "Super Great Customer", AccountNumber = "69" };
            context.Initialize(new List<Entity>()
            {
                existingAccount
            });

            var service = context.GetFakedOrganizationService();

            //Create a new entity class to update the name
            var accountToUpdate = new Account() { Id = existingAccount.Id };
            accountToUpdate.Name = "Super Great Customer Name Updated!";

            //Update the entity in the context
            service.Update(accountToUpdate);

            //Make sure existing entity still maintains AccountNumber property
            var account = context.CreateQuery<Account>().FirstOrDefault();
            Assert.Equal(account.AccountNumber, "69");
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:24,代码来源:FakeContextTestUpdate.cs

示例12: When_creating_a_record_using_early_bound_entities_primary_key_should_be_populated

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

            var c = new Contact();

            IOrganizationService service = context.GetFakedOrganizationService();
            var id = service.Create(c);

            //Retrieve the record created
            var contact = (from con in context.CreateQuery<Contact>()
                          select con).FirstOrDefault();

            Assert.True(contact.Attributes.ContainsKey("contactid"));
            Assert.Equal(id, contact["contactid"]);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:16,代码来源:FakeContextTestCreate.cs

示例13: Should_update_an_entity_when_calling_update

        public void Should_update_an_entity_when_calling_update()
        {
            var ctx = new XrmFakedContext();
            var logSystem = A.Fake<IDetailedLog>();
            var service = ctx.GetOrganizationService();

            //Arrange
            var contact = new Entity("contact") { Id = Guid.NewGuid() };
            contact["fullname"] = "Lionel Messi";

            ctx.Initialize(new Entity[]
            {
                contact
            });

            //Act
            var contactToUpdate = new Entity("contact") { Id = contact.Id };
            contactToUpdate["fullname"] = "Luis Suárez";

            var actions = new Actions(logSystem, service);
            actions.Update(contactToUpdate);

            //Assert
            var contacts = ctx.CreateQuery("contact").ToList();
            Assert.Equal(1, contacts.Count);
            Assert.Equal(contacts[0]["fullname"], "Luis Suárez");
        }
开发者ID:bkanlica,项目名称:CubeXrmFramework,代码行数:27,代码来源:ActionTests.cs

示例14: When_related_entities_and_relationship_are_used_child_entities_are_created

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

            ctx.AddRelationship("order_details",
                new XrmFakedRelationship()
                {
                    Entity1LogicalName = SalesOrder.EntityLogicalName,  //Referenced
                    Entity1Attribute = "salesorderid",              //Pk
                    Entity2LogicalName = SalesOrderDetail.EntityLogicalName,
                    Entity2Attribute = "salesorderid",              //Lookup attribute
                    RelationshipType = XrmFakedRelationship.enmFakeRelationshipType.OneToMany
                });

            var order = new SalesOrder();

            var orderItems = new EntityCollection(new List<Entity>()
            {
                new SalesOrderDetail(),
                new SalesOrderDetail()
            });

            // Add related order items so it can be created in one request
            order.RelatedEntities.Add(new Relationship
            {
                PrimaryEntityRole = EntityRole.Referenced,
                SchemaName = "order_details"
            }, orderItems);

            var request = new CreateRequest
            {
                Target = order
            };

            var id = (service.Execute(request) as CreateResponse).id;
            var createdOrderDetails = ctx.CreateQuery<SalesOrderDetail>().ToList();

            Assert.Equal(createdOrderDetails.Count, 2);
            Assert.Equal(createdOrderDetails[0].SalesOrderId.Id, id);
            Assert.Equal(createdOrderDetails[1].SalesOrderId.Id, id);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:42,代码来源:FakeContextTestCreate.cs

示例15: When_using_typed_entities_ProxyTypesAssembly_is_not_mandatory

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

            var c = new Contact() { Id = Guid.NewGuid(), FirstName = "Jordi" };
            context.Initialize(new List<Entity>() { c });

            //Linq 2 Query Expression
            using (var ctx = new XrmServiceContext(service))
            {
                var contacts = (from con in ctx.CreateQuery<Contact>()
                                select con).ToList();

                Assert.Equal(contacts.Count, 1);
            }

            //Query faked context directly
            Assert.DoesNotThrow(() => context.CreateQuery<Contact>());
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:20,代码来源:FakeContextTests.cs


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