Class SitecoreChildrenMapper
Inheritance: AbstractDataMapper
        public void MapToProperty_ItemHasThreeChildren_ThreeObjectAreCreated()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
                {
                    new Sitecore.FakeDb.DbItem("Child1"),
                    new Sitecore.FakeDb.DbItem("Child2"),
                    new Sitecore.FakeDb.DbItem("Child3")

                }
            })
            {

                var item = database.GetItem("/sitecore/content/TestItem");
                var mapper = new SitecoreChildrenMapper();

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

                var service = Substitute.For<ISitecoreService>();
                var predicate = Arg.Is<Item>(x => item.Children.Any(y => x.ID == y.ID));

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

                var context = new SitecoreDataMappingContext(null, item, service);

                mapper.Setup(new DataMapperResolverArgs(null, config));

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

                //Assert

                Assert.AreEqual(item.Children.Count, result.Count());

                foreach (Item child in item.Children)
                {
                    Assert.IsTrue(result.Any(x => x.Id == child.ID));
                }
            }

        }
        public void MapToProperty_ItemHasNoChildren_NoObjectsCreated()
        {
            //Assign
            var database = Sitecore.Configuration.Factory.GetDatabase("master");

            var item = database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreChildrenMapper/Parent/Child1");
            var mapper = new SitecoreChildrenMapper();

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

            var service = Substitute.For<ISitecoreService>();
            var predicate = Arg.Is<Item>(x => item.Children.Any(y => x.ID == y.ID));

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

            var context = new SitecoreDataMappingContext(null, item, 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 SitecoreChildrenMapper();
            var config = new SitecoreChildrenConfiguration();

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

            //Assert
            Assert.IsTrue(result);
        }
        public void ReadOnly_ReturnsTrue()
        {
            //Assign
            var mapper = new SitecoreChildrenMapper();

            //Act
            var result = mapper.ReadOnly;

            //Assert
            Assert.IsTrue(result);
        }