0

我有一个方法可以将注释链接到销售订单:

    /// <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 链接这两个实体吗?

4

1 回答 1

1

需要使用具有显式 ObjectId 属性而不是 AssociateRequest 的 Create 消息来创建注释。

前任:

https://community.dynamics.com/crm/b/mahenderpal/archive/2012/12/09/create-and-attach-text-file-to-notes-in-microsoft-crm-2011

然后,您将能够查询它们。

于 2017-03-06T23:42:27.300 回答