Exemple #1
0
        public void MapToProperty_AbsoluteQueryWithParameter_ReturnsResults()
        {
            //Assign
            //Assign
            var config = new SitecoreQueryConfiguration();

            config.PropertyInfo    = typeof(StubClass).GetProperty("StubMappeds");
            config.Query           = "{path}/../Results/*";
            config.IsRelative      = false;
            config.UseQueryContext = true;

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

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

            var mapper = new SitecoreQueryMapper(null);

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

            var source  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Source");
            var service = new SitecoreService(Database, context);

            var result1 = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Results/Result1");
            var result2 = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Results/Result2");

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

            //Assert
            Assert.AreEqual(2, results.Count());
            Assert.IsTrue(results.Any(x => x.Id == result1.ID.Guid));
            Assert.IsTrue(results.Any(x => x.Id == result2.ID.Guid));
        }
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <returns>AbstractPropertyConfiguration.</returns>
        public override AbstractPropertyConfiguration Configure(PropertyInfo propertyInfo)
        {
            var config = new SitecoreQueryConfiguration();

            Configure(propertyInfo, config);
            return(config);
        }
Exemple #3
0
        public void MapToProperty_RelativeQuery_ReturnsNoResults()
        {
            //Assign
            //Assign
            var config = new SitecoreQueryConfiguration();

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

            config.Query      = "../Results/DoesNotExist/*";
            config.IsRelative = true;

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

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

            var mapper = new SitecoreQueryMapper(null);

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

            var source  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Source");
            var service = new SitecoreService(Database, context);

            var result1 = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Results/Result1");
            var result2 = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Results/Result2");

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

            //Assert
            Assert.AreEqual(0, results.Count());
        }
Exemple #4
0
        public void MapToProperty_AbsoluteQuery_ReturnsSingleResults()
        {
            //Assign
            //Assign
            var config = new SitecoreQueryConfiguration();

            config.PropertyInfo = typeof(StubClass).GetProperty("StubMapped");
            config.Query        = "/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Results/Result1";
            config.IsRelative   = false;

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

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

            var mapper = new SitecoreQueryMapper(null);

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

            var source  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Source");
            var service = new SitecoreService(Database, context);

            var result1 = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreQueryMapper/Results/Result1");

            //Act
            var result =
                mapper.MapToProperty(new SitecoreDataMappingContext(null, source, service)) as StubMapped;

            //Assert
            Assert.AreEqual(result1.ID.Guid, result.Id);
        }
Exemple #5
0
        public void MapToProperty_AbsoluteQueryWithParameter_ReturnsResults()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
                {
                },
                new Sitecore.FakeDb.DbItem("Results")
                {
                    new Sitecore.FakeDb.DbItem("Child1"),
                    new Sitecore.FakeDb.DbItem("Child2")
                }
            })
            {
                var config = new SitecoreQueryConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("StubMappeds");
                config.Query        = "{path}/../Results/*";
                config.IsRelative   = false;


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

                var mapper = new SitecoreQueryMapper(new[] { new ItemPathParameter() });
                mapper.Setup(new DataMapperResolverArgs(context, config));

                var source  = database.GetItem("/sitecore/content/Target");
                var service = new SitecoreService(database.Database, context);

                var result1 = database.GetItem("/sitecore/content/Results/Child1");
                var result2 = database.GetItem("/sitecore/content/Results/Child2");
                var options = new GetItemOptionsParams();

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

                //Assert
                Assert.AreEqual(2, results.Count());
                Assert.IsTrue(results.Any(x => x.Id == result1.ID.Guid));
                Assert.IsTrue(results.Any(x => x.Id == result2.ID.Guid));
            }
        }
Exemple #6
0
        public void CanHandle_CorrectConfigNotMappedClass_ReturnsTrueOnDemand()
        {
            //Assign
            var mapper = new SitecoreQueryMapper(null);
            var config = new SitecoreQueryConfiguration();

            config.PropertyInfo = new FakePropertyInfo(typeof(StubNotMapped));
            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);
        }
