Ejemplo n.º 1
0
        public void MW_Should_Add_Post()
        {
            var mw = GetMeta();
            Assert.Equal(0,Hana.Model.Post.All().Count());

            var p = new Post();
            p.title = "Title";
            p.description = "Lorem Ipsum Lorem Ipsum <!--more--> Beep Beep";
            p.mt_keywords = "tag1, tag2";
            p.wp_slug = "sluggy-slug";

            mw.AddPost("0", "", "", p, true);
            Assert.Equal(1,Hana.Model.Post.All().Count());

            var p2 = Hana.Model.Post.All().First();
            Assert.Equal("Title", p2.Title);
            Assert.Equal("Lorem Ipsum Lorem Ipsum <!--more--> Beep Beep", p2.Body);
            Assert.Equal("Lorem Ipsum Lorem Ipsum", p2.Excerpt.Trim());
            Assert.Equal("sluggy-slug", p2.Slug);
            Assert.Equal("tag1, tag2", p2.Tags);
        }
Ejemplo n.º 2
0
        public void MW_Should_Add_Post_With_Generated_Slug_When_No_Slug_Passed()
        {
            var mw = GetMeta();
            Assert.Equal(0, Hana.Model.Post.All().Count());

            var p = new Post();
            p.title = "A long title";
            p.description = "Lorem Ipsum Lorem Ipsum <!--more--> Beep Beep";
            p.mt_keywords = "tag1, tag2";

            mw.AddPost("0", "", "", p, true);
            Assert.Equal(1, Hana.Model.Post.All().Count());

            var p2 = Hana.Model.Post.All().First();
            Assert.Equal("A long title", p2.Title);
            Assert.Equal("Lorem Ipsum Lorem Ipsum <!--more--> Beep Beep", p2.Body);
            Assert.Equal("Lorem Ipsum Lorem Ipsum", p2.Excerpt.Trim());
            Assert.Equal("a-long-title", p2.Slug);
        }
Ejemplo n.º 3
0
        public void MW_Should_Save_Tags_When_Adding_Post()
        {
            var mw = GetMeta();
            Assert.Equal(0, Hana.Model.Post.All().Count());

            var p = new Post();
            p.title = "Title";
            p.description = "Lorem Ipsum Lorem Ipsum <!--more--> Beep Beep";
            p.mt_keywords = "tag1, tag2";
            p.wp_slug = "sluggy-slug";

            mw.AddPost("0", "", "", p, true);
            Assert.Equal(2, Hana.Model.Tag.All().Count());
        }
Ejemplo n.º 4
0
        public void MW_Should_Update_Post()
        {
            var mw = GetMeta();

            var post = new Hana.Model.Post();
            post.Body = "La La La";
            post.PostID = 1;
            Hana.Model.Post.Setup(post);

            Post p=new Post();
            p.description = "Jeepers Creepers";

            mw.UpdatePost("1", "", "", p, true);

            post = Hana.Model.Post.SingleOrDefault(x => x.PostID == 1);
            Assert.Equal("Jeepers Creepers",post.Body);
        }
Ejemplo n.º 5
0
        public void MW_Should_Save_Categories_When_Adding_Post()
        {
            var mw = GetMeta();
            Assert.Equal(0, Hana.Model.Post.All().Count());

            var p = new Post();
            p.title = "Title";
            p.description = "Lorem Ipsum Lorem Ipsum <!--more--> Beep Beep";
            p.categories = new string[]{"cat1","cat2"};
            p.wp_slug = "sluggy-slug";

            mw.AddPost("0", "", "", p, true);
            Assert.Equal(2, Hana.Model.Category.All().Count());
        }
