public void MapToProperty_GetAllReferences_ReferrersListReturned()
        {
            //Act
            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreLinkedMapper/Target");

            //ME - when getting templates you have to disable the role manager
            using (new SecurityDisabler())
            {
                var template = Database.GetItem("/sitecore/templates/Tests/DataMappers/DataMappersSingleField");

                var config = new SitecoreLinkedConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("StubMappeds");
                config.Option       = SitecoreLinkedOptions.References;

                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

                var mapper = new SitecoreLinkedMapper();
                mapper.Setup(new DataMapperResolverArgs(context, config));

                var service = new SitecoreService(Database, context);

                //Act
                var result =
                    mapper.MapToProperty(new SitecoreDataMappingContext(null, item, service)) as IEnumerable <StubMapped>;

                //Assert
                Assert.AreEqual(1, result.Count());
                Assert.AreEqual(template.ID.Guid, result.First().Id);
            }
        }
Esempio n. 2
0
        /// <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 SitecoreLinkedConfiguration();

            this.Configure(propertyInfo, config);
            return(config);
        }
Esempio n. 3
0
        public void MapToProperty_GetAllReferences_ReferrersListReturned()
        {
            //Arrange
            var templateId = ID.NewID;
            var fieldId    = ID.NewID;
            var targetId   = ID.NewID;
            var language   = LanguageManager.GetLanguage("af-ZA");

            using (Db database = new Db
            {
                new DbTemplate(templateId),
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var target   = database.Database.GetItem("/sitecore/content/Target");
                var source   = database.Database.GetItem("/sitecore/content/Source");
                var template = database.Database.GetTemplate(templateId);

                var behavior = Substitute.For <Sitecore.Links.LinkDatabase>();

                behavior.GetReferences(target).Returns(new[]
                {
                    new Sitecore.Links.ItemLink(target, fieldId, template, template.InnerItem.Paths.FullPath),
                });


                using (new Sitecore.FakeDb.Links.LinkDatabaseSwitcher(behavior))
                {
                    //Act
                    var item = database.GetItem("/sitecore/content/Target");

                    //ME - when getting templates you have to disable the role manager
                    using (new SecurityDisabler())
                    {
                        var config = new SitecoreLinkedConfiguration();
                        config.PropertyInfo = typeof(StubClass).GetProperty("StubMappeds");
                        config.Option       = SitecoreLinkedOptions.References;

                        var context = Context.Create(Utilities.CreateStandardResolver());
                        context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(StubMapped)));


                        var mapper = new SitecoreLinkedMapper();
                        mapper.Setup(new DataMapperResolverArgs(context, config));

                        var service = new SitecoreService(database.Database, context);
                        var options = new GetItemOptionsParams();

                        //Act
                        var result =
                            mapper.MapToProperty(new SitecoreDataMappingContext(null, item, service, options)) as
                            IEnumerable <StubMapped>;

                        //Assert
                        Assert.AreEqual(1, result.Count());
                        Assert.AreEqual(templateId.Guid, result.First().Id);
                    }
                }
            }
        }
Esempio n. 4
0
        public void MapToProperty_GetAllReferrers_ReferrersListReturned()
        {
            //Assign
            var templateId = ID.NewID;
            var fieldId    = ID.NewID;
            var targetId   = ID.NewID;
            var language   = LanguageManager.GetLanguage("af-ZA");

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
                new Sitecore.FakeDb.DbItem("Source", ID.NewID, templateId)
                {
                    new DbField("Field", fieldId)
                    {
                        { language.Name, 1, targetId.ToString() }
                    }
                }
            })
            {
                var target = database.Database.GetItem("/sitecore/content/Target");
                var source = database.Database.GetItem("/sitecore/content/Source", language);

                var behavior = Substitute.For <Sitecore.Links.LinkDatabase>();

                behavior.GetReferrers(target).Returns(new[]
                {
                    new Sitecore.Links.ItemLink(source, fieldId, target, target.Paths.FullPath),
                });

                using (new Sitecore.FakeDb.Links.LinkDatabaseSwitcher(behavior))
                {
                    var config = new SitecoreLinkedConfiguration();
                    config.PropertyInfo = typeof(StubClass).GetProperty("StubMappeds");
                    config.Option       = SitecoreLinkedOptions.Referrers;

                    var context = Context.Create(Utilities.CreateStandardResolver());
                    context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(StubMapped)));

                    var mapper = new SitecoreLinkedMapper();
                    mapper.Setup(new DataMapperResolverArgs(context, config));

                    var service = new SitecoreService(database.Database, context);
                    var options = new GetItemOptionsParams();

                    //Act

                    var result =
                        mapper.MapToProperty(new SitecoreDataMappingContext(null, target, service, options)) as
                        IEnumerable <StubMapped>;

                    //Assert
                    Assert.AreEqual(1, result.Count());
                    Assert.AreEqual(source.ID.Guid, result.First().Id);
                    Assert.AreEqual(language, result.First().Language);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <param name="config">The config.</param>
        public void Configure(PropertyInfo propertyInfo, SitecoreLinkedConfiguration config)
        {
            config.Option = this.Option;
            if (TemplateId.HasValue())
            {
                config.TemplateId = new ID(TemplateId);
            }
            config.EnforceTemplate = EnforceTemplate;

            base.Configure(propertyInfo, config);
        }
