Esempio n. 1
0
        public static async Task <SiteTree> CreateSite(I_Content_Service cs, I_Puck_Repository repo, string rootName, List <string> variants, List <bool> variantIsPublished, int levels, int branches, string username)
        {
            var tree = new SiteTree();

            tree.Level  = 1;
            tree.Branch = 1;
            for (var i = 0; i < variants.Count; i++)
            {
                var published = variantIsPublished[i];
                var root      = await cs.Create <Folder>(Guid.Empty, variants[i], rootName, template : "template.cshtml", published : published, userName : username);

                await cs.SaveContent(root, triggerEvents : false, userName : username);

                var revision = repo.CurrentRevision(root.Id, root.Variant);
                tree.Variants.Add(revision);
            }

            async Task CreateLevel(int level, SiteTree ctree)
            {
                if (level > levels)
                {
                    return;
                }
                for (var j = 0; j < branches; j++)
                {
                    var btree = new SiteTree();
                    btree.Level  = level;
                    btree.Branch = j + 1;
                    for (var k = 0; k < variants.Count; k++)
                    {
                        var published = variantIsPublished[k];
                        var model     = await cs.Create <Folder>(ctree.Variants.First().Id, variants[k], (j + 1).ToString(), template : "template.cshtml", published : published, userName : username);

                        await cs.SaveContent(model, triggerEvents : false, userName : username);

                        var revision = repo.CurrentRevision(model.Id, model.Variant);
                        btree.Variants.Add(revision);
                    }
                    ctree.Children.Add(btree);
                    await CreateLevel(level + 1, btree);
                }
            }

            await CreateLevel(2, tree);

            return(tree);
        }
Esempio n. 2
0
        public async Task IdPath()
        {
            var level1 = await contentService.Create <Folder>(Guid.Empty, "en-gb", "idPathRoot", template : "~/views/home/homepage.cshtml", published : true, userName : "******");

            await contentService.SaveContent(level1, triggerEvents : false, userName : uname);

            var level2_1 = await contentService.Create <Folder>(level1.Id, "en-gb", "level2_1", template : "~/views/home/homepage.cshtml", published : true, userName : uname);

            await contentService.SaveContent(level2_1, triggerEvents : false, userName : uname);

            var level3_1 = await contentService.Create <Folder>(level2_1.Id, "en-gb", "level3_1", template : "~/views/home/homepage.cshtml", published : true, userName : uname);

            await contentService.SaveContent(level3_1, triggerEvents : false, userName : uname);

            var level3_1_idPath = contentService.GetIdPath(level3_1);
            var idPath          = $"{level1.Id},{level2_1.Id},{level3_1.Id}";

            Assert.That(level3_1_idPath == idPath);
        }