コード例 #1
0
ファイル: Taxonomies.cs プロジェクト: mute503/piranha-sandbox
        public void NullTagToTaxonomy()
        {
            Data.Tag        tag = null;
            Models.Taxonomy t   = tag;

            Assert.Null(t);
        }
コード例 #2
0
ファイル: Taxonomies.cs プロジェクト: mute503/piranha-sandbox
        public void NullCategoryToTaxonomy()
        {
            Data.Category   category = null;
            Models.Taxonomy t        = category;

            Assert.Null(t);
        }
コード例 #3
0
        public void StringToTaxonomy()
        {
            Models.Taxonomy t = "Test";

            Assert.NotNull(t);
            Assert.Equal(Guid.Empty, t.Id);
            Assert.Equal("Test", t.Title);
            Assert.Null(t.Slug);
        }
コード例 #4
0
        public override async Task InitializeAsync()
        {
            using (var api = CreateApi())
            {
                Piranha.App.Init(api);

                var pageBuilder = new PageTypeBuilder(api)
                                  .AddType(typeof(MyPage));
                pageBuilder.Build();

                var postBuilder = new PostTypeBuilder(api)
                                  .AddType(typeof(MyPost));
                postBuilder.Build();

                // Add site
                var site1 = new Site
                {
                    Id         = SITE1_ID,
                    Title      = "Page Site",
                    InternalId = "PostSite",
                    IsDefault  = true
                };
                await api.Sites.SaveAsync(site1);

                var site2 = new Site
                {
                    Id         = SITE2_ID,
                    Title      = "Page Site 2",
                    InternalId = "PostSite2",
                    Hostnames  = "www.myothersite.com",
                    IsDefault  = false
                };
                await api.Sites.SaveAsync(site2);

                // Add pages
                var page1 = await MyPage.CreateAsync(api);

                page1.Id        = PAGE1_ID;
                page1.SiteId    = SITE1_ID;
                page1.Title     = "Blog";
                page1.Published = DateTime.Now;
                await api.Pages.SaveAsync(page1);

                var page2 = await MyPage.CreateAsync(api);

                page2.Id        = PAGE2_ID;
                page2.SiteId    = SITE2_ID;
                page2.Title     = "News";
                page2.Published = DateTime.Now;
                await api.Pages.SaveAsync(page2);

                // Add categories
                var category1 = new Models.Taxonomy
                {
                    Id    = CATEGORY1_ID,
                    Title = "Default category"
                };

                var category2 = new Models.Taxonomy
                {
                    Id    = CATEGORY2_ID,
                    Title = "Default category"
                };

                // Add posts
                var post1 = await MyPost.CreateAsync(api);

                post1.Id       = POST1_ID;
                post1.BlogId   = page1.Id;
                post1.Category = category1;
                post1.Title    = "My first post";
                post1.Body     = "My first body";
                post1.Tags.Add(new Models.Taxonomy
                {
                    Id    = TAG1_ID,
                    Title = "My tag"
                });
                post1.Published = DateTime.Now;
                await api.Posts.SaveAsync(post1);

                var post2 = await MyPost.CreateAsync(api);

                post2.Id       = POST2_ID;
                post2.BlogId   = page2.Id;
                post2.Category = category2;
                post2.Title    = "My second post";
                post2.Body     = "My second body";
                post2.Tags.Add(new Models.Taxonomy
                {
                    Id    = TAG2_ID,
                    Title = "My other tag"
                });
                post2.Published = DateTime.Now;
                await api.Posts.SaveAsync(post2);
            }
        }
コード例 #5
0
        protected override void Init()
        {
            services = new ServiceCollection()
                       .AddSingleton <IMyService, MyService>()
                       .BuildServiceProvider();

            using (var api = CreateApi()) {
                Piranha.App.Init(api);

                Piranha.App.Fields.Register <MyFourthField>();

                var pageTypeBuilder = new PageTypeBuilder(api)
                                      .AddType(typeof(BlogPage));
                pageTypeBuilder.Build();
                var postTypeBuilder = new PostTypeBuilder(api)
                                      .AddType(typeof(MissingPost))
                                      .AddType(typeof(MyPost))
                                      .AddType(typeof(MyCollectionPost))
                                      .AddType(typeof(MyDIPost));
                postTypeBuilder.Build();

                // Add site
                var site = new Site()
                {
                    Id         = SITE_ID,
                    Title      = "Post Site",
                    InternalId = "PostSite",
                    IsDefault  = true
                };
                api.Sites.Save(site);

                // Add blog page
                var page = BlogPage.Create(api);
                page.Id     = BLOG_ID;
                page.SiteId = SITE_ID;
                page.Title  = "Blog";
                api.Pages.Save(page);

                var category = new Models.Taxonomy()
                {
                    Id    = CAT_1_ID,
                    Title = "My category"
                };

                var post1 = MyPost.Create(api);
                post1.Id       = POST_1_ID;
                post1.BlogId   = BLOG_ID;
                post1.Category = category;
                post1.Title    = "My first post";
                post1.Ingress  = "My first ingress";
                post1.Body     = "My first body";
                post1.Blocks.Add(new Extend.Blocks.TextBlock {
                    Body = "Sollicitudin Aenean"
                });
                post1.Blocks.Add(new Extend.Blocks.TextBlock {
                    Body = "Ipsum Elit"
                });
                api.Posts.Save(post1);

                var post2 = MyPost.Create(api);
                post2.Id       = POST_2_ID;
                post2.BlogId   = BLOG_ID;
                post2.Category = category;
                post2.Title    = "My second post";
                post2.Ingress  = "My second ingress";
                post2.Body     = "My second body";
                api.Posts.Save(post2);

                var post3 = MyPost.Create(api);
                post3.Id       = POST_3_ID;
                post3.BlogId   = BLOG_ID;
                post3.Category = category;
                post3.Title    = "My third post";
                post3.Ingress  = "My third ingress";
                post3.Body     = "My third body";
                api.Posts.Save(post3);

                var post4 = MyCollectionPost.Create(api);
                post4.BlogId   = BLOG_ID;
                post4.Category = category;
                post4.Title    = "My collection post";
                post4.Texts.Add(new TextField()
                {
                    Value = "First text"
                });
                post4.Texts.Add(new TextField()
                {
                    Value = "Second text"
                });
                post4.Texts.Add(new TextField()
                {
                    Value = "Third text"
                });
                api.Posts.Save(post4);

                var post6 = MyDIPost.Create(api);
                post6.Id       = POST_DI_ID;
                post6.BlogId   = BLOG_ID;
                post6.Category = category;
                post6.Title    = "My Injection Post";
                api.Posts.Save(post6);
            }
        }
コード例 #6
0
        public Models.Taxonomy GetTaxonomy(RenderingContext renderingContext)
        {
            var model = new Models.Taxonomy(GetDatasource(renderingContext, Taxonomy_Constants.TemplateId));

            return(model);
        }