Example #1
0
        public void SetField_InternalLinkMissingTarget_ThorwsException()
        {
            //Assign
            var mapper = new SitecoreFieldLinkMapper();

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

            var value = new Link()
            {
                Anchor   = "testAnchor",
                Class    = "testClass",
                Query    = "q=s",
                Target   = "testTarget",
                TargetId = new Guid("{11111111-3B6F-4F5F-A5C2-FD2B9D5A47A0}"),
                Text     = "Test description",
                Title    = "test alternative",
                Type     = LinkType.Internal,
                Url      = ""
            };


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

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

            //Assert
        }
        public void SetField_InternalLink_InternalLinkSetOnField()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());

#if SC93 || SC100
                var expected =
                    "<link target=\"testTarget\" title=\"test alternative\" querystring=\"q%3ds\" linktype=\"internal\" id=\"{0}\" anchor=\"testAnchor\" url=\"/en/sitecore/content/Target\" class=\"testClass\" text=\"Test description\" />"
                    .Formatted(targetId.Guid.ToString("B").ToUpperInvariant());
#else
                var expected =
                    "<link target=\"testTarget\" title=\"test alternative\" querystring=\"q%3ds\" linktype=\"internal\" id=\"{0}\" anchor=\"testAnchor\" url=\"/en/sitecore/content/Target.aspx\" class=\"testClass\" text=\"Test description\" />"
                    .Formatted(targetId.Guid.ToString("B").ToUpperInvariant());
#endif
                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                var value = new Link()
                {
                    Anchor   = "testAnchor",
                    Class    = "testClass",
                    Query    = "q=s",
                    Target   = "testTarget",
                    TargetId = targetId.Guid,
                    Text     = "Test description",
                    Title    = "test alternative",
                    Type     = LinkType.Internal,
                    Url      = ""
                };

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

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

                //Assert
                AssertHtml.AreHtmlElementsEqual(expected, field.Value, "link");
            }
        }
        public void SetField__InternalLinkField_InternalLink_InternalLinkSetOnField()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    new DbField(fieldName)
                    {
                        Type = "internal link"
                    }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper   = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var expected =
                    "/sitecore/content/Target";

                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                var value = new Link()
                {
                    Anchor   = "testAnchor",
                    Class    = "testClass",
                    Query    = "q=s",
                    Target   = "testTarget",
                    TargetId = targetId.Guid,
                    Text     = "Test description",
                    Title    = "test alternative",
                    Type     = LinkType.Internal,
                    Url      = ""
                };

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

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

                //Assert
                Assert.AreEqual(expected, field.Value);
            }
        }
        public void SetField_MedialLinkMissingItem_ThrowsException()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());


                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                var value = new Link()
                {
                    Anchor   = "",
                    Class    = "testClass",
                    Query    = "",
                    Target   = "_blank",
                    TargetId = new Guid("{11111111-CF15-4067-A3F4-85148606F9CD}"),
                    Text     = "Test description",
                    Title    = "test alternative",
                    Type     = LinkType.Media,
                    Url      = ""
                };


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

                //Act
                using (new ItemEditing(item, true))
                {
                    Assert.Throws <MapperException>(() =>
                    {
                        mapper.SetField(field, value, null, null);
                    });
                }

                //Assert
            }
        }
        public void SetField_MailToLink_MailToLinkSetOnField()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper   = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var expected =
                    "<link url=\"mailto:[email protected]\" text=\"Test description\" class=\"testClass\" title=\"test alternative\" linktype=\"mailto\" />";

                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                var value = new Link()
                {
                    Anchor   = "",
                    Class    = "testClass",
                    Query    = "",
                    Target   = "",
                    TargetId = Guid.Empty,
                    Text     = "Test description",
                    Title    = "test alternative",
                    Type     = LinkType.MailTo,
                    Url      = "mailto:[email protected]"
                };


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

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

                //Assert
                AssertHtml.AreHtmlElementsEqual(expected, field.Value, "link");
            }
        }
