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));
            }
        }
        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);
        }
        public void ReadOnly_ReturnsTrue()
        {
            //Assign
            var mapper = new UmbracoChildrenMapper();

            //Act
            var result = mapper.ReadOnly;

            //Assert
            Assert.IsTrue(result);
        }