public void SetField_FielNonRichText_ValueWrittenToField()
        {
            //Assign
            var expected = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&amp;_z=z\">link</a></p>";
            var item     = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/SetField");
            var field    = item.Fields[FieldName];

            var mapper = new SitecoreFieldStringMapper();
            var config = new SitecoreFieldConfiguration();

            config.Setting = SitecoreFieldSettings.RichTextRaw;

            Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website");

            using (new ItemEditing(item, true))
            {
                field.Value = string.Empty;
            }

            //Act
            using (new ItemEditing(item, true))
            {
                mapper.SetField(field, expected, config, null);
            }

            Sitecore.Context.Site = null;

            //Assert
            Assert.AreEqual(expected, field.Value);
        }
Beispiel #2
0
        public void SetField_ForceRenderFieldPipeline_ThrowsException()
        {
            //Assign

            var fieldValue = "<p>hello world</p>";
            var expected   = "&lt;p&gt;hello world&lt;/p&gt;";

            var item  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetField");
            var field = item.Fields[FieldName];

            var mapper = new SitecoreFieldStringMapper();
            var config = new SitecoreFieldConfiguration();

            config.Setting      = SitecoreFieldSettings.ForceRenderField;
            config.PropertyInfo = new FakePropertyInfo(typeof(string), "String", typeof(StubClass));
            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }



            //Act
            mapper.SetField(field, fieldValue, config, null);

            //Assert
        }
        public void SetField_RichText_ThrowsException()
        {
            //Assign
            var expected = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&amp;_z=z\">link</a></p>";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
                {
                    new DbField(FieldName)
                    {
                        Type = "Rich Text"
                    }
                }
            })
            {
                using (new FakeSite())
                {
                    var item =
                        database.GetItem("/sitecore/content/TestItem");
                    var field = item.Fields[FieldName];

                    var mapper = new SitecoreFieldStringMapper();
                    var config = new SitecoreFieldConfiguration();
                    config.PropertyInfo = typeof(StubClass).GetProperty("String");


                    Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website");

                    using (new ItemEditing(item, true))
                    {
                        field.Value = string.Empty;
                    }

                    //Act
                    using (new ItemEditing(item, true))
                    {
                        //Rich text not raw throws exception
                        Assert.Throws <NotSupportedException>(() => mapper.SetField(field, expected, config, null));
                    }

                    Sitecore.Context.Site = null;

                    //Assert
                    Assert.AreEqual(string.Empty, field.Value);
                }
            }
        }
        public void SetField_ForceRenderFieldPipeline_ThrowsException()
        {
            //Assign

            var fieldValue = "<p>hello world</p>";
            var expected   = "&lt;p&gt;hello world&lt;/p&gt;";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
                {
                    new DbField(FieldName)
                    {
                        Value = fieldValue
                    }
                }
            })
            {
                var item  = database.GetItem("/sitecore/content/TestItem");
                var field = item.Fields[FieldName];

                var mapper = new SitecoreFieldStringMapper();
                var config = new SitecoreFieldConfiguration();
                config.Setting      = SitecoreFieldSettings.ForceRenderField;
                config.PropertyInfo = new FakePropertyInfo(typeof(string), "String", typeof(StubClass));
                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }



                //Act
                Assert.Throws <NotSupportedException>(() => mapper.SetField(field, fieldValue, config, null));

                //Assert
            }
        }