示例#1
0
        public void GenerateAttributeUniqueIdentifier()
        {
            var entityMetadata = new EntityMetadata {
                LogicalName = "ee_test", MetadataId = Guid.NewGuid(), DisplayName = new Label("Test", 1033)
            };
            var guidAttributeMetadata = new UniqueIdentifierAttributeMetadata
            {
                LogicalName = "ee_testguid",
                MetadataId  = Guid.NewGuid(),
                DisplayName = new Label("Id", 1033)
            }.Set(x => x.EntityLogicalName, entityMetadata.LogicalName);

            organizationMetadata.Entities.Returns(new[] {
                entityMetadata.Set(x => x.Attributes, new AttributeMetadata [] { guidAttributeMetadata })
            });

            var f = Builder.Create <SolutionComponent>();

            f.Set(x => x.Regarding, entityMetadata.MetadataId);

            SolutionHelper.organisationService.RetrieveMultiple(Arg.Any <QueryExpression>())
            .Returns(new EntityCollection(new List <Entity> {
                Builder.Create <SolutionComponent>().Set(x => x.Regarding, entityMetadata.MetadataId).Set(x => x.ObjectTypeCode, ComponentType.Entity),
            }));

            Assert.IsTrue(sut.GenerateAttribute(guidAttributeMetadata, serviceProvider));
        }
        public void RefreshMappingList()
        {
            string entityName = "contactattnoattributes";

            selectedValue = "contactattnoattributes1";

            mappings = new Dictionary <string, Dictionary <string, List <string> > >();
            var values = new Dictionary <string, List <string> >
            {
                { selectedValue, new List <string>()
                  {
                      entityName
                  } }
            };

            mappings.Add(selectedValue, values);

            var attributeMetaDataItem = new UniqueIdentifierAttributeMetadata
            {
                LogicalName = selectedValue
            };

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

            var entityMetadata  = new EntityMetadata();
            var attributesField = entityMetadata.GetType().GetRuntimeFields().First(a => a.Name == "_attributes");

            attributesField.SetValue(entityMetadata, attributes.ToArray());

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

            using (var systemUnderTest = new MappingListLookup(mappings, orgServiceMock.Object, metadata, selectedValue, metadataServiceMock.Object, dataMigratorExceptionHelperMock.Object))
            {
                systemUnderTest.LoadMappedItems();

                FluentActions.Invoking(() => systemUnderTest.RefreshMappingList())
                .Should()
                .NotThrow();
            }

            metadataServiceMock.Verify(x => x.RetrieveEntities(It.IsAny <string>(), It.IsAny <IOrganizationService>(), It.IsAny <IExceptionService>()), Times.Exactly(2));
        }
示例#3
0
        public static IEnumerable <AttributeMetadata> GetProcessMetadata()
        {
            var stageid = new UniqueIdentifierAttributeMetadata("StageId")
            {
                LogicalName = "stageid"
            };

            stageid.SetSealedPropertyValue(nameof(stageid.IsValidForCreate), true);
            yield return(stageid);

            var processid = new UniqueIdentifierAttributeMetadata("ProcessId")
            {
                LogicalName = "processid"
            };

            processid.SetSealedPropertyValue(nameof(processid.IsValidForCreate), true);
            yield return(processid);
        }
        public static EntityMetadata GetEntityMetadata()
        {
            var metadata = new EntityMetadata
            {
                LogicalName = "account"
            };

            metadata.SetSealedPropertyValue(nameof(metadata.PrimaryIdAttribute), "accountid");
            metadata.SetSealedPropertyValue(nameof(metadata.PrimaryNameAttribute), "name");

            var accountid = new UniqueIdentifierAttributeMetadata("accountid")
            {
                LogicalName = "accountid"
            };

            accountid.SetSealedPropertyValue(nameof(accountid.IsPrimaryId), true);
            accountid.SetSealedPropertyValue(nameof(accountid.IsValidForCreate), true);

            var name = new StringAttributeMetadata("name")
            {
                LogicalName = "name"
            };

            name.SetSealedPropertyValue(nameof(name.IsPrimaryName), true);
            name.SetSealedPropertyValue(nameof(name.IsValidForCreate), true);

            var primarycontactid = new LookupAttributeMetadata()
            {
                LogicalName = "primarycontactid",
                SchemaName  = "primarycontactid"
            };

            primarycontactid.SetSealedPropertyValue(nameof(primarycontactid.IsValidForCreate), true);

            metadata.SetAttributeCollection(
                new AttributeMetadata[] { accountid, name, primarycontactid }
                .Concat(GlobalMetadata.GetGlobalMetadata())
                .Concat(GlobalMetadata.GetOwnerMetadata())
                .Concat(GlobalMetadata.GetProcessMetadata())
                .ToArray());

            return(metadata);
        }
