Exemplo n.º 1
0
        public void CollectCrmEntityFields()
        {
            var entityLogicalName = "contact";

            inputCheckedEntity.Add(entityLogicalName);
            var attributeSet = new HashSet <string>()
            {
                "contactId", "firstname", "lastname"
            };

            inputEntityAttributes.Add(entityLogicalName, attributeSet);
            var inputAttributeMapping = new AttributeTypeMapping();

            var schemaConfiguration = new Capgemini.Xrm.DataMigration.Config.CrmSchemaConfiguration();

            var entityMetadata = InstantiateEntityMetaData(entityLogicalName);

            InsertAttributeList(entityMetadata, new List <string> {
                "contactId", "firstname", "lastname"
            });

            var serviceParameters = GenerateMigratorParameters();

            MetadataServiceMock.Setup(x => x.RetrieveEntities(It.IsAny <string>(), It.IsAny <IOrganizationService>(), It.IsAny <IExceptionService>()))
            .Returns(entityMetadata)
            .Verifiable();

            FluentActions.Invoking(() => systemUnderTest.CollectCrmEntityFields(inputCheckedEntity, schemaConfiguration, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters))
            .Should()
            .NotThrow();

            MetadataServiceMock.VerifyAll();
        }
Exemplo n.º 2
0
        public void AreCrmEntityFieldsSelected()
        {
            var entityLogicalName = "contact";

            inputCheckedEntity.Add(entityLogicalName);
            var entityMetadata = InstantiateEntityMetaData(entityLogicalName);

            InsertAttributeList(entityMetadata, new List <string> {
                "contactId", "firstname", "lastname"
            });

            var attributeSet = new HashSet <string>()
            {
                "contactId", "firstname", "lastname"
            };

            inputEntityAttributes.Add(entityLogicalName, attributeSet);
            var inputAttributeMapping = new AttributeTypeMapping();
            var serviceParameters     = GenerateMigratorParameters();

            MetadataServiceMock.Setup(x => x.RetrieveEntities(It.IsAny <string>(), It.IsAny <IOrganizationService>(), It.IsAny <IExceptionService>()))
            .Returns(entityMetadata)
            .Verifiable();

            var actual = systemUnderTest.AreCrmEntityFieldsSelected(inputCheckedEntity, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters);

            actual.Should().BeTrue();
            MetadataServiceMock.VerifyAll();
        }
Exemplo n.º 3
0
        public void StoreAttributeMetadata()
        {
            var entityLogicalName = "contact";
            var attributeSet      = new HashSet <string>()
            {
                "contactId", "firstname", "lastname"
            };

            inputEntityAttributes.Add(entityLogicalName, attributeSet);
            var inputAttributeMapping = new AttributeTypeMapping();

            string primaryAttribute = "contactId";
            var    entityMetadata   = InstantiateEntityMetaData(entityLogicalName);

            InsertAttributeList(entityMetadata, new List <string> {
                primaryAttribute, "firstname", "lastname"
            });

            var crmFieldList = new List <Capgemini.Xrm.DataMigration.Model.CrmField>();

            FluentActions.Invoking(() => systemUnderTest.StoreAttributeMetadata(entityMetadata.Attributes[0], entityMetadata, primaryAttribute, crmFieldList, inputEntityAttributes, inputAttributeMapping, NotificationServiceMock.Object))
            .Should()
            .NotThrow();

            crmFieldList.Count.Should().Be(1);
        }
        public void StoreCrmEntityData()
        {
            var entityLogicalName = "contact";
            var attributeSet      = new HashSet <string>()
            {
                "contactId", "firstname", "lastname"
            };

            inputEntityAttributes.Add(entityLogicalName, attributeSet);
            var inputAttributeMapping = new AttributeTypeMapping();

            var entityMetadata = InstantiateEntityMetaData(entityLogicalName);

            InsertAttributeList(entityMetadata, new List <string> {
                "contactId", "firstname", "lastname"
            });

            var crmEntity     = new CrmEntity();
            var crmEntityList = new List <CrmEntity>();

            FluentActions.Invoking(() => systemUnderTest.StoreCrmEntityData(crmEntity, entityMetadata, crmEntityList, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, NotificationServiceMock.Object))
            .Should()
            .NotThrow();

            crmEntityList.Count.Should().Be(1);
        }
