Example #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);
        }
Example #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);
        }
Example #3
0
        public void ReadOnly_ReturnsTrue()
        {
            //Assign
            var mapper = new SitecoreItemMapper();

            //Act
            var result = mapper.ReadOnly;

            //Assert
            Assert.IsTrue(result);
        }
Example #4
0
        public void CanHandle_ConfigIsNotNodeAndClassMapped_ReturnsTrue()
        {
            //Assign
            var config  = new SitecoreFieldConfiguration();
            var context = Context.Create(Utilities.CreateStandardResolver());
            var mapper  = new SitecoreItemMapper();

            config.PropertyInfo = typeof(Stub).GetProperty("StubMapped");
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

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

            //Assert
            Assert.IsFalse(result);
        }
Example #5
0
        public void MapToProperty_MapsItemToProperty()
        {
            //Arrange
            var database = Sitecore.Configuration.Factory.GetDatabase("master");
            var item     = database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreItemMapper/Target");
            var mapper   = new SitecoreItemMapper();
            var obj      = new StubClass();

            var mappingContext = new SitecoreDataMappingContext(obj, item, null);

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

            //Assign
            Assert.AreEqual(item, result);
        }
        public void CanHandle_ConfigIsNodeAndClassNotMapped_ReturnsTrueOndemand()
        {
            //Assign
            var config  = new SitecoreNodeConfiguration();
            var context = Context.Create(Utilities.CreateStandardResolver());
            var mapper  = new SitecoreItemMapper();

            config.PropertyInfo = new FakePropertyInfo(typeof(StubNotMapped));
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

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

            //Assert
            Assert.IsTrue(result);
        }
Example #7
0
        public void MapToProperty_MapsItemToProperty()
        {
            //Arrange

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var item   = database.GetItem("/sitecore/content/TestItem");
                var mapper = new SitecoreItemMapper();
                var obj    = new StubClass();

                var mappingContext = new SitecoreDataMappingContext(obj, item, null);

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

                //Assign
                Assert.AreEqual(item, result);
            }
        }