本文整理汇总了C#中FakeXrmEasy.XrmFakedContext类的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext类的具体用法?C# XrmFakedContext怎么用?C# XrmFakedContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XrmFakedContext类属于FakeXrmEasy命名空间,在下文中一共展示了XrmFakedContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: 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
示例3: When_an_entity_is_created_with_an_empty_logical_name_an_exception_is_thrown
public void When_an_entity_is_created_with_an_empty_logical_name_an_exception_is_thrown()
{
var context = new XrmFakedContext();
var service = context.GetFakedOrganizationService();
var e = new Entity("") { Id = Guid.Empty };
var ex = Assert.Throws<InvalidOperationException>(() => service.Create(e));
Assert.Equal(ex.Message, "The LogicalName property must not be empty");
}
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:10,代码来源:FakeContextTestCreate.cs
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: 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:ccellar,项目名称:fake-xrm-easy,代码行数:31,代码来源:FakeContextTestLinqQueries.cs
示例9: 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
示例10: 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
示例11: 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
示例12: When_retrieve_is_invoked_with_an_empty_guid_an_exception_is_thrown
public void When_retrieve_is_invoked_with_an_empty_guid_an_exception_is_thrown()
{
var context = new XrmFakedContext();
var service = context.GetFakedOrganizationService();
var ex = Assert.Throws<InvalidOperationException>(() => service.Retrieve("account", Guid.Empty, new ColumnSet()));
Assert.Equal(ex.Message, "The id must not be empty.");
}
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:8,代码来源:FakeContextTestRetrieve.cs
示例13: When_retrieve_is_invoked_with_a_null_columnset_exception_is_thrown
public void When_retrieve_is_invoked_with_a_null_columnset_exception_is_thrown()
{
var context = new XrmFakedContext();
var service = context.GetFakedOrganizationService();
var ex = Assert.Throws<InvalidOperationException>(() => service.Retrieve("account", Guid.NewGuid(), null));
Assert.Equal(ex.Message, "The columnset parameter must not be null.");
}
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:8,代码来源:FakeContextTestRetrieve.cs
示例14: When_a_null_entity_is_created_an_exception_is_thrown
public void When_a_null_entity_is_created_an_exception_is_thrown()
{
var context = new XrmFakedContext();
var service = context.GetFakedOrganizationService();
var ex = Assert.Throws<InvalidOperationException>(() => service.Create(null));
Assert.Equal(ex.Message, "The entity must not be null");
}
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:8,代码来源:FakeContextTestCreate.cs
示例15: When_getting_a_fake_service_reference_it_uses_a_singleton_pattern
public void When_getting_a_fake_service_reference_it_uses_a_singleton_pattern()
{
var context = new XrmFakedContext();
var service = context.GetFakedOrganizationService();
var service2 = context.GetFakedOrganizationService();
Assert.Equal(service, service2);
}
开发者ID:DigitalFlow,项目名称:fake-xrm-easy,代码行数:8,代码来源:FakeContextTests.cs
示例16: FakeRetrieve
/// <summary>
/// A fake retrieve method that will query the FakedContext to retrieve the specified
/// entity and Guid, or null, if the entity was not found
/// </summary>
/// <param name="context">The faked context</param>
/// <param name="fakedService">The faked service where the Retrieve method will be faked</param>
/// <returns></returns>
protected static void FakeRetrieve(XrmFakedContext context, IOrganizationService fakedService)
{
A.CallTo(() => fakedService.Retrieve(A<string>._, A<Guid>._, A<ColumnSet>._))
.ReturnsLazily((string entityName, Guid id, ColumnSet columnSet) =>
{
if (string.IsNullOrWhiteSpace(entityName))
{
throw new InvalidOperationException("The entity logical name must not be null or empty.");
}
if (id == Guid.Empty)
{
throw new InvalidOperationException("The id must not be empty.");
}
if (columnSet == null)
{
throw new InvalidOperationException("The columnset parameter must not be null.");
}
// Don't fail with invalid operation exception, if no record of this entity exists, but entity is known
if (!context.Data.ContainsKey(entityName))
{
if (context.ProxyTypesAssembly == null)
{
throw new InvalidOperationException(string.Format("The entity logical name {0} is not valid.",
entityName));
}
if (!context.ProxyTypesAssembly.GetTypes().Any(type => context.FindReflectedType(entityName) != null))
{
throw new InvalidOperationException(string.Format("The entity logical name {0} is not valid.",
entityName));
}
}
//Entity logical name exists, so , check if the requested entity exists
if (context.Data.ContainsKey(entityName) && context.Data[entityName] != null
&& context.Data[entityName].ContainsKey(id))
{
//Entity found => return only the subset of columns specified or all of them
if (columnSet.AllColumns)
return context.Data[entityName][id];
else
{
//Return the subset of columns requested only
var foundEntity = context.Data[entityName][id];
Entity projected = foundEntity.ProjectAttributes(columnSet,context);
return projected;
}
}
else
{
//Entity not found in the context => return null
throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("{0} With Id = {1} Does Not Exist", entityName, id.ToString("D")));
}
});
}
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:65,代码来源:XrmFakedContext.Crud.cs
示例17: FakeRetrieveAttributeRequest
/// <summary>
/// Fakes the RetrieveAttributeRequest that checks if an attribute exists for a given entity
/// For simpicity, it asumes all attributes exist
/// </summary>
/// <param name="context"></param>
/// <param name="fakedService"></param>
protected static OrganizationResponse FakeRetrieveAttributeRequest(XrmFakedContext context, IOrganizationService fakedService, RetrieveAttributeRequest req)
{
var response = new RetrieveAttributeResponse
{
};
return response;
}
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:15,代码来源:XrmFakedContext.Metadata.cs
示例18: 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
示例19: AccountTests
// Test class constructor
public AccountTests()
{
// Create fake service
fakeContext = new XrmFakedContext();
fakeService = fakeContext.GetOrganizationService();
// Create real service
realContext = new MyContext("XRM");
realService = realContext.GetOrganizationService();
}
开发者ID:BISmb,项目名称:Projects,代码行数:11,代码来源:AccountTests.cs
示例20: 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
注:本文中的FakeXrmEasy.XrmFakedContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论