Пример #1
0
        public void MapToProperty_GetItemByIdDifferentLanguageTargetDoesNotExistInLanguage_ReturnsNull()
        {
            //Assign
            var config   = new SitecoreNodeConfiguration();
            var context  = Context.Create(Utilities.CreateStandardResolver());
            var mapper   = new SitecoreItemMapper();
            var language = LanguageManager.GetLanguage("af-ZA");

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

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

            var obj      = new Stub();
            var source   = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreItemMapper/Source", language);
            var target   = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreItemMapper/TargetOneLanguage", language);
            var service  = Substitute.For <ISitecoreService>();
            var expected = new StubMapped();

            config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
            config.Id           = "{03CDE6B5-B2A2-40D6-A944-53D66DDD2CA4}";

            service.CreateType(
                typeof(StubMapped),
                Arg.Is <Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                false,
                false).Returns(expected);

            var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

            //Assert
            Assert.IsNull(result);
        }
Пример #2
0
        public void MapToProperty_GetItemByID_ReturnsItem()
        {
            //Assign
            var config   = new SitecoreNodeConfiguration();
            var context  = Context.Create(Utilities.CreateStandardResolver());
            var mapper   = new SitecoreItemMapper();
            var language = LanguageManager.GetLanguage("en");

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

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

            var obj      = new Stub();
            var source   = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreItemMapper/Source", language);
            var target   = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreItemMapper/Target", language);
            var service  = Substitute.For <ISitecoreService>();
            var expected = new StubMapped();

            config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
            config.Id           = "{EC4351CE-C5F1-4F01-B354-3D26DC7A66CD}";

            service.CreateType(
                typeof(StubMapped),
                Arg.Is <Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                false,
                false).Returns(expected);

            var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void MapToProperty_GetItemByPathDifferentLanguage_ReturnsItem()
        {
            //Assign

            var language = LanguageManager.GetLanguage("af-ZA");

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Source")
                {
                    new Sitecore.FakeDb.DbField("Title")
                    {
                        { language.Name, language.Name }
                    }
                },
                new Sitecore.FakeDb.DbItem("Target")
                {
                    new Sitecore.FakeDb.DbField("Title")
                    {
                        { language.Name, language.Name }
                    }
                },
            })
            {
                var config = new SitecoreNodeConfiguration();
                var mapper = new SitecoreNodeMapper();

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

                var obj      = new Stub();
                var source   = database.Database.GetItem("/sitecore/content/Source", language);
                var target   = database.Database.GetItem("/sitecore/content/Target", language);
                var service  = Substitute.For <ISitecoreService>();
                var expected = new StubMapped();

                config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
                config.Path         = "/sitecore/content/Target";

                service.CreateType(
                    typeof(StubMapped),
                    Arg.Is <Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                    false,
                    false, null).Returns(expected);
                service.ItemVersionHandler.VersionCountEnabledAndHasVersions(target).Returns(true);

                var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

                //Assert
                Assert.AreEqual(expected, result);
            }
        }
Пример #4
0
        public void MapToProperty_GetItemByPathDifferentLanguage_ReturnsItem()
        {
            //Assign

            var language = LanguageManager.GetLanguage("af-ZA");

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Source")
                {
                    new Sitecore.FakeDb.DbField("Title")
                    {
                        { language.Name, language.Name }
                    }
                },
                new Sitecore.FakeDb.DbItem("Target")
                {
                    new Sitecore.FakeDb.DbField("Title")
                    {
                        { language.Name, language.Name }
                    }
                },
            })
            {
                var config = new SitecoreNodeConfiguration();
                var mapper = new SitecoreNodeMapper();

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

                var obj      = new Stub();
                var source   = database.Database.GetItem("/sitecore/content/Source", language);
                var target   = database.Database.GetItem("/sitecore/content/Target", language);
                var service  = Substitute.For <ISitecoreService>();
                var expected = new StubMapped();
                var options  = new GetItemOptionsParams();

                config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
                config.Path         = "/sitecore/content/Target";


                service.GetItem(Arg.Is <GetItemByItemOptions>(x => x.Item.Uri == target.Uri)).Returns(expected);


                var mappingContext = new SitecoreDataMappingContext(obj, source, service, options);

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

                //Assert
                Assert.AreEqual(expected, result);
            }
        }
        public void MapToProperty_GetItemByPathIsLazy_ReturnsItem()
        {
            //Assign
            var config   = new SitecoreNodeConfiguration();
            var context  = Context.Create(FakeDb.Utilities.CreateStandardResolver());
            var mapper   = new SitecoreNodeMapper();
            var language = LanguageManager.GetLanguage("en");

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

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

            var obj = new Stub();

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Source"),
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var source   = database.Database.GetItem("/sitecore/content/Source", language);
                var target   = database.Database.GetItem("/sitecore/content/Target", language);
                var service  = Substitute.For <ISitecoreService>();
                var expected = new StubMapped();

                config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
                config.Path         = "/sitecore/content/Target";
                config.IsLazy       = true;

                service.CreateType(
                    typeof(StubMapped),
                    Arg.Is <Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                    true,
                    false, null).Returns(expected);

                service.ItemVersionHandler.VersionCountEnabledAndHasVersions(target).Returns(true);



                var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

                //Assert
                Assert.AreEqual(expected, result);
            }
        }
