Beispiel #1
0
        public void MapCmsToProperty_PageEditorOnly_FieldNotUpdated()
        {
            //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 set";
                var preValue   = "some other value";
                var fieldName  = "Field";
                var item       = database.GetItem("/sitecore/content/Target");
                var options    = new GetItemOptionsParams();

                var config = new SitecoreFieldConfiguration();
                config.FieldName    = fieldName;
                config.PropertyInfo = typeof(Stub).GetProperty("Property");
                config.ReadOnly     = false;
                config.Setting      = SitecoreFieldSettings.PageEditorOnly;

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

                Assert.IsFalse(mapper.ReadOnly);

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

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

                //Act
                using (new SecurityDisabler())
                {
                    item.Editing.BeginEdit();
                    mapper.MapCmsToProperty(context);
                    item.Editing.EndEdit();
                }
                //Assert
                var itemAfter =
                    database.GetItem("/sitecore/content/Target");
                Assert.AreEqual(mapper.Value, preValue);
                Assert.AreEqual(fieldValue, itemAfter[fieldName]);
            }
        }
Beispiel #2
0
        public void MapCmsToProperty_PageEditorOnly_FieldNotUpdated()
        {
            //Assign
            var fieldValue = "test value set";
            var preValue   = "some other value";
            var fieldName  = "Field";
            var database   = Sitecore.Configuration.Factory.GetDatabase("master");
            var item       = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms");

            var config = new SitecoreFieldConfiguration();

            config.FieldName    = fieldName;
            config.PropertyInfo = typeof(Stub).GetProperty("Property");
            config.ReadOnly     = false;
            config.Setting      = SitecoreFieldSettings.PageEditorOnly;

            var mapper = new StubMapper(null);

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

            Assert.IsFalse(mapper.ReadOnly);

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

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

            //Act
            using (new SecurityDisabler())
            {
                item.Editing.BeginEdit();
                mapper.MapCmsToProperty(context);
                item.Editing.EndEdit();
            }
            //Assert
            var itemAfter = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms");

            Assert.AreEqual(mapper.Value, preValue);
            Assert.AreEqual(fieldValue, itemAfter[fieldName]);
        }
        public void MapCmsToProperty_ValueFromCms_WritesToProperty()
        {
            //Assign
            var obj = new StubClass();
            var config = Substitute.For<AbstractPropertyConfiguration>();
            var  dataMapper = new StubMapper();

            AbstractDataMappingContext context = Substitute.For<AbstractDataMappingContext>(obj);
           dataMapper.Setup(new DataMapperResolverArgs(null, config));
            config.PropertyInfo = typeof(StubClass).GetProperties().First(x => x.Name == "AProperty");

            //Act
            dataMapper.MapCmsToProperty(context);

            //Assert
            Assert.AreEqual("Hello world", obj.AProperty);
            Assert.AreEqual(context, dataMapper.MappingContext);

        }
Beispiel #4
0
        public void MapCmsToProperty_ValueFromCms_WritesToProperty()
        {
            //Assign
            var obj        = new StubClass();
            var config     = Substitute.For <AbstractPropertyConfiguration>();
            var dataMapper = new StubMapper();

            AbstractDataMappingContext context = Substitute.For <AbstractDataMappingContext>(obj);

            dataMapper.Setup(new DataMapperResolverArgs(null, config));
            config.PropertyInfo = typeof(StubClass).GetProperties().First(x => x.Name == "AProperty");

            //Act
            dataMapper.MapCmsToProperty(context);

            //Assert
            Assert.AreEqual("Hello world", obj.AProperty);
            Assert.AreEqual(context, dataMapper.MappingContext);
        }
        public void MapCmsToProperty_PageEditorOnly_FieldNotUpdated()
        {
            //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 set";
                var preValue = "some other value";
                var fieldName = "Field";
                var item = database.GetItem("/sitecore/content/Target");

                var config = new SitecoreFieldConfiguration();
                config.FieldName = fieldName;
                config.PropertyInfo = typeof(Stub).GetProperty("Property");
                config.ReadOnly = false;
                config.Setting = SitecoreFieldSettings.PageEditorOnly;

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

                Assert.IsFalse(mapper.ReadOnly);

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

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

                //Act
                using (new SecurityDisabler())
                {
                    item.Editing.BeginEdit();
                    mapper.MapCmsToProperty(context);
                    item.Editing.EndEdit();

                }
                //Assert
                var itemAfter =
                    database.GetItem("/sitecore/content/Target");
                Assert.AreEqual(mapper.Value, preValue);
                Assert.AreEqual(fieldValue, itemAfter[fieldName]);
            }
        }
        public void MapCmsToProperty_PageEditorOnly_FieldNotUpdated()
        {
            //Assign
            var fieldValue = "test value set";
            var preValue = "some other value";
            var fieldName = "Field";
            var database = Sitecore.Configuration.Factory.GetDatabase("master");
            var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms");

            var config = new SitecoreFieldConfiguration();
            config.FieldName = fieldName;
            config.PropertyInfo = typeof(Stub).GetProperty("Property");
            config.ReadOnly = false;
            config.Setting = SitecoreFieldSettings.PageEditorOnly;

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

            Assert.IsFalse(mapper.ReadOnly);

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

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

            //Act
            using (new SecurityDisabler())
            {
                item.Editing.BeginEdit();
                mapper.MapCmsToProperty(context);
                item.Editing.EndEdit();

            }
            //Assert
            var itemAfter = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms");
            Assert.AreEqual(mapper.Value, preValue);
            Assert.AreEqual(fieldValue, itemAfter[fieldName]);

        }