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


C# XrmFakedContext.Initialize方法代码示例

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


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

示例1: XrmFakedContext

        public void When_doing_a_crm_linq_query_and_proxy_types_and_a_selected_attribute_returned_projected_entity_is_thesubclass()
        {
            var fakedContext = new XrmFakedContext();
            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, FirstName = "Jordi" },
                new Contact() { Id = guid2, FirstName = "Other" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("Jordi")
                               select new
                               {
                                   FirstName = c.FirstName,
                                   CrmRecord = c
                               }).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));
                Assert.IsAssignableFrom(typeof(Contact), matches[0].CrmRecord);
                Assert.True(matches[0].CrmRecord.GetType() == typeof(Contact));

            }
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:30,代码来源:FakeContextTestLinqQueries.cs

示例2: When_doing_a_crm_linq_query_with_an_equals_operator_record_is_returned

        public void When_doing_a_crm_linq_query_with_an_equals_operator_record_is_returned()
        {
            var fakedContext = new XrmFakedContext();
            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, FirstName = "Jordi" },
                new Contact() { Id = guid2, FirstName = "Other" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("Jordi")
                               select c).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));

                matches = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName == "Jordi" //Using now equality operator
                               select c).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));
            }
            
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:31,代码来源:FakeContextTestLinqQueries.cs

