public void EditPostDoesntTouchAlreadyPublishedEntrysPublishDate()
        {
            FakePostService postService = new FakePostService();
            FakeUserService userService = new FakeUserService();

            Guid     postID        = Guid.NewGuid();
            DateTime publishedDate = DateTime.Now.AddDays(-1);

            postService.AddedPosts.Add(new Oxite.Models.Post()
            {
                ID        = postID,
                Published = publishedDate
            });

            Post newPost = new Post()
            {
                title       = "PostTitle",
                description = "PostDescription",
                mt_excerpt  = "PostBodyShort",
                mt_basename = "PostSlug"
            };

            MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null);

            service.EditPost(postID.ToString(), "test", "test", newPost, true);

            Assert.Equal(publishedDate, postService.AddedPosts[0].Published);
        }
        public void EditPostPublishesIfPublishIsTrue()
        {
            FakePostService postService = new FakePostService();
            FakeUserService userService = new FakeUserService();

            Guid postID = Guid.NewGuid();

            postService.AddedPosts.Add(new Oxite.Models.Post()
            {
                ID = postID,
            });

            Post newPost = new Post()
            {
                title       = "PostTitle",
                description = "PostDescription",
                mt_excerpt  = "PostBodyShort",
                mt_basename = "PostSlug"
            };

            MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null);

            service.EditPost(postID.ToString(), "test", "test", newPost, true);

            Assert.True(DateTime.Today < postService.AddedPosts[0].Published);
        }
        public void EditPostSavesChangesToTextFields()
        {
            FakePostService postService = new FakePostService();
            FakeUserService userService = new FakeUserService();

            Guid postID = Guid.NewGuid();

            postService.AddedPosts.Add(new Oxite.Models.Post()
            {
                ID = postID,
            });

            Post newPost = new Post()
            {
                title       = "PostTitle",
                description = "PostDescription",
                mt_excerpt  = "PostBodyShort",
                mt_basename = "PostSlug"
            };

            MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null);

            bool success = service.EditPost(postID.ToString(), "test", "test", newPost, false);

            Assert.True(success);
            Oxite.Models.Post edited = postService.AddedPosts[0];
            Assert.Equal(newPost.title, edited.Title);
            Assert.Equal(newPost.description, edited.Body);
            Assert.Equal(newPost.mt_excerpt, edited.BodyShort);
            Assert.Equal(newPost.mt_basename, edited.Slug);
        }
        public void EditPostEditsTagList()
        {
            FakePostService postService = new FakePostService();
            FakeUserService userService = new FakeUserService();
            Guid            postID      = Guid.NewGuid();

            postService.AddedPosts.Add(new Oxite.Models.Post()
            {
                ID        = postID,
                Title     = "PreTitle",
                Body      = "PreBody",
                BodyShort = "PreBodyShort",
                Tags      =
                    new List <Oxite.Models.Tag>(new Oxite.Models.Tag[]
                {
                    new Oxite.Models.Tag()
                    {
                        Name = "Old1"
                    },
                    new Oxite.Models.Tag()
                    {
                        Name = "Both1"
                    }
                })
            });

            Post newPost = new Post()
            {
                categories  = new[] { "New1", "Both1" },
                title       = "PostTitle",
                description = "PostDescription",
                mt_excerpt  = "PostBodyShort"
            };

            MetaWeblogAPI service = new MetaWeblogAPI(postService, null, userService, null, null);

            service.EditPost(postID.ToString(), "test", "test", newPost, false);

            Oxite.Models.Post edited = postService.AddedPosts[0];
            Assert.Equal(2, edited.Tags.Count());
            Assert.Contains("New1", edited.Tags.Select(t => t.Name));
            Assert.Contains("Both1", edited.Tags.Select(t => t.Name));
        }
        public void EditPostFaultsOnNullUser()
        {
            MetaWeblogAPI service = new MetaWeblogAPI(null, null, null, null, null);

            Assert.Throws <ArgumentException>(() => service.EditPost(Guid.NewGuid().ToString(), null, null, null, false));
        }
        public void EditPostFaultsOnInvalidEntryID()
        {
            MetaWeblogAPI service = new MetaWeblogAPI(null, null, null, null, null);

            Assert.Throws <ArgumentException>(() => service.EditPost(null, null, null, null, false));
        }