UmbracoChildrenConfiguration
Inheritance: Glass.Mapper.Configuration.ChildrenConfiguration
        /// <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);
        }
        public void MapToProperty_ContentHasChildren_ChildrenObjectsAreCreated()
        {
            //Assign
            var content = _contentService.GetById(new Guid("{373D1D1C-BD0D-4A8C-9A67-1D513815FE10}"));
            var children = _contentService.GetChildren(content.Id);
            var service = Substitute.For<IUmbracoService>();
            var predicate = Arg.Is<IContent>(x => children.Any(y => x.Id == y.Id));

            var config = new UmbracoChildrenConfiguration();
            config.InferType = false;
            config.IsLazy = false;
            config.PropertyInfo = typeof(Stub).GetProperty("Children");

            var mapper = new UmbracoChildrenMapper();

            //ME - Although this looks correct I am not sure it is
            service.ContentService.Returns(_contentService);
            service.CreateType(typeof(StubChild), predicate, false, false).ReturnsForAnyArgs(info => new StubChild
                                                                                  {
                                                                                      Id =  info.Arg<IContent>().Id
                                                                                  });

            var context = new UmbracoDataMappingContext(null, content, service);
            mapper.Setup(new DataMapperResolverArgs(null, config));

            //Act
            var result = mapper.MapToProperty(context) as IEnumerable<StubChild>;

            //Assert
            Assert.AreEqual(1, children.Count());
            Assert.AreEqual(children.Count(), result.Count());

            foreach (IContent child in children)
            {
                Assert.IsTrue(result.Any(x => x.Id == child.Id));
            }
        }
        /// <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;
        }
        public void MapToProperty_ContentHasNoChildren_NoObjectsCreated()
        {
            //Assign
            var content = _contentService.GetById(new Guid("{3F34475B-D744-40E9-BC30-5D33249FA9FE}"));
            var children = _contentService.GetChildren(content.Id);
            var service = Substitute.For<IUmbracoService>();
            var predicate = Arg.Is<IContent>(x => children.Any(y => x.Id == y.Id));

            var config = new UmbracoChildrenConfiguration();
            config.InferType = false;
            config.IsLazy = false;
            config.PropertyInfo = typeof(Stub).GetProperty("Children");

            var mapper = new UmbracoChildrenMapper();

            //ME - Although this looks correct I am not sure it is
            service.CreateType(typeof(StubChild), predicate, false, false).ReturnsForAnyArgs(info => new StubChild
            {
                Id = info.Arg<IContent>().Id
            });

            var context = new UmbracoDataMappingContext(null, content, service);
            mapper.Setup(new DataMapperResolverArgs(null, config));

            //Act
            var result = mapper.MapToProperty(context) as IEnumerable<StubChild>;

            //Assert
            Assert.AreEqual(0, result.Count());
        }
        public void CanHandle_ConfigIsChildren_ReturnsTrue()
        {
            //Assign
            var mapper = new UmbracoChildrenMapper();
            var config = new UmbracoChildrenConfiguration();

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

            //Assert
            Assert.IsTrue(result);
        }