Exemplo n.º 5
0
        public void CollectCrmAttributesFields()
        {
            var entityLogicalName = "contact";

            var attributeSet = new HashSet <string>()
            {
                "contactId", "firstname", "lastname"
            };

            inputEntityAttributes.Add(entityLogicalName, attributeSet);
            var inputAttributeMapping = new AttributeTypeMapping();

            var entityMetadata = InstantiateEntityMetaData(entityLogicalName);

            InsertAttributeList(entityMetadata, new List <string> {
                "contactId", "firstname", "lastname"
            });

            var crmEntity = new Capgemini.Xrm.DataMigration.Model.CrmEntity
            {
                Name        = entityLogicalName,
                DisplayName = entityLogicalName
            };

            FluentActions.Invoking(() => systemUnderTest.CollectCrmAttributesFields(entityMetadata, crmEntity, inputEntityAttributes, inputAttributeMapping, NotificationServiceMock.Object))
            .Should()
            .NotThrow();

            crmEntity.CrmFields.Count.Should().Be(3);
        }
Exemplo n.º 6
0
        public void AreCrmEntityFieldsSelectedCheckedEntityCountIsZero()
        {
            var inputAttributeMapping = new AttributeTypeMapping();
            var serviceParameters     = GenerateMigratorParameters();

            var actual = systemUnderTest.AreCrmEntityFieldsSelected(inputCheckedEntity, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters);

            actual.Should().BeFalse();
        }
