Example #1
0
        public void ShouldReturnCustomTitle()
        {
            //Arrange
            using (var db = new Db {
                new ItemBuilder().AddSubItemWithField("titleField", "titleValue")
                .WithReference("droplink").Build()
            })
            {
                var item      = db.GetItem("/sitecore/content/source");
                var indexable = new SitecoreIndexableItem(item);

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(@"<field><target referenceFieldName=""titleField""/></field>");
                var xmlNode = xmlDoc.FirstChild;

                var sut = new ReferenceField(xmlNode)
                {
                    FieldName = "Reference"
                };

                //Act
                var actual = (IEnumerable <string>)sut.ComputeFieldValue(indexable);

                //Assert
                actual.Should().BeEquivalentTo("titleValue");
            }
        }
Example #2
0
        public void BrokenLinkShouldNotFail()
        {
            //Arrange
            using (var db = new Db {
                new ItemBuilder()
                .WithReference(new List <ID> {
                    ID.NewID
                }).Build()
            })
            {
                var item      = db.GetItem("/sitecore/content/source");
                var indexable = new SitecoreIndexableItem(item);

                var sut = new ReferenceField
                {
                    FieldName = "Reference",
                };

                //Act
                var actual = (IEnumerable <string>)sut.ComputeFieldValue(indexable);

                //Assert
                actual.Should().BeEquivalentTo();
            }
        }
Example #3
0
        public void ShouldReturnName(string fieldType)
        {
            //Arrange
            using (var db = new Db {
                new ItemBuilder().AddSubItem().WithReference(fieldType).Build()
            })
            {
                var item      = db.GetItem("/sitecore/content/source");
                var indexable = new SitecoreIndexableItem(item);

                var sut = new ReferenceField
                {
                    FieldName = "Reference"
                };

                //Act
                var actual = (IEnumerable <string>)sut.ComputeFieldValue(indexable);

                //Assert
                actual.Should().BeEquivalentTo("subitem");
            }
        }
Example #4
0
        public void WrongFieldNameShouldNotfail(string fieldName)
        {
            //Arrange
            using (var db = new Db {
                new ItemBuilder().AddSubItem()
                .WithReference("droplink").Build()
            })
            {
                var item      = db.GetItem("/sitecore/content/source");
                var indexable = new SitecoreIndexableItem(item);

                var sut = new ReferenceField
                {
                    FieldName = fieldName,
                };

                //Act
                var actual = sut.ComputeFieldValue(indexable);

                //Assert
                actual.Should().Be("");
            }
        }