Example #1
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);
                    }
                }
            }
        }
        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);
            }
        }
Example #3
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);
                }
            }
        }
        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);
            }
        }