UmbracoIdConfiguration
상속: Glass.Mapper.Configuration.IdConfiguration
        /// <summary>
        /// Called to map each property automatically
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        protected override AbstractPropertyConfiguration AutoMapProperty(System.Reflection.PropertyInfo property)
        {
            string          name = property.Name;
            UmbracoInfoType infoType;

            if (name.ToLowerInvariant() == "id")
            {
                UmbracoIdConfiguration idConfig = new UmbracoIdConfiguration();
                idConfig.PropertyInfo = property;
                return(idConfig);
            }

            if (name.ToLowerInvariant() == "parent")
            {
                UmbracoParentConfiguration parentConfig = new UmbracoParentConfiguration();
                parentConfig.PropertyInfo = property;
                return(parentConfig);
            }
            if (name.ToLowerInvariant() == "children")
            {
                UmbracoChildrenConfiguration childrenConfig = new UmbracoChildrenConfiguration();
                childrenConfig.PropertyInfo = property;
                return(childrenConfig);
            }

            if (Enum.TryParse(name, true, out infoType))
            {
                UmbracoInfoConfiguration infoConfig = new UmbracoInfoConfiguration();
                infoConfig.PropertyInfo = property;
                infoConfig.Type         = infoType;
                return(infoConfig);
            }

            UmbracoPropertyConfiguration fieldConfig = new UmbracoPropertyConfiguration();

            fieldConfig.PropertyAlias = name;
            fieldConfig.PropertyInfo  = property;
            return(fieldConfig);
        }
예제 #2
0
        public void MapToProperty_ContentIdAsInt_ReturnsIdAsInt()
        {
            var content = _contentService.GetById(new Guid("{263768E1-E958-4B00-BB00-191CC33A3F48}"));

            //Assign
            var mapper = new UmbracoIdMapper();
            var config = new UmbracoIdConfiguration();
            var property = typeof(Stub).GetProperty("Id");

            Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists");

            config.PropertyInfo = property;
            
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var dataContext = new UmbracoDataMappingContext(null, content, null);
            var expected = content.Id;

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            Assert.AreEqual(expected, value);
        }
        public void CanHandle_IncorrectConfigType_ReturnsFalse()
        {
            //Assign
            var config = new UmbracoIdConfiguration();
            var type2 = typeof(string);
            var type1 = typeof(int);
            var mapper = new StubMapper(type1, type2);

            config.PropertyInfo = typeof(Stub).GetProperty("Property");

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsFalse(result);
        }
        /// <summary>
        /// Called to map each property automatically
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        protected override AbstractPropertyConfiguration AutoMapProperty(System.Reflection.PropertyInfo property)
        {
            string name = property.Name;
            UmbracoInfoType infoType;

            if (name.ToLowerInvariant() == "id")
            {
                UmbracoIdConfiguration idConfig = new UmbracoIdConfiguration();
                idConfig.PropertyInfo = property;
                return idConfig;
            }

            if (name.ToLowerInvariant() == "parent")
            {
                UmbracoParentConfiguration parentConfig = new UmbracoParentConfiguration();
                parentConfig.PropertyInfo = property;
                return parentConfig;
            }
            if (name.ToLowerInvariant() == "children")
            {
                UmbracoChildrenConfiguration childrenConfig = new UmbracoChildrenConfiguration();
                childrenConfig.PropertyInfo = property;
                return childrenConfig;
            }

            if (Enum.TryParse(name, true, out infoType))
            {
                UmbracoInfoConfiguration infoConfig = new UmbracoInfoConfiguration();
                infoConfig.PropertyInfo = property;
                infoConfig.Type = infoType;
                return infoConfig;
            }

            UmbracoPropertyConfiguration fieldConfig = new UmbracoPropertyConfiguration();
            fieldConfig.PropertyAlias = name;
            fieldConfig.PropertyInfo = property;
            return fieldConfig;
        }