예제 #1
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());
        }
예제 #2
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));
        }
예제 #3
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);
        }
예제 #4
0
        public void ReadOnly_ReturnsTrue()
        {
            //Assign
            var mapper = new SitecoreQueryMapper(null);

            //Act
            var result = mapper.ReadOnly;

            //Assert
            Assert.IsTrue(result);
        }
예제 #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));
            }
        }
예제 #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);
        }
예제 #7
0
        public void CanHandle_IncorrectConfigMappedClass_ReturnsFalse()
        {
            //Assign
            var mapper = new SitecoreQueryMapper(null);
            var config = new SitecoreFieldConfiguration();

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

            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);
        }
예제 #8
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());
            }
        }
예제 #9
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);
        }
예제 #10
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);
            }
        }
예제 #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);
            }
        }