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
            });

            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());
        }
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <returns>AbstractPropertyConfiguration.</returns>
        public override Mapper.Configuration.AbstractPropertyConfiguration Configure(System.Reflection.PropertyInfo propertyInfo)
        {
            var config = new SitecoreChildrenConfiguration();

            base.Configure(propertyInfo, config);
            return(config);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public void MapToProperty_EnforceTemplate_OneObjectAreCreated()
        {
            //Assign


            ID templateId = ID.NewID;
            ID childId    = ID.NewID;

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                },
                new Sitecore.FakeDb.DbItem("TestItem")
                {
                    new Sitecore.FakeDb.DbItem("Child1", childId, templateId),
                    new Sitecore.FakeDb.DbItem("Child2"),
                    new Sitecore.FakeDb.DbItem("Child3")
                }
            })
            {
                var item    = database.GetItem("/sitecore/content/TestItem");
                var mapper  = new SitecoreChildrenMapper();
                var options = new GetItemOptionsParams();

                var config = new SitecoreChildrenConfiguration();
                config.InferType       = false;
                config.PropertyInfo    = typeof(Stub).GetProperty("Children");
                config.TemplateId      = templateId;
                config.EnforceTemplate = SitecoreEnforceTemplate.TemplateAndBase;

                var scContext = Context.Create(Utilities.CreateStandardResolver());

                var service = new SitecoreService(database.Database, scContext);


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

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

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

                //Assert

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

                Assert.AreEqual(childId, result.First().Id);
            }
        }
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <returns>AbstractPropertyConfiguration.</returns>
        public override Mapper.Configuration.AbstractPropertyConfiguration Configure(System.Reflection.PropertyInfo propertyInfo)
        {
            var config = new SitecoreChildrenConfiguration();

            if (TemplateId.HasValue())
            {
                config.TemplateId = new ID(TemplateId);
            }

            config.EnforceTemplate = EnforceTemplate;

            base.Configure(propertyInfo, config);
            return(config);
        }
        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));
                }
            }
        }
Пример #7
0
        public void MapToProperty_ItemHasThreeChildren_ThreeObjectAreCreated()
        {
            //Assign
            using (new EventDisabler())
                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 options = new GetItemOptionsParams();

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

                    var service = Substitute.For <ISitecoreService>();

                    service.GetItems(Arg.Any <GetItemsByFuncOptions>()).Returns(info => ((GetItemsByFuncOptions)info.Args()[0]).ItemsFunc(item.Database).Select(child => new StubChild {
                        Id = child.ID
                    }));

                    service.Config.Returns(new Config());

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

                    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));
                    }
                }
        }
Пример #8
0
        public void MapToProperty_ItemHasNoChildren_NoObjectsCreated()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
                {
                }
            })
            {
                var item    = database.GetItem("/sitecore/content/TestItem");
                var mapper  = new SitecoreChildrenMapper();
                var options = new GetItemOptionsParams();

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

                var scContext = Context.Create(Utilities.CreateStandardResolver());

                var service = new SitecoreService(database.Database, scContext);

                service.Config = new Config();

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

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

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

                //Assert

                Assert.AreEqual(0, result.Count());
            }
        }
 /// <summary>
 /// Configures the specified property info.
 /// </summary>
 /// <param name="propertyInfo">The property info.</param>
 /// <returns>AbstractPropertyConfiguration.</returns>
 public override Mapper.Configuration.AbstractPropertyConfiguration Configure(System.Reflection.PropertyInfo propertyInfo)
 {
     var config = new SitecoreChildrenConfiguration();
     base.Configure(propertyInfo, config);
     return config;
 }