Esempio n. 6
0
        public void CanHandle_IsListOfMappedClassWithLinkedConfig_ReturnsFalse()
        {
            //Assign
            var config = new SitecoreLinkedConfiguration();

            config.PropertyInfo = new FakePropertyInfo(typeof(List <StubMapped>));
            var mapper  = new SitecoreLinkedMapper();
            var context = Context.Create(Utilities.CreateStandardResolver());

            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));


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

            //Assert
            Assert.IsFalse(result);
        }
        public void MapToProperty_GetAll_ReferrersListReturned()
        {
            //Assign
            var item     = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreLinkedMapper/Target");
            var language = LanguageManager.GetLanguage("af-ZA");

            var source = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreLinkedMapper/Source",
                                          language);

            using (new ItemEditing(source, true))
            {
                source[FieldName] = "<a href=\"~/link.aspx?_id=216C0015-8626-4951-9730-85BCA34EC2A3&amp;_z=z\">Source</a>";
            }


            //ME - when getting templates you have to disable the role manager
            using (new SecurityDisabler())
            {
                var template = Database.GetItem("/sitecore/templates/Tests/DataMappers/DataMappersSingleField");


                var config = new SitecoreLinkedConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("StubMappeds");
                config.Option       = SitecoreLinkedOptions.All;

                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

                var mapper = new SitecoreLinkedMapper();
                mapper.Setup(new DataMapperResolverArgs(context, config));

                var service = new SitecoreService(Database, context);

                //Act
                var result =
                    mapper.MapToProperty(new SitecoreDataMappingContext(null, item, service)) as IEnumerable <StubMapped>;

                //Assert
                Assert.AreEqual(2, result.Count());
                Assert.AreEqual(template.ID.Guid, result.First().Id);
                Assert.AreEqual(source.ID.Guid, result.Skip(1).First().Id);
                Assert.AreEqual(source.Language, result.Skip(1).First().Language);
            }
        }
        public void CanHandle_IsEnumerableOfNotMappedClassWithLinkedConfig_ReturnsTrueOnDemand()
        {
            //Assign
            var config = new SitecoreLinkedConfiguration();

            config.PropertyInfo = typeof(StubClass).GetProperty("StubNotMappeds");

            var mapper  = new SitecoreLinkedMapper();
            var context = Context.Create(Utilities.CreateStandardResolver());

            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));


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

            //Assert
            Assert.IsTrue(result);
        }
Esempio n. 9
0
        public void CanHandle_IsNonGenericOfMappedClassWithLinkedConfig_ReturnsTrue()
        {
            //Assign
            var config = new SitecoreLinkedConfiguration();

            config.PropertyInfo = typeof(StubClass).GetProperty("StubMapped");

            var mapper  = new SitecoreLinkedMapper();
            var context = Context.Create(Utilities.CreateStandardResolver());

            context.Load(new OnDemandLoader <SitecoreTypeConfiguration>(typeof(StubClass)));



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

            //Assert
            Assert.IsFalse(result);
        }
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <param name="config">The config.</param>
        public void Configure(PropertyInfo propertyInfo, SitecoreLinkedConfiguration config)
        {
            config.Option = this.Option;

            base.Configure(propertyInfo, config);
        }
 /// <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 SitecoreLinkedConfiguration();
     this.Configure(propertyInfo, config);
     return config;
 }
Esempio n. 12
0
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <param name="config">The config.</param>
        public void Configure(PropertyInfo propertyInfo, SitecoreLinkedConfiguration config)
        {
            config.Option = this.Option;

            base.Configure(propertyInfo, config);
        }