Exemple #7
0
        public void MapToProperty_RelativeQueryEnforceTemplate_ReturnsNoResults()
        {
            //Assign

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

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
                {
                    new Sitecore.FakeDb.DbItem("Child1", childId, templateId),
                    new Sitecore.FakeDb.DbItem("Child2")
                }
            })
            {
                var config = new SitecoreQueryConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("StubMappeds");

                config.Query           = "../Target/*";
                config.IsRelative      = true;
                config.TemplateId      = templateId;
                config.EnforceTemplate = SitecoreEnforceTemplate.TemplateAndBase;

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

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

                var source  = database.GetItem("/sitecore/content/Target");
                var service = new SitecoreService(database.Database, context);
                var options = new GetItemOptionsParams();

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

                //Assert
                Assert.AreEqual(1, results.Count());
            }
        }
Exemple #8
0
        public void CanHandle_CorrectConfigNotMappedClass_ReturnsTrueOnDemand()
        {
            //Assign
            var mapper = new SitecoreQueryMapper(null);
            var config = new SitecoreQueryConfiguration();

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

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

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



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

            //Assert
            Assert.IsTrue(result);
        }
Exemple #9
0
        public void MapToProperty_RelativeQuerySelf_ReturnsSelf()
        {
            //Assign
            //Assign

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
                {
                    new Sitecore.FakeDb.DbItem("Child1"),
                    new Sitecore.FakeDb.DbItem("Child2")
                }
            })
            {
                var config = new SitecoreQueryConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("StubMapped");

                config.Query      = "ancestor-or-self::*";
                config.IsRelative = true;

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

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

                var source  = database.GetItem("/sitecore/content/Target");
                var service = new SitecoreService(database.Database, context);
                var options = new GetItemOptionsParams();

                //Act
                var result =
                    mapper.MapToProperty(new SitecoreDataMappingContext(null, source, service, options)) as StubMapped;

                //Assert
                Assert.AreEqual(source.ID.Guid, result.Id);
            }
        }
 /// <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, SitecoreQueryConfiguration config)
 {
     config.UseQueryContext = this.UseQueryContext;
     base.Configure(propertyInfo, (QueryConfiguration)config);
 }
Exemple #11
0
        public void MapToProperty_AbsoluteQueryMultiLanguages_ReturnsResults()
        {
            //Assign

            var templateId = ID.NewID;


            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
                {
                    new DbTemplate(templateId)
                    {
                        { "title", "" }
                    },
                    new Sitecore.FakeDb.DbItem("Child1", new ID(Guid.NewGuid()), templateId)
                    {
                        Fields =
                        {
                            new DbField("title")
                            {
                                { "en", "test en" },
                                { "da", "test"    }
                            }
                        }
                    },
                    new Sitecore.FakeDb.DbItem("Child2", new ID(Guid.NewGuid()), templateId)
                    {
                        Fields =
                        {
                            new DbField("title")
                            {
                                { "en", "test en" },
                                { "da", "test1"   }
                            }
                        },
                    }
                }
            })
            {
                var config = new SitecoreQueryConfiguration();
                config.PropertyInfo = typeof(StubClass).GetProperty("StubMappeds");

                config.Query      = "/sitecore/content/Target/Child2";
                config.IsRelative = false;

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

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

                var source  = database.GetItem("/sitecore/content/Target/child1", "da");
                var service = new SitecoreService(database.Database, context);

                var options = new GetItemOptionsParams();

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

                //Assert
                Assert.AreEqual(1, results.Count());
                Assert.AreEqual("test1", results.First().Title);
            }
        }
 /// <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, SitecoreQueryConfiguration config)
 {
     config.UseQueryContext = this.UseQueryContext;
     base.Configure(propertyInfo, (QueryConfiguration) config);
 }
 /// <summary>
 /// Configures the specified property info.
 /// </summary>
 /// <param name="propertyInfo">The property info.</param>
 /// <returns>AbstractPropertyConfiguration.</returns>
 public override AbstractPropertyConfiguration Configure(PropertyInfo propertyInfo)
 {
     var config = new SitecoreQueryConfiguration();
     Configure(propertyInfo, config);
     return config;
 }
Exemple #14
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, SitecoreQueryConfiguration config)
 {
     base.Configure(propertyInfo, (QueryConfiguration)config);
 }