コード例 #1
0
        public void SetField_ImagePassed_ReturnsPopulatedField()
        {
            //Assign
            var expected =
                "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" width=\"640\" vspace=\"50\" height=\"480\" hspace=\"30\" alt=\"test alt\" />";

            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldImageMapper/GetField");
            var field = item.Fields[FieldName];
            var mapper = new SitecoreFieldImageMapper();
            var image = new Image()
                            {
                                Alt = "test alt",
                                HSpace = 30,
                                Height = 480,
                                MediaId =  new Guid("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}"),
                                VSpace = 50,
                                Width = 640,
                                Border = String.Empty,
                                Class =  String.Empty

                            };

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

            //Act
            using (new ItemEditing(item, true))
            {
                mapper.SetField(field, image, null, null);
            }
            //Assert
            Assert.AreEqual(expected, field.Value);
        }
コード例 #2
0
        public void SetField_JustImageId_ReturnsPopulatedField()
        {
            //Assign
            var expected =
                "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" alt=\"\" />";

            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldImageMapper/GetField");
            var field = item.Fields[FieldName];
            var mapper = new SitecoreFieldImageMapper();
            var image = new Image()
            {
                MediaId = new Guid("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}"),
            };

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

            //Act
            using (new ItemEditing(item, true))
            {
                mapper.SetField(field, image, null, null);
            }
            //Assert
            Assert.AreEqual(expected, field.Value);
        }
コード例 #3
0
        public void SetField_JustImageId_ReturnsPopulatedField()
        {
            //Assign
            var expected =
                "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" />";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
                {
                    new DbField(FieldName)
                },
                new Sitecore.FakeDb.DbItem("MediaItem", new ID("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}"))
            })
            {
                var item = database.GetItem("/sitecore/content/TestItem");
                var field = item.Fields[FieldName];
                var mapper = new SitecoreFieldImageMapper();
                var image = new Image()
                {
                    MediaId = new Guid("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}"),
                };

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

                //Act
                using (new ItemEditing(item, true))
                {
                    mapper.SetField(field, image, null, null);
                }
                //Assert
                AssertHtml.AreHtmlElementsEqual(expected, field.Value, "image");

            }
        }