public void Update_ItemPassed_ShouldReplaceLinks([Substitute] LinkDatabase linkDb, Db db) { var datasourceItemId = ID.NewID; db.Add(new DbItem("source") { Children = { new DbItem("_Local") { new DbItem("DatasourceItem") } }, Fields = { "testField" } }); ; db.Add(new DbItem("target") { Children = { new DbItem("_Local") { new DbItem("DatasourceItem") } }, Fields = { "testField" } }); ; var sourceItem = db.GetItem("/sitecore/content/source"); var targetItem = db.GetItem("/sitecore/content/target"); var datasourceItem = db.GetItem("/sitecore/content/source/_Local/DatasourceItem"); var targetDatasourceItem = db.GetItem("/sitecore/content/target/_Local/DatasourceItem"); var itemLinks = new[] { new ItemLink(sourceItem, FieldIDs.LayoutField, datasourceItem, string.Empty) }; linkDb.GetReferences(sourceItem).Returns(itemLinks.ToArray()); using (new LinkDatabaseSwitcher(linkDb)) { using (new EditContext(targetItem)) { targetItem["__Renderings"] = datasourceItem.ID.ToString(); } var referenceReplacer = new UpdateLocalDatasourceReferencesService(sourceItem, targetItem); referenceReplacer.Update(); var expectedValue = targetDatasourceItem.ID.ToString(); targetItem["__Renderings"].Should().Be(expectedValue); } }
public void GetLocalDatasourceDependencies_HasDatasourceFolder_ShouldReturnLinkedItem([Substitute] LinkDatabase linkDb, [Content] Item item, [Content] Item[] refItems, [Content] DbTemplate template) { var itemLinks = refItems.Select(x => new ItemLink(item, FieldIDs.LayoutField, x, string.Empty)).ToList(); var datasourceFolder = item.Add("_Local", new TemplateID(template.ID)); var datasourceItem = datasourceFolder.Add("DatasourceItem", new TemplateID(item.TemplateID)); itemLinks.Add(new ItemLink(item, FieldIDs.LayoutField, datasourceItem, string.Empty)); linkDb.GetReferences(item).Returns(itemLinks.ToArray()); using (new LinkDatabaseSwitcher(linkDb)) { var linkItem = item.GetLocalDatasourceDependencies().Single(); linkItem.ID.Should().Be(datasourceItem.ID); } }