Example #6
0
        public void SetField_MedialLink_MediaLinkSetOnField()
        {
            //Assign
            var mapper   = new SitecoreFieldLinkMapper();
            var expected =
                "<link target=\"_blank\" title=\"test alternative\" linktype=\"media\" id=\"{8E1C32F3-CF15-4067-A3F4-85148606F9CD}\" url=\"/~/media/8E1C32F3CF154067A3F485148606F9CD.ashx\" class=\"testClass\" text=\"Test description\" />";


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

            var value = new Link()
            {
                Anchor   = "",
                Class    = "testClass",
                Query    = "",
                Target   = "_blank",
                TargetId = new Guid("{8E1C32F3-CF15-4067-A3F4-85148606F9CD}"),
                Text     = "Test description",
                Title    = "test alternative",
                Type     = LinkType.Media,
                Url      = ""
            };


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

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

            //Assert
            Assert.AreEqual(expected, field.Value);
        }
Example #7
0
        public void SetField_InternalLink_InternalLinkSetOnField()
        {
            //Assign
            var mapper   = new SitecoreFieldLinkMapper();
            var expected =
                "<link target=\"testTarget\" title=\"test alternative\" querystring=\"q=s\" linktype=\"internal\" id=\"{1AE37F34-3B6F-4F5F-A5C2-FD2B9D5A47A0}\" anchor=\"testAnchor\" url=\"/en/sitecore/content/Tests/DataMappers/SitecoreFieldLinkMapper/Target.aspx\" class=\"testClass\" text=\"Test description\" />";

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

            var value = new Link()
            {
                Anchor   = "testAnchor",
                Class    = "testClass",
                Query    = "q=s",
                Target   = "testTarget",
                TargetId = new Guid("{1AE37F34-3B6F-4F5F-A5C2-FD2B9D5A47A0}"),
                Text     = "Test description",
                Title    = "test alternative",
                Type     = LinkType.Internal,
                Url      = ""
            };


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

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

            //Assert
            Assert.AreEqual(expected, field.Value);
        }
Example #8
0
        public void SetField_MailToLink_MailToLinkSetOnField()
        {
            //Assign
            var mapper   = new SitecoreFieldLinkMapper();
            var expected =
                "<link url=\"mailto:[email protected]\" text=\"Test description\" class=\"testClass\" title=\"test alternative\" linktype=\"mailto\" />";

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

            var value = new Link()
            {
                Anchor   = "",
                Class    = "testClass",
                Query    = "",
                Target   = "",
                TargetId = Guid.Empty,
                Text     = "Test description",
                Title    = "test alternative",
                Type     = LinkType.MailTo,
                Url      = "mailto:[email protected]"
            };


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

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

            //Assert
            Assert.AreEqual(expected, field.Value);
        }
Example #9
0
        public void SetField_MedialLinkMissingItem_ThrowsException()
        {
            //Assign
            var mapper = new SitecoreFieldLinkMapper();


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

            var value = new Link()
            {
                Anchor   = "",
                Class    = "testClass",
                Query    = "",
                Target   = "_blank",
                TargetId = new Guid("{11111111-CF15-4067-A3F4-85148606F9CD}"),
                Text     = "Test description",
                Title    = "test alternative",
                Type     = LinkType.Media,
                Url      = ""
            };


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

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

            //Assert
        }
        public void SetField_MedialLink_MediaLinkSetOnField()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper   = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var expected =
                    "<link target=\"_blank\" title=\"test alternative\" linktype=\"media\" id=\"{0}\" url=\"Media.Aspx\" class=\"testClass\" text=\"Test description\" />"
                    .Formatted(targetId.Guid.ToString("B").ToUpperInvariant());



                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                var value = new Link()
                {
                    Anchor   = "",
                    Class    = "testClass",
                    Query    = "",
                    Target   = "_blank",
                    TargetId = targetId.Guid,
                    Text     = "Test description",
                    Title    = "test alternative",
                    Type     = LinkType.Media,
                    Url      = ""
                };


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


#if SC90 || SC91
                var mediaUrlProvider = Substitute.For <BaseMediaManager>();

                SitecoreVersionAbstractions.MediaManager = new LazyResetable <BaseMediaManager>(() => mediaUrlProvider);

                mediaUrlProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == targetId))
                .Returns("Media.Aspx");
#else
                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    Substitute.For <Sitecore.Resources.Media.MediaProvider>();
                mediaProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == targetId))
                .Returns("Media.Aspx");

                new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider);
#endif



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

                //Assert
                AssertHtml.AreHtmlElementsEqual(expected, field.Value, "link");
            }
        }