Example #1
0
        public void Add()
        {
            using (var api = new Api(GetDb(), storage, cache)) {
                var count = api.Posts.GetAll(BLOG_ID).Count();
                var post  = MyPost.Create(api, "MyPost");
                post.BlogId     = BLOG_ID;
                post.CategoryId = CAT_1_ID;
                post.Title      = "My fourth post";
                post.Ingress    = "My fourth ingress";
                post.Body       = "My fourth body";

                api.Posts.Save(post);

                Assert.Equal(count + 1, api.Posts.GetAll(BLOG_ID).Count());
            }
        }
Example #2
0
        public void Add()
        {
            using (var api = CreateApi()) {
                var count    = api.Posts.GetAll(BLOG_ID).Count();
                var catCount = api.Posts.GetAllCategories(BLOG_ID).Count();
                var post     = MyPost.Create(api, "MyPost");
                post.BlogId   = BLOG_ID;
                post.Category = "My category";
                post.Title    = "My fourth post";
                post.Ingress  = "My fourth ingress";
                post.Body     = "My fourth body";

                api.Posts.Save(post);

                Assert.Equal(count + 1, api.Posts.GetAll(BLOG_ID).Count());
                Assert.Equal(catCount, api.Posts.GetAllCategories(BLOG_ID).Count());
            }
        }
Example #3
0
        public void AddWithTags()
        {
            using (var api = new Api(GetDb(), storage, cache)) {
                var count    = api.Posts.GetAll(BLOG_ID).Count();
                var catCount = api.Categories.GetAll(BLOG_ID).Count();
                var tagCount = api.Tags.GetAll(BLOG_ID).Count();

                var post = MyPost.Create(api, "MyPost");
                post.BlogId   = BLOG_ID;
                post.Category = "My category";
                post.Tags.Add("Testing", "Trying", "Adding");
                post.Title   = "My fifth post";
                post.Ingress = "My fifth ingress";
                post.Body    = "My fifth body";

                api.Posts.Save(post);

                Assert.Equal(count + 1, api.Posts.GetAll(BLOG_ID).Count());
                Assert.Equal(catCount, api.Categories.GetAll(BLOG_ID).Count());
                Assert.Equal(tagCount + 3, api.Tags.GetAll(BLOG_ID).Count());

                post = api.Posts.GetBySlug <MyPost>(BLOG_ID, Piranha.Utils.GenerateSlug("My fifth post"));

                Assert.NotNull(post);
                Assert.Equal(3, post.Tags.Count);
                post.Tags.Add("Another tag");

                api.Posts.Save(post);

                Assert.Equal(tagCount + 4, api.Tags.GetAll(BLOG_ID).Count());

                post = api.Posts.GetBySlug <MyPost>(BLOG_ID, Piranha.Utils.GenerateSlug("My fifth post"));

                Assert.NotNull(post);
                Assert.Equal(4, post.Tags.Count);
            }
        }
Example #4
0
        protected override void Init()
        {
            using (var api = new Api(GetDb(), storage, cache)) {
                Piranha.App.Init(api);

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

                // Add site
                var site = new Data.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 Data.Category()
                {
                    Id     = CAT_1_ID,
                    BlogId = BLOG_ID,
                    Title  = "My category"
                };
                api.Categories.Save(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";
                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);
            }
        }
Example #5
0
        protected override void Init()
        {
            using (var api = new Api(GetDb(), new ContentServiceFactory(services), storage)) {
                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 Data.Site()
                {
                    Id         = SITE1_ID,
                    Title      = "Page Site",
                    InternalId = "PostSite",
                    IsDefault  = true
                };
                api.Sites.Save(site1);

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

                // Add pages
                var page1 = MyPage.Create(api);
                page1.Id        = PAGE1_ID;
                page1.SiteId    = SITE1_ID;
                page1.Title     = "Blog";
                page1.Published = DateTime.Now;
                api.Pages.Save(page1);

                var page2 = MyPage.Create(api);
                page2.Id        = PAGE2_ID;
                page2.SiteId    = SITE2_ID;
                page2.Title     = "News";
                page2.Published = DateTime.Now;
                api.Pages.Save(page2);

                // Add categories
                var category1 = new Data.Category()
                {
                    Id     = CATEGORY1_ID,
                    BlogId = PAGE1_ID,
                    Title  = "Default category"
                };
                api.Categories.Save(category1);

                var category2 = new Data.Category()
                {
                    Id     = CATEGORY2_ID,
                    BlogId = PAGE2_ID,
                    Title  = "Default category"
                };
                api.Categories.Save(category2);

                // Add tags
                var tag = new Data.Tag()
                {
                    Id     = TAG1_ID,
                    BlogId = PAGE1_ID,
                    Title  = "My tag"
                };
                api.Tags.Save(tag);

                tag = new Data.Tag()
                {
                    Id     = TAG2_ID,
                    BlogId = PAGE2_ID,
                    Title  = "My other tag"
                };
                api.Tags.Save(tag);

                // Add posts
                var post1 = MyPost.Create(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("My tag");
                post1.Published = DateTime.Now;
                api.Posts.Save(post1);

                var post2 = MyPost.Create(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("My other tag");
                post2.Published = DateTime.Now;
                api.Posts.Save(post2);
            }
        }
Example #6
0
        protected override void Init()
        {
            services = new ServiceCollection()
                       .AddSingleton <IMyService, MyService>()
                       .BuildServiceProvider();

            using (var api = new Api(GetDb(), new ContentServiceFactory(services), storage, cache)) {
                Piranha.App.Init();

                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 Data.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 Data.Category()
                {
                    Id     = CAT_1_ID,
                    BlogId = BLOG_ID,
                    Title  = "My category"
                };
                api.Categories.Save(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);
            }
        }