Ejemplo n.º 6
0
        public bool UpdatePost(string postid, string username, string password, Post post, bool publish)
        {
            bool result = false;
            if (ValidateUser(username, password)) {

                var updatePost = Hana.Model.Post.SingleOrDefault(x => x.PostID == int.Parse(postid));

                updatePost.Body = post.description;
                updatePost.ModifiedOn = DateTime.Now;

                updatePost.Title = post.title;
                if (!string.IsNullOrEmpty(post.wp_slug)) {
                    updatePost.Slug = post.wp_slug;
                } else {
                    updatePost.Slug = updatePost.Title.CreateSlug();
                }

                updatePost.Update();

                //set categories and tags

                if (post.categories != null) {
                    Hana.Model.Categories_Post.Delete(x => x.PostID == updatePost.PostID);

                    updatePost.CategorySlug = post.categories[0].CreateSlug();
                    foreach (var c in post.categories) {
                        AssignCategory(updatePost.PostID, c);
                    }
                }

                var tags = new string[0];
                if (!String.IsNullOrEmpty(post.mt_keywords)) {
                    tags = post.mt_keywords.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    updatePost.Tags = string.Join(",", tags);
                }
                if (!String.IsNullOrEmpty(post.mt_keywords)) {

                    foreach (var t in tags) {
                        AssignTag(updatePost.PostID, t);
                    }
                }

                return result;
            }
            throw new XmlRpcFaultException(0, "User is not valid!");
        }
Ejemplo n.º 7
0
        public Post[] GetRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            if (ValidateUser(username, password))
            {
                List<Post> posts = new List<Post>();

                var qry = Hana.Model.Post.Recent(numberOfPosts);

                foreach (var p in qry)
                {
                    Post post = new Post();
                    post.title = p.Title;
                    post.postid = p.PostID.ToString();
                    post.dateCreated = p.CreatedOn;
                    post.description = p.Body;
                    posts.Add(post);
                }

                return posts.ToArray();
            }
            throw new XmlRpcFaultException(0, "User is not valid!");
        }
Ejemplo n.º 8
0
        public Post GetPost(string postid, string username, string password)
        {
            if (ValidateUser(username, password))
            {
                Post post = new Post();

                var title = Hana.Model.Post.SingleOrDefault(x => x.PostID == int.Parse(postid));
                post.title =title.Title;
                post.postid = postid;
                post.description = title.Body;
                post.wp_slug = title.Slug;

                var results=new List<string>();
                var cats = Hana.Model.Post.Categories(title.PostID);
                foreach (var cat in cats)
                {
                    results.Add(cat.Description);
                }

                post.categories = results.ToArray();

                //tags
                post.mt_keywords = title.Tags;

                return post;
            }
            throw new XmlRpcFaultException(0, "User is not valid!");
        }
Ejemplo n.º 9
0
        public string AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            if (ValidateUser(username, password))
            {

                var newPost = new Hana.Model.Post();
                newPost.Author = Hana.Model.Blog.Owner;
                newPost.CreatedOn = DateTime.Now;
                newPost.ModifiedOn = DateTime.Now;
                newPost.Title = post.title;
                newPost.Body = post.description;
                if (!string.IsNullOrEmpty(post.mt_text_more))
                    newPost.Body += post.mt_text_more;

                newPost.Slug = newPost.Title.CreateSlug();
                if (!string.IsNullOrEmpty(post.wp_slug))
                    newPost.Slug = post.wp_slug;

                var tags = new string[0];
                if (!String.IsNullOrEmpty(post.mt_keywords)){
                    tags = post.mt_keywords.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
                    newPost.Tags = string.Join(",", tags);
                }

                if (publish && post.dateCreated > DateTime.MinValue) {
                    newPost.PublishedOn = post.dateCreated;
                } else if (publish) {
                    newPost.PublishedOn = DateTime.Now;
                } else {
                    newPost.PublishedOn = DateTime.Now.AddDays(365);
                }

                newPost.Excerpt = Hana.Model.Post.CreateSummary(newPost);

                newPost.Add();
                //save the cats

                if (post.categories.Length>0)
                {
                    newPost.CategorySlug = post.categories[0].CreateSlug();
                    foreach (var c in post.categories)
                    {
                        AssignCategory(newPost.PostID, c);
                    }
                }

                if(!String.IsNullOrEmpty(post.mt_keywords)){

                    foreach (var t in tags) {
                      AssignTag(newPost.PostID,t);
                    }
                }

                return Hana.Model.Blog.BlogURL+newPost.Slug;
            }
            throw new XmlRpcFaultException(0, "User is not valid!");
        }