public void GetField_ImageInField_ReturnsImageObject()
        {
            //Assign
            var fieldValue =
                "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";

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

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

            //Act
            var result = mapper.GetField(field, null, null) as Image;

            //Assert
            Assert.AreEqual("test alt", result.Alt);
            // Assert.Equals(null, result.Border);
            Assert.AreEqual(string.Empty, result.Class);
            Assert.AreEqual(15, result.HSpace);
            Assert.AreEqual(480, result.Height);
            Assert.AreEqual(new Guid("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}"), result.MediaId);
            Assert.IsTrue(result.Src.EndsWith("/~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx"));
            Assert.AreEqual(20, result.VSpace);
            Assert.AreEqual(640, result.Width);
        }
        public void GetField_ImageInField_ReturnsImageObject()
        {
            //Assign
            var fieldValue =
                "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";
            var mediaId = new ID("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}");

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
                {
                    new DbField(FieldName)
                    {
                        Value = fieldValue
                    }
                },
                new Sitecore.FakeDb.DbItem("MediaItem", mediaId)
                {
                    new DbField("alt") {Value = "test alt"},
                    new DbField("height") {Value = "480"},
                    new DbField("width") {Value = "640"},
                }
            })
            {

                Sitecore.Resources.Media.MediaProvider mediaProvider = Substitute.For<Sitecore.Resources.Media.MediaProvider>();
                mediaProvider
                      .GetMediaUrl(Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == mediaId))
                      .Returns("/~/media/Test.ashx");

                using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider))
                {

                    var item = database.GetItem("/sitecore/content/TestItem");
                    var field = item.Fields[FieldName];
                    var mapper = new SitecoreFieldImageMapper();

                    //Act
                    var result = mapper.GetField(field, null, null) as Image;

                    //Assert
                    Assert.AreEqual("test alt", result.Alt);
                    // Assert.Equals(null, result.Border);
                    Assert.AreEqual(string.Empty, result.Class);
                    Assert.AreEqual(15, result.HSpace);
                    Assert.AreEqual(480, result.Height);
                    Assert.AreEqual(new Guid("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}"), result.MediaId);
                    Assert.IsTrue(result.Src.EndsWith("/~/media/Test.ashx"));
                    Assert.AreEqual(20, result.VSpace);
                    Assert.AreEqual(640, result.Width);
                }
            }
        }
        public void GetField_FieldIsEmpty_ReturnsNullImageObject()
        {
            //Assign
            var fieldValue = string.Empty;

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



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

            //Act
            var result = mapper.GetField(field, null, null) as Image;

            //Assert
            Assert.IsNull(result);
        }
        public void GetField_FieldIsEmpty_ReturnsNullImageObject()
        {
            //Assign
            var fieldValue = string.Empty;

            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldImageMapper/GetField");
            var field = item.Fields[FieldName];
            var mapper = new SitecoreFieldImageMapper();
            var service = Substitute.For<ISitecoreService>();
            service.Config = new Config();
            
            var context = new SitecoreDataMappingContext(null, null, service);


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


            //Act
            var result = mapper.GetField(field, null, context) as Image;

            //Assert
            Assert.IsNull(result);
        }
        public void GetField_FieldIsNull_ReturnsNullImageObject()
        {
            //Assign
            string fieldValue = null;

            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 SitecoreFieldImageMapper();

                var service = Substitute.For<ISitecoreService>();
                service.Config = new Config();

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


                //Act
                var result = mapper.GetField(field, null, context) as Image;

                //Assert
                Assert.IsNull(result);
            }
        }