Exemple #1
0
        public void MapToProperty_GetsValueByPropertyAlias_ReturnsPropertyValue()
        {
            //Assign
            var propertyValue = "test value set";
            var propertyAlias = "Property";
            var content       = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}"));

            var config = new UmbracoPropertyConfiguration();

            config.PropertyAlias = propertyAlias;

            var mapper = new StubMapper(null);

            mapper.Setup(new DataMapperResolverArgs(null, config));
            mapper.Value = propertyValue;

            var context = new UmbracoDataMappingContext(null, content, null, false);

            content.Properties[propertyAlias].Value = propertyValue;

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

            //Assert
            Assert.AreEqual(propertyValue, result);
        }
Exemple #2
0
        public void MapToProperty_GetsValueByFieldId_ReturnsFieldValue()
        {
            //Assign
            var fieldValue = "test value";
            var fieldId    = new ID("{6B43481F-F129-4F53-BEEE-EA84F9B1A6D4}");
            var database   = Sitecore.Configuration.Factory.GetDatabase("master");
            var item       = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToProperty");

            var config = new SitecoreFieldConfiguration();

            config.FieldId = fieldId;

            var mapper = new StubMapper(null);

            mapper.Setup(new DataMapperResolverArgs(null, config));
            mapper.Value = fieldValue;

            var context = new SitecoreDataMappingContext(null, item, null);

            using (new SecurityDisabler())
            {
                item.Editing.BeginEdit();
                item[fieldId] = fieldValue;
                item.Editing.EndEdit();
            }

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

            //Assert
            Assert.AreEqual(fieldValue, result);
        }
Exemple #3
0
        public void MapToProperty_GetsValueByFieldName_ReturnsFieldValue()
        {
            //Assign
            var templateId = ID.NewID;
            var fieldId    = ID.NewID;
            var targetId   = ID.NewID;

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { "Field", "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var fieldValue = "test value";
                var fieldName  = "Field";
                var item       =
                    database.GetItem("/sitecore/content/Target");
                var options = new GetItemOptionsParams();

                var config = new SitecoreFieldConfiguration();
                config.FieldName = fieldName;

                var mapper = new StubMapper(null);
                mapper.Setup(new DataMapperResolverArgs(null, config));
                mapper.Value = fieldValue;

                var context = new SitecoreDataMappingContext(null, item, null, options);

                using (new SecurityDisabler())
                {
                    item.Editing.BeginEdit();
                    item[fieldName] = fieldValue;
                    item.Editing.EndEdit();
                }

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

                //Assert
                Assert.AreEqual(fieldValue, result);
            }
        }
        public void MapToProperty_GetsValueByFieldId_ReturnsFieldValue()
        {
            //Assign
            var fieldValue = "test value";
            var fieldId = new ID("{6B43481F-F129-4F53-BEEE-EA84F9B1A6D4}");
            var database = Sitecore.Configuration.Factory.GetDatabase("master");
            var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToProperty");

            var config = new SitecoreFieldConfiguration();
            config.FieldId = fieldId;

            var mapper = new StubMapper(null);
            mapper.Setup(new DataMapperResolverArgs(null,config));
            mapper.Value = fieldValue;

            var context = new SitecoreDataMappingContext(null, item, null);

            using (new SecurityDisabler())
            {
                item.Editing.BeginEdit();
                item[fieldId] = fieldValue;
                item.Editing.EndEdit();
            }

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

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

        }
        public void MapToProperty_GetsValueByPropertyAlias_ReturnsPropertyValue()
        {
            //Assign
            var propertyValue = "test value set";
            var propertyAlias = "Property";
            var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}"));
           
            var config = new UmbracoPropertyConfiguration();
            config.PropertyAlias = propertyAlias;

            var mapper = new StubMapper(null);
            mapper.Setup(new DataMapperResolverArgs(null,config));
            mapper.Value = propertyValue;

            var context = new UmbracoDataMappingContext(null, content, null);

            content.Properties[propertyAlias].Value = propertyValue;

            //Act
            var result = mapper.MapToProperty(context);
            
            //Assert
            Assert.AreEqual(propertyValue, result);
        }
        public void MapToProperty_GetsValueByFieldId_ReturnsFieldValue()
        {
            //Assign
            var templateId = ID.NewID;
            var fieldId = ID.NewID;
            var targetId = ID.NewID;
            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    {fieldId, ""}
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),

            })
            {
                var fieldValue = "test value";
                var item =
                    database.GetItem("/sitecore/content/Target");

                var config = new SitecoreFieldConfiguration();
                config.FieldId = fieldId;

                var mapper = new StubMapper(null);
                mapper.Setup(new DataMapperResolverArgs(null, config));
                mapper.Value = fieldValue;

                var context = new SitecoreDataMappingContext(null, item, null);

                using (new SecurityDisabler())
                {
                    item.Editing.BeginEdit();
                    item[fieldId] = fieldValue;
                    item.Editing.EndEdit();
                }

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

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

            }
        }