public void RemovesDatasourceRoot()
        {
            var newTemplateId = ID.NewID;
            var componentsFolderTemplateId = ID.Parse("{122AE27A-D84F-4C5E-8367-0F42C764976E}");
            var dsFolderId = ID.NewID;

            using (var db = new Db()
            {
                new DbTemplate("ComponentsFolder", componentsFolderTemplateId),
                new DbTemplate("PageTemplate", newTemplateId),
                new DbTemplate("WebsiteFolder", TemplateIDs.WebsiteFolder),
                new DbItem("Website", ID.NewID, TemplateIDs.WebsiteFolder)
                {
                    new DbItem("home"),
                    new DbItem("_components", ID.NewID, componentsFolderTemplateId)
                    {
                        new DbItem("PageTemplate", dsFolderId, componentsFolderTemplateId)
                    }
                },
                new DbItem("rendering")
                {
                    new DbField("Datasource template")
                    {
                        Value = newTemplateId.ToString()
                    }
                }
            })
            {
                var home      = db.GetItem("/sitecore/content/Website/home");
                var rendering = db.GetItem("/sitecore/content/rendering");
                var args      = new GetRenderingDatasourceArgs(rendering)
                {
                    ContextItemPath = home.Paths.FullPath
                };
                args.DatasourceRoots.Add(db.GetItem(dsFolderId));

                var ctx    = new GetRenderingDatasourceRuleContext(args);
                var action = new RemoveWebsiteDatasourceRootAction <GetRenderingDatasourceRuleContext>();

                ctx.Args.DatasourceRoots.Should().HaveCount(1);

                action.Apply(ctx);

                ctx.Args.DatasourceRoots.Should().HaveCount(0);
            }
        }
        public void AddsDatasourceRoot()
        {
            using (var db = GetFakeDb())
            {
                var home      = db.GetItem("/sitecore/content/home");
                var rendering = db.GetItem("/sitecore/content/rendering");
                var ctx       = new GetRenderingDatasourceRuleContext(new GetRenderingDatasourceArgs(rendering)
                {
                    ContextItemPath = home.Paths.FullPath
                });
                var action = new AddLocalDatasourceRootAction <GetRenderingDatasourceRuleContext>();

                action.Apply(ctx);

                ctx.Args.DatasourceRoots.Should().HaveCount(1).And.ContainSingle(x => x.Name == "ContentBlock");
            }
        }
        public void IgnoresAddingMissingItem()
        {
            using (var db = new Db()
            {
                new DbItem("home"), new DbItem("components")
            })
            {
                var home   = db.GetItem("/sitecore/content/home");
                var ctx    = new GetRenderingDatasourceRuleContext(new GetRenderingDatasourceArgs(home));
                var action = new AddDatasourceRootAction <GetRenderingDatasourceRuleContext>()
                {
                    NewDatasourceRoot = null
                };

                action.Apply(ctx);

                ctx.Args.DatasourceRoots.Should().BeEmpty();
            }
        }
        public void AddsDatasourceRoot()
        {
            using (var db = new Db()
            {
                new DbItem("home"), new DbItem("components")
            })
            {
                var home   = db.GetItem("/sitecore/content/home");
                var ctx    = new GetRenderingDatasourceRuleContext(new GetRenderingDatasourceArgs(home));
                var action = new AddDatasourceRootAction <GetRenderingDatasourceRuleContext>()
                {
                    NewDatasourceRoot = home
                };

                action.Apply(ctx);

                ctx.Args.DatasourceRoots.Should().HaveCount(1).And.ContainSingle(x => x.ID == home.ID);
            }
        }
Exemple #5
0
        public void AddsWebsiteDatasourceRoot()
        {
            var newTemplateId = ID.NewID;

            using (var db = new Db()
            {
                new DbTemplate("ComponentsFolder", ID.Parse("{122AE27A-D84F-4C5E-8367-0F42C764976E}")),
                new DbTemplate("PageTemplate", newTemplateId),
                new DbTemplate("WebsiteFolder", TemplateIDs.WebsiteFolder),
                new DbItem("Website", ID.NewID, TemplateIDs.WebsiteFolder)
                {
                    new DbItem("home"),
                    new DbItem("components")
                },
                new DbItem("rendering")
                {
                    new DbField("Datasource template")
                    {
                        Value = newTemplateId.ToString()
                    }
                }
            })
            {
                var home      = db.GetItem("/sitecore/content/Website/home");
                var rendering = db.GetItem("/sitecore/content/rendering");
                var ctx       = new GetRenderingDatasourceRuleContext(new GetRenderingDatasourceArgs(rendering)
                {
                    ContextItemPath = home.Paths.FullPath
                });
                var action = new AddWebsiteDatasourceRootAction <GetRenderingDatasourceRuleContext>();

                action.Apply(ctx);

                ctx.Args.DatasourceRoots.Should().HaveCount(1).And.ContainSingle(x => x.Name == "PageTemplate");
                db.GetItem("/sitecore/content/Website/_components").Should().NotBeNull();
            }
        }