public void Should_return_a_clone_when_querying_entity_metadatas()
        {
            var ctx            = new XrmFakedContext();
            var entityMetadata = new EntityMetadata()
            {
                LogicalName = "account"
            };

            ctx.InitializeMetadata(new List <EntityMetadata>()
            {
                entityMetadata
            });

            var metadata1 = ctx.CreateMetadataQuery().FirstOrDefault();
            var metadata2 = ctx.CreateMetadataQuery().FirstOrDefault();

            Assert.True(metadata1 != metadata2);
        }
Exemple #2
0
 private void SetPrimaryIdAttributes(XrmFakedContext context)
 {
     foreach (var entity in context.CreateMetadataQuery())
     {
         typeof(EntityMetadata).GetProperty(nameof(EntityMetadata.PrimaryIdAttribute)).SetValue(entity, entity.LogicalName + "id");
         var attr = entity.Attributes.Single(a => a.LogicalName == entity.LogicalName + "id");
         typeof(AttributeMetadata).GetProperty(nameof(AttributeMetadata.IsPrimaryId)).SetValue(attr, true);
         context.SetEntityMetadata(entity);
     }
 }
Exemple #3
0
        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
        {
            var req = request as RetrieveAllEntitiesRequest;

            if (req.EntityFilters == 0)
            {
                req.EntityFilters = EntityFilters.Default;
            }

            if (req.EntityFilters.HasFlag(EntityFilters.Entity) ||
                req.EntityFilters.HasFlag(EntityFilters.Attributes) ||
                req.EntityFilters.HasFlag(EntityFilters.Privileges) ||
                req.EntityFilters.HasFlag(EntityFilters.Relationships))
            {
                var allEntities = ctx.CreateMetadataQuery().Select(x => x.Copy()).ToArray();
                foreach (var entityMetadata in allEntities)
                {
                    if (!req.EntityFilters.HasFlag(EntityFilters.Attributes))
                    {
                        entityMetadata.SetAttributeCollection(null);
                    }

                    if (!req.EntityFilters.HasFlag(EntityFilters.Privileges))
                    {
                        entityMetadata.SetSecurityPrivilegeCollection(null);
                    }

                    if (!req.EntityFilters.HasFlag(EntityFilters.Relationships))
                    {
                        entityMetadata.SetOneToManyRelationshipCollection(null);
                        entityMetadata.SetManyToOneRelationshipCollection(null);
                        entityMetadata.SetManyToManyRelationshipCollection(null);
                    }
                }

                var response = new RetrieveAllEntitiesResponse()
                {
                    Results = new ParameterCollection
                    {
                        { "EntityMetadata", allEntities }
                    }
                };

                return(response);
            }

            throw new Exception("Entity Filter not supported");
        }
        public void Should_store_a_clone_after_initialisation()
        {
            var ctx            = new XrmFakedContext();
            var entityMetadata = new EntityMetadata()
            {
                LogicalName = "account"
            };

            ctx.InitializeMetadata(new List <EntityMetadata>()
            {
                entityMetadata
            });

            var metadatas = ctx.CreateMetadataQuery().ToList();

            Assert.True(metadatas[0] != entityMetadata);
        }
Exemple #5
0
        public void Should_initialize_metadata_from_early_bound_assembly()
        {
            var ctx = new XrmFakedContext();

            ctx.InitializeMetadata(typeof(Crm.Account).Assembly);

            var accountMetadata = ctx.CreateMetadataQuery().Where(x => x.LogicalName == "account").FirstOrDefault();

            Assert.NotNull(accountMetadata);

            var accountid = accountMetadata.Attributes.FirstOrDefault(x => x.LogicalName == "accountid");


            Assert.Equal("accountid", accountMetadata.PrimaryIdAttribute);
            Assert.NotNull(accountid);
            Assert.Equal(AttributeTypeCode.Uniqueidentifier, accountid.AttributeType);
        }
        public void Should_contain_one_entity_metadata_after_initialisation()
        {
            var ctx            = new XrmFakedContext();
            var entityMetadata = new EntityMetadata()
            {
                LogicalName = "account"
            };

            ctx.InitializeMetadata(new List <EntityMetadata>()
            {
                entityMetadata
            });

            var metadatas = ctx.CreateMetadataQuery().ToList();

            Assert.True(metadatas.Count == 1);
            Assert.Equal("account", metadatas[0].LogicalName);
        }