本文整理汇总了C#中XrmFakedContext.AddRelationship方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.AddRelationship方法的具体用法?C# XrmFakedContext.AddRelationship怎么用?C# XrmFakedContext.AddRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XrmFakedContext
的用法示例。
在下文中一共展示了XrmFakedContext.AddRelationship方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: When_calling_context_add_addrelated_and_save_changes_entities_are_added_to_the_faked_context
public void When_calling_context_add_addrelated_and_save_changes_entities_are_added_to_the_faked_context()
{
var context = new XrmFakedContext();
var relationship = new XrmFakedRelationship()
{
IntersectEntity = "accountleads",
Entity1Attribute = "accountid",
Entity2Attribute = "leadid",
Entity1LogicalName = "account",
Entity2LogicalName = "lead"
};
context.AddRelationship("accountleads", relationship);
var service = context.GetFakedOrganizationService();
using (var ctx = new XrmServiceContext(service))
{
var account = new Account() { Name = "Test account" };
ctx.AddObject(account);
var contact = new Lead() { FirstName = "Jane", LastName = "Doe" };
ctx.AddRelatedObject(account, new Relationship("accountleads"), contact);
var result = ctx.SaveChanges();
var resultaccount = ctx.CreateQuery<Account>()
.ToList()
.FirstOrDefault();
Assert.NotNull(resultaccount);
Assert.Equal("Test account", resultaccount.Name);
var reaultlead = ctx.CreateQuery<Lead>()
.ToList()
.FirstOrDefault();
Assert.NotNull(reaultlead);
Assert.Equal("Jane", reaultlead.FirstName);
Assert.Equal("Doe", reaultlead.LastName);
var relationshipRecords = ctx.CreateQuery("accountleads")
.ToList();
Assert.NotEmpty(relationshipRecords);
}
}
示例3: Should_Only_Find_Correct_Faked_N_To_N_Records
public static void Should_Only_Find_Correct_Faked_N_To_N_Records()
{
var fakedContext = new XrmFakedContext();
var fakedService = fakedContext.GetFakedOrganizationService();
var userId = new Guid("11111111-7982-4276-A8FE-7CE05FABEAB4");
var businessId = Guid.NewGuid();
var testUser = new SystemUser
{
Id = userId
};
var testRole = new Role
{
Id = new Guid("22222222-7982-4276-A8FE-7CE05FABEAB4"),
Name = "Test Role",
BusinessUnitId = new EntityReference(BusinessUnit.EntityLogicalName, businessId)
};
var testUser2 = new SystemUser
{
Id = Guid.NewGuid()
};
var testRole2 = new Role
{
Id = Guid.NewGuid(),
Name = "Test Role",
BusinessUnitId = new EntityReference(BusinessUnit.EntityLogicalName, businessId)
};
fakedContext.Initialize(new Entity[] { testUser, testRole, testUser2, testRole2 });
fakedContext.AddRelationship("systemuserroles_association", new XrmFakedRelationship
{
IntersectEntity = "systemuserroles",
Entity1LogicalName = SystemUser.EntityLogicalName,
Entity1Attribute = "systemuserid",
Entity2LogicalName = Role.EntityLogicalName,
Entity2Attribute = "roleid"
});
var request = new AssociateRequest()
{
Target = testUser.ToEntityReference(),
RelatedEntities = new EntityReferenceCollection()
{
new EntityReference(Role.EntityLogicalName, testRole.Id),
},
Relationship = new Relationship("systemuserroles_association")
};
fakedService.Execute(request);
var request2 = new AssociateRequest()
{
Target = testUser2.ToEntityReference(),
RelatedEntities = new EntityReferenceCollection()
{
new EntityReference(Role.EntityLogicalName, testRole2.Id),
},
Relationship = new Relationship("systemuserroles_association")
};
fakedService.Execute(request2);
var query = new QueryExpression()
{
EntityName = "role",
ColumnSet = new ColumnSet("name"),
LinkEntities = {
new LinkEntity {
LinkFromEntityName = Role.EntityLogicalName,
LinkFromAttributeName = "roleid",
LinkToEntityName = SystemUserRoles.EntityLogicalName,
LinkToAttributeName = "roleid",
LinkCriteria = new FilterExpression {
FilterOperator = LogicalOperator.And,
Conditions = {
new ConditionExpression {
AttributeName = "systemuserid",
Operator = ConditionOperator.Equal,
Values = { userId }
}
}
}
}
}
};
var result = fakedService.RetrieveMultiple(query);
Assert.NotEmpty(result.Entities);
Assert.Equal(1, result.Entities.Count);
}
示例4: Should_Not_Fail_On_Conditions_In_Link_Entities
public static void Should_Not_Fail_On_Conditions_In_Link_Entities()
{
var fakedContext = new XrmFakedContext();
var fakedService = fakedContext.GetFakedOrganizationService();
var testEntity1 = new Entity("entity1")
{
Attributes = new AttributeCollection
{
{"entity1attr", "test1" }
}
};
var testEntity2 = new Entity("entity2")
{
Attributes = new AttributeCollection
{
{"entity2attr", "test2" }
}
};
testEntity1.Id = fakedService.Create(testEntity1);
testEntity2.Id = fakedService.Create(testEntity2);
var testRelation = new XrmFakedRelationship
{
IntersectEntity = "TestIntersectEntity",
Entity1LogicalName = "entity1",
Entity1Attribute = "entity1attr",
Entity2LogicalName = "entity2",
Entity2Attribute = "entity2attr"
};
fakedContext.AddRelationship(testRelation.Entity2LogicalName, testRelation);
fakedService.Associate(testEntity1.LogicalName, testEntity1.Id, new Relationship(testRelation.Entity2LogicalName), new EntityReferenceCollection { testEntity2.ToEntityReference() });
var query = new QueryExpression
{
EntityName = "entity1",
Criteria = new FilterExpression { FilterOperator = LogicalOperator.And },
ColumnSet = new ColumnSet(true)
};
var link = new LinkEntity
{
JoinOperator = JoinOperator.Natural,
LinkFromEntityName = "entity1",
LinkFromAttributeName = "entity1attr",
LinkToEntityName = "entity2",
LinkToAttributeName = "entity2attr",
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions = { new ConditionExpression { AttributeName = "entity2attr", Operator = ConditionOperator.Equal, Values = { "test2" } } }
}
};
query.LinkEntities.Add(link);
var result = fakedService.RetrieveMultiple(query);
Assert.NotEmpty(result.Entities);
Assert.Equal(1, result.Entities.Count);
}