Beispiel #1
0
        public void GetViewValue_FieldPointsAtFile_ReturnFileObject()
        {
            //Assign
            var templateId = ID.NewID;
            var fieldId    = ID.NewID;
            var targetId   = ID.NewID;
            var expected   = "/~/media/C10794CE624F4F72A2B914336F3FB582.ashx";
            var mediaId    = new ID("{C10794CE-624F-4F72-A2B9-14336F3FB582}");

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { "Field", "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
                new DbItem("Media", mediaId)
            })
            {
                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    Substitute.For <Sitecore.Resources.Media.MediaProvider>();
                mediaProvider
                .GetMediaUrl(
                    Arg.Is <Sitecore.Data.Items.MediaItem>(
                        i => i.ID == mediaId)
                    )
                .Returns(expected);

                using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider))
                {
                    var fieldValue =
                        "<file mediaid=\"{C10794CE-624F-4F72-A2B9-14336F3FB582}\" src=\"~/media/C10794CE624F4F72A2B914336F3FB582.ashx\" />";

                    var item   = database.GetItem("/sitecore/content/Target");
                    var field  = item.Fields["Field"];
                    var mapper = new SitecoreFieldFileMapper();

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

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

                    //Assert
                    Assert.AreEqual(mediaId.Guid, result.Id);
                    Assert.AreEqual(expected, result.Src);
                }
            }
        }
        public void GetViewValue_FieldEmpty_ReturnEmptyValues()
        {
            //Assign
            var fieldValue = string.Empty;

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

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

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

            //Assert
            Assert.AreEqual(Guid.Empty, result.Id);
            Assert.AreEqual(null, result.Src);
        }
        public void GetViewValue_FieldPointsAtFile_ReturnFileObject()
        {
            //Assign
            var fieldValue =
                "<file mediaid=\"{C10794CE-624F-4F72-A2B9-14336F3FB582}\" src=\"~/media/C10794CE624F4F72A2B914336F3FB582.ashx\" />";

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

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

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

            //Assert
            Assert.AreEqual(new Guid("{C10794CE-624F-4F72-A2B9-14336F3FB582}"), result.Id);
            Assert.IsTrue(result.Src.EndsWith("/~/media/C10794CE624F4F72A2B914336F3FB582.ashx"));
        }
        public void GetViewValue_FieldEmpty_ReturnEmptyValues()
        {
            //Assign
            var templateId = ID.NewID;
            var fieldId    = ID.NewID;
            var targetId   = ID.NewID;
            var mediaId    = new ID("{C10794CE-624F-4F72-A2B9-14336F3FB582}");

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { "Field", "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
                new DbItem("Media", mediaId)
            })
            {
                var fieldValue = string.Empty;


                var item   = database.GetItem("/sitecore/content/Target");
                var field  = item.Fields["Field"];
                var mapper = new SitecoreFieldFileMapper();

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

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

                //Assert
                Assert.AreEqual(Guid.Empty, result.Id);
                Assert.AreEqual(null, result.Src);
            }
        }