sshushliapin/Sitecore.FakeDb

Item.Links.GetValidLinks only returns the item template.

Opened this issue · 1 comments

In the code below, only the template of the item is returned when calling articles.Links.GetValidLinks() or source.Links.GetValidLinks(). I've tried creating a hierarchy and using the LinkDatabaseSwitcher.

public void TestHierarchy()
{
using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
{
new Sitecore.FakeDb.DbItem("Articles")
{
new Sitecore.FakeDb.DbItem("Getting Started"),
new Sitecore.FakeDb.DbItem("Troubleshooting")
}
})
{
Sitecore.Data.Items.Item articles =
db.GetItem("/sitecore/content/Articles");

	**var links = articles.Links.GetValidLinks();**
	Assert.IsTrue(links.Any());
}

}

public void HowToWorkWithLinkDatabase()
{
// arrange your database and items
Sitecore.Data.ID sourceId = Sitecore.Data.ID.NewID;
Sitecore.Data.ID aliasId = Sitecore.Data.ID.NewID;
Sitecore.Data.ID linkedItemId = Sitecore.Data.ID.NewID;

using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
{
	new Sitecore.FakeDb.DbItem("source", sourceId),
	new Sitecore.FakeDb.DbItem("clone"),
	new Sitecore.FakeDb.DbItem("alias", aliasId, Sitecore.TemplateIDs.Alias)
	{
		new Sitecore.FakeDb.DbField("Linked item", linkedItemId)
	}
})
{
	// arrange desired LinkDatabase behavior
	var behavior = Substitute.For<Sitecore.Links.LinkDatabase>();

	Sitecore.Data.Items.Item source = db.GetItem("/sitecore/content/source");
	Sitecore.Data.Items.Item alias = db.GetItem("/sitecore/content/alias");
	Sitecore.Data.Items.Item clone = db.GetItem("/sitecore/content/clone");

	string sourcePath = source.Paths.FullPath;
	behavior.GetReferrers(source).Returns(new[]
	{
		new Sitecore.Links.ItemLink(alias, linkedItemId, source, sourcePath),
		new Sitecore.Links.ItemLink(clone, Sitecore.FieldIDs.Source, source, sourcePath)
	});
	

	using (new Sitecore.FakeDb.Links.LinkDatabaseSwitcher(behavior))
	{
		**var sourceLinks = source.Links.GetValidLinks();**
	}
}

}

What would you expect to be returned? Please provide a Minimal, Complete, and Verifiable example describing your use case.