private void ResolveDatasourceTemplate(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var datasourceLocation = args.RenderingItem[Templates.RenderingOptions.Fields.DatasourceLocation]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocation); if (string.IsNullOrEmpty(name)) { return; } args.Prototype = _provider.GetDatasourceTemplate(contextItem, name); }
public void Process_DatasourceProviderIsNotNull_SourcesAndTemplateAreSet(IDatasourceProvider sourceProvider, [Substitute]DatasourceProviderFactory factory, DbItem renderingItem, Db db, string settingName, Item[] sources, Item sourceTemplate) { var processor = new GetDatasourceLocationAndTemplateFromSite(factory); sourceProvider.GetDatasources(Arg.Any<string>(), Arg.Any<Item>()).Returns(sources); sourceProvider.GetDatasourceTemplate(Arg.Any<string>(), Arg.Any<Item>()).Returns(sourceTemplate); factory.GetProvider(Arg.Any<Database>()).Returns(sourceProvider); var setting = settingName.Replace("-", string.Empty); renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{setting}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Should().Contain(sources); args.Prototype.Should().Be(sourceTemplate); }
public void Process_DatasourceProviderIsNotNull_SourcesAndTemplateAreSet(IDatasourceProvider sourceProvider, [Substitute] DatasourceProviderFactory factory, DbItem renderingItem, Db db, string settingName, Item[] sources, Item sourceTemplate) { var processor = new GetDatasourceLocationAndTemplateFromSite(factory); sourceProvider.GetDatasources(Arg.Any <string>(), Arg.Any <Item>()).Returns(sources); sourceProvider.GetDatasourceTemplate(Arg.Any <string>(), Arg.Any <Item>()).Returns(sourceTemplate); factory.GetProvider(Arg.Any <Database>()).Returns(sourceProvider); var setting = settingName.Replace("-", string.Empty); renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{setting}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Should().Contain(sources); args.Prototype.Should().Be(sourceTemplate); }