public void AssociateManyToManyEntity()
        {
            testOrgService.ExecutionResponse = new RetrieveEntityResponse();

            MockRetryExecutor.Setup(a => a.Execute(It.IsAny <Func <ExecuteMultipleResponse> >()))
            .Returns(requestResult);
            ManyToManyDetails details = new ManyToManyDetails
            {
                Entity1IntersectAttribute = "contactid",
                Entity2IntersectAttribute = "accountid",
                IsManyToMany = true,
                SchemaName   = "accountcontact"
            };

            MockEntityMetadataCache.Setup(a => a.GetManyToManyEntityDetails(It.IsAny <string>()))
            .Returns(details);

            FluentActions.Invoking(() => systemUnderTest.AssociateManyToManyEntity(entities))
            .Should()
            .NotThrow();

            MockRetryExecutor.VerifyAll();
            MockEntityMetadataCache.VerifyAll();
        }
Пример #2
0
        public void ProcessEntityApplyAliasMapping()
        {
            entityName = "ProcessEntityApplyAliasMapping";
            string lookUpName    = "contact";
            string attributeName = "c.contactid";
            var    testEntity    = new Entity("contact", Guid.NewGuid());
            var    listOfEntity  = new List <Entity> {
                testEntity
            };

            var attributeMetaDataItem = new AttributeMetadata {
                LogicalName = attributeName
            };

            SetFieldValue(attributeMetaDataItem, "_attributeType", AttributeTypeCode.Uniqueidentifier);

            var attributes = new List <AttributeMetadata> {
                attributeMetaDataItem
            };

            var oneToManyRelationshipMetadata = new OneToManyRelationshipMetadata
            {
                ReferencingAttribute = attributeName
            };
            var oneToManyRelationships = new List <OneToManyRelationshipMetadata>
            {
                oneToManyRelationshipMetadata
            };

            var entityMetaData = InitializeEntityMetadata(attributes, oneToManyRelationships);

            SetFieldValue(entityMetaData, "_primaryIdAttribute", attributeName);

            mappingConfig.ApplyAliasMapping = true;
            EntityWrapper entityWraper = new EntityWrapper(new Entity()
            {
                LogicalName = entityName
            });

            entityWraper.OriginalEntity.Attributes[attributeName] = new AliasedValue("contact", "contactid", testEntity.Id.ToString());

            MockEntityRepo.SetupGet(a => a.GetEntityMetadataCache).Returns(MockEntityMetadataCache.Object);
            MockEntityRepo.Setup(a => a.GetParentBuId()).Returns(Guid.NewGuid());
            MockEntityRepo.Setup(a => a.GetOrganizationId()).Returns(Guid.NewGuid());
            MockEntityRepo.Setup(a => a.FindEntitiesByName(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(listOfEntity);

            MockEntityMetadataCache.Setup(a => a.GetEntityMetadata(It.IsAny <string>())).Returns(entityMetaData);
            MockEntityMetadataCache.Setup(a => a.GetIdAliasKey(It.IsAny <string>())).Returns(attributeName);
            MockEntityMetadataCache.Setup(a => a.GetLookUpEntityName(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(lookUpName);

            systemUnderTest = new MapEntityProcessor(mappingConfig, MockLogger.Object, MockEntityRepo.Object, passOneReferences);

            FluentActions.Invoking(() => systemUnderTest.ProcessEntity(entityWraper, passNumber, maxPassNumber))
            .Should()
            .NotThrow();

            MockEntityRepo.VerifyAll();
            MockEntityMetadataCache.VerifyAll();
        }