public void MapToProperty_ConfigurationIsLazy_CallsCreateClassOnServiceWithIsLazy()
        {
            //Assign
            var db        = Sitecore.Configuration.Factory.GetDatabase("master");
            var item      = db.GetItem("/sitecore/content/Tests/DataMappers/SitecoreParentMapperFixture/EmptyItem");
            var service   = Substitute.For <ISitecoreService>();
            var scContext = new SitecoreDataMappingContext(null, item, service);

            var config = new SitecoreParentConfiguration();

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

            var mapper = new SitecoreParentMapper();

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

            //Act
            var result = mapper.MapToProperty(scContext);

            //Assert

            //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
            service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is <Item>(x => x.ID == item.Parent.ID), true, false, null);
        }
Exemplo n.º 2
0
        public void MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var item      = database.GetItem("/sitecore/content/TestItem");
                var service   = Substitute.For <ISitecoreService>();
                var scContext = new SitecoreDataMappingContext(null, item, service);

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

                var mapper = new SitecoreParentMapper();
                mapper.Setup(new DataMapperResolverArgs(null, config));

                //Act
                var result = mapper.MapToProperty(scContext);

                //Assert

                //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
                service.Received()
                .CreateType(config.PropertyInfo.PropertyType, Arg.Is <Item>(x => x.ID == item.Parent.ID), true, false,
                            null);
            }
        }
Exemplo n.º 3
0
        public void MapToProperty_ConfigurationIsLazy_CallsCreateClassOnServiceWithIsLazy()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var item    = database.GetItem("/sitecore/content/TestItem");
                var service = Substitute.For <ISitecoreService>();
                var options = new GetItemOptionsParams();
                options.Lazy = LazyLoading.Enabled;
                var scContext = new SitecoreDataMappingContext(null, item, service, options);

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

                var mapper = new SitecoreParentMapper();
                mapper.Setup(new DataMapperResolverArgs(null, config));

                //Act
                var result = mapper.MapToProperty(scContext);

                //Assert

                service.Received()
                .GetItem(Arg.Is <GetItemByItemOptions>(x => x.Item.Uri == item.Parent.Uri &&
                                                       x.Lazy == LazyLoading.Enabled));
            }
        }
        public void MapToProperty_ParentDoesNotHaveLanguageVersion_ReturnsNull()
        {
            //Assign
            var db       = Sitecore.Configuration.Factory.GetDatabase("master");
            var language = LanguageManager.GetLanguage("af-ZA");
            var item     = db.GetItem("/sitecore/content/Tests/DataMappers/SitecoreParentMapperFixture/EmptyItem", language);

            //parent mustn't have a version
            Assert.AreEqual(0, item.Parent.Versions.Count);

            var service   = Substitute.For <ISitecoreService>();
            var scContext = new SitecoreDataMappingContext(null, item, service);

            var config = new SitecoreParentConfiguration();

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

            var mapper = new SitecoreParentMapper();

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

            //Act
            var result = mapper.MapToProperty(scContext);

            //Assert

            //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
            service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is <Item>(x => x.ID == item.Parent.ID), true, true, null);
            Assert.IsNull(result);
        }
Exemplo n.º 5
0
        public void MapToProperty_EnforceTemplate_ReturnsParentItem()
        {
            //Assign

            ID templateId = ID.NewID;
            ID parentID   = ID.NewID;

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Parent", parentID, templateId)
                {
                    new Sitecore.FakeDb.DbItem("TestItem")
                }
            })
            {
                var item    = database.GetItem("/sitecore/content/Parent/TestItem");
                var context = Context.Create(Utilities.CreateStandardResolver());
                var service = new SitecoreService(database.Database, context);
                var options = new GetItemOptionsParams();
                options.Lazy = LazyLoading.Enabled;
                var scContext = new SitecoreDataMappingContext(null, item, service, options);

                var config = new SitecoreParentConfiguration();
                config.PropertyInfo    = typeof(Stub).GetProperty("Property");
                config.TemplateId      = templateId;
                config.EnforceTemplate = SitecoreEnforceTemplate.TemplateAndBase;

                var mapper = new SitecoreParentMapper();
                mapper.Setup(new DataMapperResolverArgs(null, config));

                //Act
                var result = mapper.MapToProperty(scContext) as Stub;

                //Assert
                Assert.NotNull(result);
                Assert.AreEqual(parentID, result.Id);
            }
        }