Exemplo n.º 7
0
        public void CollectCrmEntityFieldsCheckedEntityCountIsZero()
        {
            var inputAttributeMapping = new AttributeTypeMapping();
            var serviceParameters     = GenerateMigratorParameters();

            var schemaConfiguration = new Capgemini.Xrm.DataMigration.Config.CrmSchemaConfiguration();

            FluentActions.Invoking(() => systemUnderTest.CollectCrmEntityFields(inputCheckedEntity, schemaConfiguration, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters))
            .Should()
            .NotThrow();
        }
        public void SaveSchemaNoEntityAttributeSelected()
        {
            NotificationServiceMock.Setup(x => x.DisplayFeedback("Please select at least one attribute for each selected entity!"))
            .Verifiable();

            using (var schemaPathTextBox = new System.Windows.Forms.TextBox())
            {
                var serviceParameters = GenerateMigratorParameters();

                var inputAttributeMapping       = new AttributeTypeMapping();
                var inputCrmSchemaConfiguration = new DataMigration.Config.CrmSchemaConfiguration();

                FluentActions.Invoking(() => systemUnderTest.SaveSchema(serviceParameters, inputCheckedEntity, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, inputCrmSchemaConfiguration, schemaPathTextBox))
                .Should()
                .NotThrow();
            }

            NotificationServiceMock.Verify(x => x.DisplayFeedback("Please select at least one attribute for each selected entity!"), Times.Once);
        }
        public void SaveSchemaEntityAttributeSelected()
        {
            NotificationServiceMock.Setup(x => x.DisplayFeedback("Please select at least one attribute for each selected entity!"))
            .Verifiable();
            var entityLogicalName = "contact";
            var entityMetadata    = InstantiateEntityMetaData(entityLogicalName);

            InsertAttributeList(entityMetadata, new List <string> {
                "contactId", "firstname", "lastname"
            });

            inputCheckedEntity.Add(entityLogicalName);

            var attributeSet = new HashSet <string>()
            {
                "contactId", "firstname", "lastname"
            };

            inputEntityAttributes.Add(entityLogicalName, attributeSet);
            var inputAttributeMapping = new AttributeTypeMapping();
            var serviceParameters     = GenerateMigratorParameters();

            MetadataServiceMock.Setup(x => x.RetrieveEntities(It.IsAny <string>(), It.IsAny <IOrganizationService>(), It.IsAny <IExceptionService>()))
            .Returns(entityMetadata)
            .Verifiable();

            using (var schemaPathTextBox = new System.Windows.Forms.TextBox())
            {
                var inputCrmSchemaConfiguration = new DataMigration.Config.CrmSchemaConfiguration();

                FluentActions.Invoking(() => systemUnderTest.SaveSchema(serviceParameters, inputCheckedEntity, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, inputCrmSchemaConfiguration, schemaPathTextBox))
                .Should()
                .NotThrow();
            }

            MetadataServiceMock.VerifyAll();
            NotificationServiceMock.Verify(x => x.DisplayFeedback("Please select at least one attribute for each selected entity!"), Times.Never);
        }
 public void StoreAttributeMetadata(AttributeMetadata attribute, EntityMetadata entityMetadata, string primaryAttribute, List <CrmField> crmFieldList, Dictionary <string, HashSet <string> > inputEntityAttributes, AttributeTypeMapping inputAttributeMapping, INotificationService notificationService)
 {
     if (inputEntityAttributes != null && inputEntityAttributes.ContainsKey(entityMetadata.LogicalName))
     {
         var crmField = new CrmField();
         foreach (var attributeLogicalName in inputEntityAttributes[entityMetadata.LogicalName])
         {
             if (attribute.LogicalName.Equals(attributeLogicalName, StringComparison.InvariantCulture))
             {
                 crmField.DisplayName = attribute.DisplayName.UserLocalizedLabel == null ? string.Empty : attribute.DisplayName.UserLocalizedLabel.Label;
                 crmField.FieldName   = attribute.LogicalName;
                 inputAttributeMapping.AttributeMetadataType = attribute.AttributeTypeName.Value.ToString(CultureInfo.InvariantCulture);
                 inputAttributeMapping.GetMapping(notificationService);
                 crmField.FieldType = inputAttributeMapping.AttributeMetadataTypeResult;
                 StoreLookUpAttribute(attribute, crmField, notificationService);
                 StoreAttributePrimaryKey(primaryAttribute, crmField);
                 crmFieldList.Add(crmField);
             }
         }
     }
 }
        public void CollectCrmAttributesFields(EntityMetadata sourceList, CrmEntity crmEntity, Dictionary <string, HashSet <string> > inputEntityAttributes, AttributeTypeMapping inputAttributeMapping, INotificationService notificationService)
        {
            if (inputEntityAttributes != null)
            {
                var attributes = sourceList.Attributes.ToArray();

                var primaryAttribute = sourceList.PrimaryIdAttribute;
                if (sourceList.LogicalName != null && inputEntityAttributes.ContainsKey(sourceList.LogicalName))
                {
                    var crmFieldList = new List <CrmField>();
                    foreach (AttributeMetadata attribute in attributes)
                    {
                        StoreAttributeMetadata(attribute, sourceList, primaryAttribute, crmFieldList, inputEntityAttributes, inputAttributeMapping, notificationService);
                    }

                    crmEntity.CrmFields.Clear();
                    crmEntity.CrmFields.AddRange(crmFieldList);
                }
            }
        }
        public void CollectCrmEntityFields(HashSet <string> inputCheckedEntity, CrmSchemaConfiguration schemaConfiguration, Dictionary <string, HashSet <string> > inputEntityRelationships, Dictionary <string, HashSet <string> > inputEntityAttributes, AttributeTypeMapping inputAttributeMapping, ServiceParameters serviceParameters)
        {
            if (inputCheckedEntity.Count > 0)
            {
                var crmEntityList = new List <CrmEntity>();

                foreach (var item in inputCheckedEntity)
                {
                    var crmEntity  = new CrmEntity();
                    var sourceList = serviceParameters.MetadataService.RetrieveEntities(item, serviceParameters.OrganizationService, serviceParameters.ExceptionService);
                    StoreCrmEntityData(crmEntity, sourceList, crmEntityList, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters.NotificationService);
                }

                schemaConfiguration.Entities.Clear();
                schemaConfiguration.Entities.AddRange(crmEntityList);
            }
        }
        public void StoreCrmEntityData(CrmEntity crmEntity, EntityMetadata sourceList, List <CrmEntity> crmEntityList, Dictionary <string, HashSet <string> > inputEntityRelationships, Dictionary <string, HashSet <string> > inputEntityAttributes, AttributeTypeMapping inputAttributeMapping, INotificationService notificationService)
        {
            crmEntity.Name = sourceList.LogicalName;

            crmEntity.DisplayName = sourceList.DisplayName?.UserLocalizedLabel == null ? string.Empty : sourceList.DisplayName.UserLocalizedLabel.Label;

            crmEntity.EntityCode       = sourceList.ObjectTypeCode.ToString();
            crmEntity.PrimaryIdField   = sourceList.PrimaryIdAttribute;
            crmEntity.PrimaryNameField = sourceList.PrimaryNameAttribute;
            CollectCrmEntityRelationShip(sourceList, crmEntity, inputEntityRelationships);
            CollectCrmAttributesFields(sourceList, crmEntity, inputEntityAttributes, inputAttributeMapping, notificationService);
            crmEntityList.Add(crmEntity);
        }
        public bool AreCrmEntityFieldsSelected(HashSet <string> inputCheckedEntity, Dictionary <string, HashSet <string> > inputEntityRelationships, Dictionary <string, HashSet <string> > inputEntityAttributes, AttributeTypeMapping inputAttributeMapping, ServiceParameters serviceParameters)
        {
            var fieldsSelected = false;

            if (inputCheckedEntity.Count > 0)
            {
                var crmEntityList = new List <CrmEntity>();

                foreach (var item in inputCheckedEntity)
                {
                    var crmEntity  = new CrmEntity();
                    var sourceList = serviceParameters.MetadataService.RetrieveEntities(item, serviceParameters.OrganizationService, serviceParameters.ExceptionService);
                    StoreCrmEntityData(crmEntity, sourceList, crmEntityList, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters.NotificationService);

                    if (crmEntity.CrmFields != null && crmEntity.CrmFields.Any())
                    {
                        fieldsSelected = true;
                    }
                    else
                    {
                        fieldsSelected = false;
                        break;
                    }
                }
            }

            return(fieldsSelected);
        }
Exemplo n.º 15
0
        public void Setup()
        {
            notificationServiceMock = new Mock <INotificationService>();

            systemUnderTest = new AttributeTypeMapping();
        }
Exemplo n.º 16
0
 public void SaveSchema(ServiceParameters serviceParameters, HashSet <string> inputCheckedEntity, Dictionary <string, HashSet <string> > inputEntityRelationships, Dictionary <string, HashSet <string> > inputEntityAttributes, AttributeTypeMapping inputAttributeMapping, CrmSchemaConfiguration inputCrmSchemaConfiguration, TextBox schemaPathTextBox)
 {
     if (AreCrmEntityFieldsSelected(inputCheckedEntity, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters))
     {
         CollectCrmEntityFields(inputCheckedEntity, inputCrmSchemaConfiguration, inputEntityRelationships, inputEntityAttributes, inputAttributeMapping, serviceParameters);
         GenerateXMLFile(schemaPathTextBox, inputCrmSchemaConfiguration);
         inputCrmSchemaConfiguration.Entities.Clear();
     }
     else
     {
         serviceParameters.NotificationService.DisplayFeedback("Please select at least one attribute for each selected entity!");
     }
 }