コード例 #1
0
        public void When_calling_retrieve_entity_with_a_fake_attribute_definition_it_is_returned()
        {
            var ctx = new XrmFakedContext()
            {
                ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account))
            };

            var service = ctx.GetOrganizationService();

            var executor = new RetrieveEntityRequestExecutor();

            executor.AddFakeEntityMetadata(Account.EntityLogicalName, new EntityMetadata()
            {
                IsCustomizable = new BooleanManagedProperty(true)
            });

            var stringMetadata = new StringAttributeMetadata()
            {
                MaxLength = 200
            };

            stringMetadata.GetType().GetProperty("IsValidForCreate").SetValue(stringMetadata, new Nullable <bool>(true), null);
            executor.AddFakeAttributeMetadata(Account.EntityLogicalName, "name", stringMetadata);

            ctx.AddFakeMessageExecutor <RetrieveEntityRequest>(executor);

            var request = new RetrieveEntityRequest()
            {
                EntityFilters = EntityFilters.Attributes,
                LogicalName   = Account.EntityLogicalName
            };

            var response = service.Execute(request);

            Assert.IsType <RetrieveEntityResponse>(response);

            var nameAttribute = (response as RetrieveEntityResponse).EntityMetadata.Attributes
                                .Where(a => a.SchemaName.Equals("name"))
                                .FirstOrDefault();

            Assert.True(nameAttribute.IsValidForCreate.Value);
        }