本文整理汇总了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);
}
示例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);
}
示例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"]);
}
示例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."));
}
示例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);
});
}
示例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");
}
示例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);
}
示例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);
}
示例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!");
}
示例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");
}
示例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");
}
示例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"]);
}
示例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");
}
示例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);
}
示例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>());
}