示例3: When_executing_a_query_expression_with_2_filters_combined_with_an_or_filter_right_result_is_returned

        public void When_executing_a_query_expression_with_2_filters_combined_with_an_or_filter_right_result_is_returned()
        {
            var context = new XrmFakedContext();
            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1"; contact1["firstname"] = "First 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2"; contact2["firstname"] = "First 2";

            context.Initialize(new List<Entity>() { contact1, contact2 });

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

            var filter1 = new FilterExpression();
            filter1.AddCondition(new ConditionExpression("fullname", ConditionOperator.Equal, "Contact 1"));

            var filter2 = new FilterExpression();
            filter2.AddCondition(new ConditionExpression("fullname", ConditionOperator.Equal, "Contact 2"));

            qe.Criteria = new FilterExpression(LogicalOperator.Or);
            qe.Criteria.AddFilter(filter1);
            qe.Criteria.AddFilter(filter2);

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

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

示例4: When_initialising_the_context_twice_exception_is_thrown

 public void When_initialising_the_context_twice_exception_is_thrown()
 {
     var context = new XrmFakedContext();
     var c = new Contact() { Id = Guid.NewGuid(), FirstName = "Lionel" };
     Assert.DoesNotThrow(() => context.Initialize(new List<Entity>() { c }));
     Assert.Throws<Exception>(() => context.Initialize(new List<Entity>() { c }));
 }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:7,代码来源:FakeContextTests.cs

示例5: When_using_proxy_types_assembly_the_attribute_metadata_is_inferred_from_the_proxy_types_assembly

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

            var contact1 = new Entity("contact") { Id = Guid.NewGuid() }; contact1["fullname"] = "Contact 1"; contact1["firstname"] = "First 1";
            var contact2 = new Entity("contact") { Id = Guid.NewGuid() }; contact2["fullname"] = "Contact 2"; contact2["firstname"] = "First 2";

            fakedContext.Initialize(new List<Entity>() { contact1, contact2 });

            var guid = Guid.NewGuid();

            //Empty contecxt (no Initialize), but we should be able to query any typed entity without an entity not found exception

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var contact = (from c in ctx.CreateQuery<Contact>()
                               where c.FirstName.Equals("First 1")
                               select c).ToList();

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

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

示例7: Should_Not_Change_Context_Objects_Without_Update

        public void Should_Not_Change_Context_Objects_Without_Update()
        {
            var entityId = Guid.NewGuid();
            var context = new XrmFakedContext();
            var service = context.GetOrganizationService();

            context.Initialize(new[] {
                new Entity ("account")
                {
                    Id = entityId,
                    Attributes = new AttributeCollection
                    {
                        { "accountname", "Adventure Works" }
                    }
                }
            });

            var firstRetrieve = service.Retrieve("account", entityId, new ColumnSet(true));
            var secondRetrieve = service.Retrieve("account", entityId, new ColumnSet(true));

            firstRetrieve["accountname"] = "Updated locally";

            Assert.Equal("Updated locally", firstRetrieve["accountname"]);
            Assert.Equal("Adventure Works", secondRetrieve["accountname"]);
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:25,代码来源:FakeContextTestUpdate.cs

示例8: When_a_query_by_attribute_is_executed_when_one_attribute_right_result_is_returned

        public static void When_a_query_by_attribute_is_executed_when_one_attribute_right_result_is_returned()
        {
            var context = new XrmFakedContext();
            var account = new Account() {Id = Guid.NewGuid(), Name = "Test"};
            var account2 = new Account() { Id = Guid.NewGuid(), Name = "Other account!" };
            context.Initialize(new List<Entity>()
            {
                account, account2
            });

            var service = context.GetFakedOrganizationService();

            QueryByAttribute query = new QueryByAttribute();
            query.Attributes.AddRange(new string[] { "name" });
            query.ColumnSet = new ColumnSet(new string[] { "name" });
            query.EntityName = Account.EntityLogicalName;
            query.Values.AddRange(new object[] { "Test" });

            //Execute using a request to test the OOB (XRM) message contracts
            RetrieveMultipleRequest request = new RetrieveMultipleRequest();
            request.Query = query;
            Collection<Entity> entityList = ((RetrieveMultipleResponse)service.Execute(request)).EntityCollection.Entities;

            Assert.True(entityList.Count == 1);
            Assert.Equal(entityList[0]["name"].ToString(), "Test");
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:26,代码来源:QueryByAttributeTests.cs

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

示例10: When_doing_a_crm_linq_query_and_proxy_types_projection_must_be_applied_after_where_clause

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

            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();

            fakedContext.Initialize(new List<Entity>() {
                new Contact() { Id = guid1, FirstName = "Jordi", LastName = "Montana" },
                new Contact() { Id = guid2, FirstName = "Other" }
            });

            var service = fakedContext.GetFakedOrganizationService();

            using (XrmServiceContext ctx = new XrmServiceContext(service))
            {
                var matches = (from c in ctx.CreateQuery<Contact>()
                               where c.LastName == "Montana"  //Should be able to filter by a non-selected attribute
                               select new
                               {
                                   FirstName = c.FirstName
                               }).ToList();

                Assert.True(matches.Count == 1);
                Assert.True(matches[0].FirstName.Equals("Jordi"));
            }
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:28,代码来源:FakeContextTestLinqQueries.cs

示例11: When_initializing_the_context_with_an_entity_with_an_empty_guid_an_exception_is_thrown

        public void When_initializing_the_context_with_an_entity_with_an_empty_guid_an_exception_is_thrown()
        {
            var context = new XrmFakedContext();
            IEnumerable<Entity> data = new List<Entity>() {
                new Entity("account") { Id = Guid.Empty }
            };

            var ex = Assert.Throws<InvalidOperationException>(() => context.Initialize(data));
            Assert.Equal(ex.Message, "An entity with an empty Id can't be added");
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:10,代码来源:FakeContextTests.cs

示例12: When_initializing_the_context_with_an_entity_with_an_empty_logical_name_an_exception_is_thrown

        public void When_initializing_the_context_with_an_entity_with_an_empty_logical_name_an_exception_is_thrown()
        {
            var context = new XrmFakedContext();
            IEnumerable<Entity> data = new List<Entity>() {
                new Entity() { Id = Guid.NewGuid()}
            };

            var ex = Assert.Throws<InvalidOperationException>(() => context.Initialize(data));
            Assert.Equal(ex.Message, "An entity must not have a null or empty LogicalName property.");
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:10,代码来源:FakeContextTests.cs

示例13: When_initializing_the_context_with_a_dynamic_entity_with_a_primary_key_is_added_to_the_context

        public void When_initializing_the_context_with_a_dynamic_entity_with_a_primary_key_is_added_to_the_context()
        {
            var context = new XrmFakedContext();
            IEnumerable<Entity> data = new List<Entity>() {
                new Entity("account") { Id = Guid.NewGuid(), Attributes = new AttributeCollection { { "accountid", Guid.NewGuid() } }  }
            };

            Assert.DoesNotThrow(() => context.Initialize(data));
            Assert.True(context.Data.Count == 1);
            Assert.True(context.Data["account"].Count == 1);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:11,代码来源:FakeContextTests.cs

示例14: XrmFakedContext

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

            var e = new Entity("account") { Id = Guid.NewGuid() };
            context.Initialize(new List<Entity>() { e });

            Assert.True(e.Attributes.ContainsKey("createdon"));
            Assert.True(e.Attributes.ContainsKey("modifiedon"));
            Assert.True(e.Attributes.ContainsKey("createdby"));
            Assert.True(e.Attributes.ContainsKey("modifiedby"));
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:13,代码来源:FakeContextTests.cs

示例15: When_initializing_the_context_with_an_entity_the_context_has_that_entity

        public void When_initializing_the_context_with_an_entity_the_context_has_that_entity()
        {
            var context = new XrmFakedContext();
            var guid = Guid.NewGuid();

            IQueryable<Entity> data = new List<Entity>() {
                new Entity("account") { Id = guid }
            }.AsQueryable();

            context.Initialize(data);
            Assert.True(context.Data.Count == 1);
            Assert.True(context.Data["account"].Count == 1);
            Assert.Equal(context.Data["account"][guid], data.FirstOrDefault());
        }
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:14,代码来源:FakeContextTests.cs


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