本文整理汇总了C#中XrmFakedContext类的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext类的具体用法?C# XrmFakedContext怎么用?C# XrmFakedContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XrmFakedContext类属于命名空间,在下文中一共展示了XrmFakedContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
{
var assignRequest = (AssignRequest)request;
var target = assignRequest.Target;
var assignee = assignRequest.Assignee;
if (target == null)
{
throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not assign without target");
}
if (assignee == null)
{
throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not assign without assignee");
}
var service = ctx.GetFakedOrganizationService();
var assignment = new Entity
{
LogicalName = target.LogicalName,
Id = target.Id,
Attributes = new AttributeCollection
{
{ "ownerid", assignee }
}
};
service.Update(assignment);
return new AssignResponse();
}
示例2: 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);
}
示例3: 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);
}
示例4: When_execute_is_called_with_a_null_target_exception_is_thrown
public void When_execute_is_called_with_a_null_target_exception_is_thrown()
{
var context = new XrmFakedContext();
var executor = new AssignRequestExecutor();
AssignRequest req = new AssignRequest() { Target = null };
Assert.Throws<FaultException<OrganizationServiceFault>>(() => executor.Execute(req, context));
}
示例5: ProjectAttributes
public static void ProjectAttributes(Entity e, Entity projected, LinkEntity le, XrmFakedContext context)
{
var sAlias = string.IsNullOrWhiteSpace(le.EntityAlias) ? le.LinkToEntityName : le.EntityAlias;
if (le.Columns.AllColumns && le.Columns.Columns.Count == 0)
{
foreach (var attKey in e.Attributes.Keys)
{
if(attKey.StartsWith(sAlias + "."))
{
projected[attKey] = e[attKey];
}
}
}
else
{
foreach (var attKey in le.Columns.Columns)
{
var linkedAttKey = sAlias + "." + attKey;
if (e.Attributes.ContainsKey(linkedAttKey))
projected[linkedAttKey] = e[linkedAttKey];
}
}
foreach (var nestedLinkedEntity in le.LinkEntities)
{
ProjectAttributes(e, projected, nestedLinkedEntity, context);
}
}
示例6: 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);
}
示例7: When_translating_a_fetch_xml_attribute_node_must_have_a_name_attribute
public void When_translating_a_fetch_xml_attribute_node_must_have_a_name_attribute()
{
var ctx = new XrmFakedContext();
Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><attribute></attribute></entity></fetch>"));
Assert.DoesNotThrow(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><attribute name='firstname'></attribute></entity></fetch>"));
}
示例8: 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);
}
示例9: When_execute_is_called_with_a_null_request_exception_is_thrown
public void When_execute_is_called_with_a_null_request_exception_is_thrown()
{
var context = new XrmFakedContext();
var executor = new AssociateRequestExecutor();
AssociateRequest req = null;
Assert.Throws<Exception>(() => executor.Execute(req, context));
}
示例10: When_execute_is_called_with_a_null_target_exception_is_thrown
public void When_execute_is_called_with_a_null_target_exception_is_thrown()
{
var context = new XrmFakedContext();
var executor = new AssociateRequestExecutor();
var req = new AssociateRequest() { Target = null, Relationship = new Relationship("fakeRelationship") };
context.AddRelationship("fakeRelationship", new XrmFakedRelationship());
Assert.Throws<Exception>(() => executor.Execute(req, context));
}
示例11: XrmFakedContext
public void When_translating_a_fetch_xml_expression_first_node_must_be_a_fetch_element_otherwise_exception_is_thrown()
{
var ctx = new XrmFakedContext();
Assert.DoesNotThrow(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'></entity></fetch>"));
Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<attribute></attribute>"));
Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<entity></entity>"));
}
示例12: When_translating_a_fetch_xml_order_node_must_have_2_attributes
public void When_translating_a_fetch_xml_order_node_must_have_2_attributes()
{
var ctx = new XrmFakedContext();
Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order></order></entity></fetch>"));
Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order attribute=''></order></entity></fetch>"));
Assert.Throws<Exception>(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order descending=''></order></entity></fetch>"));
Assert.DoesNotThrow(() => XrmFakedContext.TranslateFetchXmlToQueryExpression(ctx, "<fetch><entity name='contact'><order attribute='firstname' descending='true'></order></entity></fetch>"));
}
示例13: Execute
public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
{
var associateRequest = request as AssociateRequest;
var service = ctx.GetFakedOrganizationService();
if (associateRequest == null)
{
throw new Exception("Only associate request can be processed!");
}
var associateRelationship = associateRequest.Relationship;
var relationShipName = associateRelationship.SchemaName;
var fakeRelationShip = ctx.GetRelationship(relationShipName);
if (fakeRelationShip == null)
{
throw new Exception(string.Format("Relationship {0} does not exist in the metadata cache", relationShipName));
}
if (associateRequest.Target == null)
{
throw new Exception("Association without target is invalid!");
}
foreach (var relatedEntityReference in associateRequest.RelatedEntities)
{
if (fakeRelationShip.RelationshipType == XrmFakedRelationship.enmFakeRelationshipType.ManyToMany)
{
var association = new Entity(fakeRelationShip.IntersectEntity)
{
Attributes = new AttributeCollection
{
{ fakeRelationShip.Entity1Attribute, associateRequest.Target.Id },
{ fakeRelationShip.Entity2Attribute, relatedEntityReference.Id }
}
};
service.Create(association);
}
else
{
//One to many
//Get entity to update
var entityToUpdate = new Entity(relatedEntityReference.LogicalName)
{
Id = relatedEntityReference.Id
};
entityToUpdate[fakeRelationShip.Entity2Attribute] = associateRequest.Target;
service.Update(entityToUpdate);
}
}
return new AssociateResponse ();
}
示例14: Execute
public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
{
var createRequest = (CreateRequest)request;
var service = ctx.GetFakedOrganizationService();
service.Create(createRequest.Target);
return new CreateResponse();
}
示例15: When_calling_publish_xml_no_exception_is_raised
public void When_calling_publish_xml_no_exception_is_raised()
{
var ctx = new XrmFakedContext();
var service = ctx.GetFakedOrganizationService();
var req = new PublishXmlRequest()
{
ParameterXml = "<somexml></somexml>"
};
Assert.DoesNotThrow(() => service.Execute(req));
}