示例#5
0
        public void OnlyLookupsAreCheckedOnCustomUnmanagedEntity()
        {
            var entity = new EntityMetadata()
            {
                SchemaName = "foo_myEntity",
            };

            entity.SetSealedPropertyValue("IsManaged", false);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            var scope = RuleScope.Lookup;

            var stringAttr = new StringAttributeMetadata()
            {
                SchemaName = "foo_StrField"
            };

            stringAttr.SetSealedPropertyValue("IsCustomAttribute", true);
            stringAttr.SetSealedPropertyValue("IsManaged", false);

            var primaryKeyAttr = new UniqueIdentifierAttributeMetadata()
            {
                SchemaName = "foo_myEntityId"
            };

            primaryKeyAttr.SetSealedPropertyValue("IsCustomAttribute", true);
            primaryKeyAttr.SetSealedPropertyValue("IsManaged", false);

            var attributes = new List <AttributeMetadata> {
                stringAttr,
                primaryKeyAttr
            };
            var solutionEntity = new SolutionEntity(entity, attributes, true);

            var rule    = new RegexRule(_REGEX_PATTERN, scope);
            var results = rule.Validate(solutionEntity);

            Assert.True(results.Passed);
        }
示例#6
0
        private RetrieveAttributeResponse ExecuteInternal(RetrieveAttributeRequest request)
        {
            var response   = new RetrieveAttributeResponse();
            var entityType =
                CrmServiceUtility.GetEarlyBoundProxyAssembly().GetTypes().FirstOrDefault(t =>
                                                                                         t.GetCustomAttribute <EntityLogicalNameAttribute>(true)?.LogicalName == request.EntityLogicalName);

            var propertyTypes = entityType?.GetProperties()
                                .Where(p =>
                                       p.GetCustomAttribute <AttributeLogicalNameAttribute>()?.LogicalName == request.LogicalName
                                       ).Select(p => p.PropertyType.IsGenericType
                    ? p.PropertyType.GenericTypeArguments.First()
                    : p.PropertyType).ToList();

            var propertyType = propertyTypes?.Count == 1
                ? propertyTypes[0]
                : propertyTypes?.FirstOrDefault(p => p != typeof(OptionSetValue) &&
                                                p != typeof(EntityReference));      // Handle OptionSets/EntityReferences that may have multiple properties

            if (propertyType == null)
            {
                throw new Exception($"Unable to find a property for Entity {request.EntityLogicalName} and property {request.LogicalName} in {CrmServiceUtility.GetEarlyBoundProxyAssembly().FullName}");
            }

            AttributeMetadata metadata;

            if (propertyType.IsEnum || propertyTypes.Any(p => p == typeof(OptionSetValue)))
            {
                metadata = CreateOptionSetAttributeMetadata(request, propertyType);
            }
            else if (propertyType == typeof(string))
            {
                metadata = new StringAttributeMetadata(request.LogicalName);
            }
            else if (propertyTypes.Any(p => p == typeof(EntityReference)))
            {
                metadata = new LookupAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
#if !XRM_2013
            else if (propertyType == typeof(Guid))
            {
                metadata = new UniqueIdentifierAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
#endif
            else if (propertyType == typeof(bool))
            {
                metadata = new BooleanAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
            else if (propertyType == typeof(Money))
            {
                metadata = new MoneyAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
            else if (propertyType == typeof(int))
            {
                metadata = new IntegerAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
            else if (propertyType == typeof(long))
            {
                metadata = new BigIntAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
            else if (propertyType == typeof(DateTime))
            {
                metadata = new DateTimeAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
            else if (propertyType == typeof(double))
            {
                metadata = new DoubleAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
            else if (propertyType == typeof(decimal))
            {
                metadata = new DecimalAttributeMetadata
                {
                    LogicalName = request.LogicalName
                };
            }
            else
            {
                throw new NotImplementedException($"Attribute Type of {propertyType.FullName} is not implemented.");
            }
            response.Results["AttributeMetadata"] = metadata;
            return(response);
        }