我有一个方法可以将注释链接到销售订单:
/// <summary> Links. </summary>
/// <param name="noteGuid"> Unique identifier for the note. </param>
/// <param name="salesOrderGuid"> Unique identifier for the sales order. </param>
/// <returns> A SalesOrder. </returns>
public SalesOrder Link(Guid noteGuid, Guid salesOrderGuid)
{
var associateRequest = new AssociateRequest
{
Target =
new EntityReference(
SalesOrder.EntityLogicalName,
salesOrderGuid),
RelatedEntities =
new EntityReferenceCollection
{
new EntityReference(
Annotation
.EntityLogicalName,
noteGuid)
},
Relationship = new Relationship("SalesOrder_Annotation")
};
_xrmServiceContext.Execute(associateRequest);
return GetSalesOrderByOrderGuid(salesOrderGuid);
}
我正在尝试使用以下测试对该方法进行单元测试:
[Test]
public void Link_ExistingRecordHavingNotes_LinksItemCorrectly()
{
using (var xrmServiceContext = new XrmServiceContext(_fakeOrganizationService))
{
// Arrange
var salesOrderGuid = Guid.NewGuid();
var note1 = new Annotation { Id = Guid.NewGuid(), Subject = "this is note1" };
var salesOrder = new SalesOrder
{
Id = salesOrderGuid
};
_fakeContext.Initialize(new List<Entity> { salesOrder, note1 });
this._fakeContext.AddRelationship(
"SalesOrder_Annotation",
new XrmFakedRelationship
{
Entity2LogicalName = "annotation",
Entity2Attribute = "salesorderid",
Entity1LogicalName = "salesorder",
Entity1Attribute = "SalesOrder_Annotation.Id",
RelationshipType = XrmFakedRelationship.enmFakeRelationshipType.OneToMany
});
var sut = new SalesOrderService(xrmServiceContext);
// Act
var linkedRecord = sut.Link(note1.Id, salesOrderGuid);
var annotations = xrmServiceContext.AnnotationSet.FirstOrDefault(note => note.ObjectId.Id == salesOrderGuid);
...
我不明白为什么annotations
为空。当我使用上述关联请求将一个实体链接到另一个实体时,它不应该通过 ObjectId 链接这两个实体吗?