Пример #6
0
        public void MapToProperty_GetItemByPathIsLazy_ReturnsItem()
        {
            //Assign
            var config   = new SitecoreNodeConfiguration();
            var context  = Context.Create(FakeDb.Utilities.CreateStandardResolver());
            var mapper   = new SitecoreNodeMapper();
            var language = LanguageManager.GetLanguage("en");

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

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

            var obj = new Stub();

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Source"),
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var source   = database.Database.GetItem("/sitecore/content/Source", language);
                var target   = database.Database.GetItem("/sitecore/content/Target", language);
                var service  = Substitute.For <ISitecoreService>();
                var expected = new StubMapped();
                var options  = new GetItemOptionsParams
                {
                    Lazy = LazyLoading.Enabled
                };

                config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
                config.Path         = "/sitecore/content/Target";


                service.GetItem(Arg.Is <GetItemByItemOptions>(x => x.Item.Uri == target.Uri && x.Lazy == LazyLoading.Enabled)).Returns(expected);

                var mappingContext = new SitecoreDataMappingContext(obj, source, service, options);

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

                //Assert
                Assert.AreEqual(expected, result);
            }
        }
Пример #7
0
        public void MapToProperty_GetItemByPathIsLazy_ReturnsItem()
        {
            //Assign
            var config   = new SitecoreNodeConfiguration();
            var context  = Context.Create(Utilities.CreateStandardResolver());
            var mapper   = new SitecoreNodeMapper();
            var language = LanguageManager.GetLanguage("en");

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

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

            var obj     = new Stub();
            var source  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Source", language);
            var target  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Target", language);
            var service = Substitute.For <ISitecoreService>();

            var itemVersionHandler = Substitute.For <IItemVersionHandler>();

            itemVersionHandler.VersionCountEnabledAndHasVersions(Arg.Any <Item>()).Returns(true);
            service.ItemVersionHandler.Returns(itemVersionHandler);

            var expected = new StubMapped();

            config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
            config.Path         = "/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Target";
            config.IsLazy       = true;

            service.CreateType(
                typeof(StubMapped),
                Arg.Is <Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                true,
                false, null).Returns(expected);

            var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void MapToProperty_GetItemByPathInferType_ReturnsItem()
        {
            //Assign
            var config = new SitecoreNodeConfiguration();
            var context = Context.Create(Utilities.CreateStandardResolver());
            var mapper = new SitecoreNodeMapper();
            var language = LanguageManager.GetLanguage("en");
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

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

            var obj = new Stub();
            var source = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Source", language);
            var target = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Target", language);
            var service = Substitute.For<ISitecoreService>();
            var itemVersionHandler = Substitute.For<IItemVersionHandler>();
            itemVersionHandler.VersionCountEnabledAndHasVersions(Arg.Any<Item>()).Returns(true);
            service.ItemVersionHandler.Returns(itemVersionHandler);

            var expected = new StubMapped();

            config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
            config.Path = "/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Target";
            config.InferType = true;

            service.CreateType(
                typeof(StubMapped),
                Arg.Is<Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                false,
                true, null).Returns(expected);

            var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

            //Assert
            Assert.AreEqual(expected, result);

        }
        public void MapToProperty_GetItemByIdDifferentLanguageTargetDoesNotExistInLanguage_ReturnsNull()
        {
            //Assign
            var config = new SitecoreNodeConfiguration();
            var context = Context.Create(Utilities.CreateStandardResolver());
            var mapper = new SitecoreNodeMapper();
            var language = LanguageManager.GetLanguage("af-ZA");
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

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

            var obj = new Stub();
            var source = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Source", language);
            var target = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/TargetOneLanguage", language);
            var service = Substitute.For<ISitecoreService>();
            var expected = new StubMapped();

            config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
            config.Id = "{03CDE6B5-B2A2-40D6-A944-53D66DDD2CA4}";

            service.CreateType(
                typeof(StubMapped),
                Arg.Is<Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                false,
                false, null).Returns(expected);

            var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

            //Assert
            Assert.IsNull(result);
        }
Пример #10
0
        public void MapToProperty_GetItemByIdDifferentLanguage_ReturnsItem()
        {
            //Assign
            var config = new SitecoreNodeConfiguration();
            var context = Context.Create(Utilities.CreateStandardResolver());
            var mapper = new SitecoreItemMapper();
            var language = LanguageManager.GetLanguage("af-ZA");
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

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

            var obj = new Stub();
            var source = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreItemMapper/Source", language);
            var target = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreItemMapper/Target", language);
            var service = Substitute.For<ISitecoreService>();
            var expected = new StubMapped();

            config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
            config.Id = "{EC4351CE-C5F1-4F01-B354-3D26DC7A66CD}";

            service.CreateType(
                typeof(StubMapped),
                Arg.Is<Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                false,
                false).Returns(expected);

            var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void MapToProperty_GetItemByPath_ReturnsItem()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Source"),
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var config = new SitecoreNodeConfiguration();
                var mapper = new SitecoreNodeMapper();
                var language = LanguageManager.GetLanguage("en");

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

                var obj = new Stub();
                var source = database.Database.GetItem("/sitecore/content/Source", language);
                var target = database.Database.GetItem("/sitecore/content/Target", language);
                var service = Substitute.For<ISitecoreService>();
                var expected = new StubMapped();

                config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
                config.Path = "/sitecore/content/Target";

                service.CreateType(
                    typeof(StubMapped),
                    Arg.Is<Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                    false,
                    false, null).Returns(expected);
                service.ItemVersionHandler.VersionCountEnabledAndHasVersions(target).Returns(true);
                var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

                //Assert
                Assert.AreEqual(expected, result);
            }

        }
        public void MapToProperty_GetItemByIdDifferentLanguageTargetDoesNotExistInLanguage_ReturnsNull()
        {
            //Assign
            var config = new SitecoreNodeConfiguration();
            var context = Context.Create(FakeDb.Utilities.CreateStandardResolver());
            var mapper = new SitecoreNodeMapper();
            var language = LanguageManager.GetLanguage("af-ZA");
            context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubMapped)));


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

            var obj = new Stub();

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Source"),
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var source = database.Database.GetItem("/sitecore/content/Source", language);
                var target = database.Database.GetItem("/sitecore/content/Target", language);
                var service = Substitute.For<ISitecoreService>();
                var expected = new StubMapped();

                config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
                config.Id = target.ID.Guid.ToString();

                service.CreateType(
                    typeof(StubMapped),
                    Arg.Is<Item>(x => x.Paths.FullPath == target.Paths.FullPath && x.Language == language),
                    false,
                    false, null).Returns(expected);

                service.ItemVersionHandler.VersionCountEnabledAndHasVersions(target).Returns(false);

                var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

                //Assert
                Assert.IsNull(result);
            }
        }
        public void MapToProperty_GetItemByPathDifferentLanguageTargetDoesNotExistInLanguage_ReturnsNull()
        {
            //Assign
            var config = new SitecoreNodeConfiguration();
            var mapper = new SitecoreNodeMapper();
            var language = LanguageManager.GetLanguage("af-ZA");

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Source")
                {
                    new Sitecore.FakeDb.DbField("Title")
                    {
                        {language.Name, language.Name}
                    }
                },
                new Sitecore.FakeDb.DbItem("TargetOneLanguage")
                {
                   
                },
            })
            {
                mapper.Setup(new DataMapperResolverArgs(null, config));

                var obj = new Stub();
                var source = database.Database.GetItem("/sitecore/content/Source", language);
                var target = database.Database.GetItem(
                    "/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/TargetOneLanguage", language);
                var service = Substitute.For<ISitecoreService>();
                var expected = new StubMapped();

                config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
                config.Path = "/sitecore/content/Tests/DataMappers/SitecoreNodeMapper/Target";

                service.CreateType(
                    typeof(StubMapped),
                    Arg.Is<Item>(x => 
                        x.Paths.FullPath == target.Paths.FullPath 
                        && x.Language == language
                        && x.Versions.Count == 0),
                    false,
                    false, null).Returns(expected);

                var mappingContext = new SitecoreDataMappingContext(obj, source, service);

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

                //Assert
                Assert.IsNull(result);
            }
        }