public void NewPostCreatesSlugForEntry()
        {
            FakePostService        postService        = new FakePostService();
            FakeAreaService        areaService        = new FakeAreaService();
            FakeTagService         tagService         = new FakeTagService();
            FakeUserService        userService        = new FakeUserService();
            FakeRegularExpressions regularExpressions = new FakeRegularExpressions();
            Guid areaID = Guid.NewGuid();

            areaService.StoredAreas.Add("test", new Oxite.Models.Area()
            {
                ID = areaID
            });

            Post newPost = new Post()
            {
                title = "This is a test", description = "A Test", dateCreated = DateTime.Now, mt_basename = ""
            };

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

            service.NewPost(areaID.ToString(), "test", "test", newPost, false);

            Oxite.Models.Post savedPost = postService.AddedPosts[0];
            Assert.Equal("This-is-a-test", savedPost.Slug);
        }
        public void NewPostAddsToService()
        {
            FakePostService postService = new FakePostService();
            FakeAreaService areaService = new FakeAreaService();
            FakeTagService  tagService  = new FakeTagService();
            FakeUserService userService = new FakeUserService();
            Guid            areaID      = Guid.NewGuid();

            areaService.StoredAreas.Add("test", new Oxite.Models.Area()
            {
                ID = areaID
            });

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

            Post newPost = new Post()
            {
                title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test"
            };
            string postIDString = service.NewPost(areaID.ToString(), "test", "test", newPost, false);

            Assert.NotNull(postIDString);
            Assert.Equal(1, postService.AddedPosts.Count);
            Assert.Equal(postService.AddedPosts[0].ID.ToString(), postIDString);
            Assert.Equal("Test", postService.AddedPosts[0].Title);
            Assert.Equal("A Test", postService.AddedPosts[0].Body);
            Assert.Equal(newPost.dateCreated, postService.AddedPosts[0].Created);
            Assert.Equal("test", postService.AddedPosts[0].Slug);
            Assert.Equal(Oxite.Models.EntityState.Normal, postService.AddedPosts[0].State);
        }
        public void NewPostAddsPassedCategoriesAsTags()
        {
            FakePostService postService = new FakePostService();
            FakeAreaService areaService = new FakeAreaService();
            FakeTagService  tagService  = new FakeTagService();
            FakeUserService userService = new FakeUserService();
            Guid            areaID      = Guid.NewGuid();
            Guid            tag1ID      = Guid.NewGuid();
            Guid            tag2ID      = Guid.NewGuid();

            areaService.StoredAreas.Add("test", new Oxite.Models.Area()
            {
                ID = areaID
            });

            Post newPost = new Post()
            {
                categories  = new[] { "Test1", "Test2" },
                title       = "Test",
                description = "A Test",
                dateCreated = DateTime.Now,
                mt_basename = "test"
            };

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

            service.NewPost(areaID.ToString(), "test", "test", newPost, false);

            Assert.Equal(1, postService.AddedPosts.Count);

            Oxite.Models.Post savedPost = postService.AddedPosts[0];
            Assert.Equal(2, savedPost.Tags.Count);
            Assert.Contains("Test1", savedPost.Tags.Select(t => t.Name));
            Assert.Contains("Test2", savedPost.Tags.Select(t => t.Name));
        }
        public void NewPostFaultsForNonParsableBlogID()
        {
            FakeUserService userService = new FakeUserService();
            MetaWeblogAPI   service     = new MetaWeblogAPI(null, null, userService, null, null);

            Assert.Throws <FormatException>(() => service.NewPost("xxx", "test", "test", null, false));
        }
        public void NewPostFaultsOnNullUser()
        {
            FakeUserService userService = new FakeUserService();

            Guid areaID = Guid.NewGuid();

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

            Assert.Throws <ArgumentException>(() => service.NewPost(Guid.NewGuid().ToString(), null, null, new Post(), false));
        }
        public void NewPostSetsCreatorToUser()
        {
            FakePostService postService = new FakePostService();
            FakeAreaService areaService = new FakeAreaService();
            FakeTagService  tagService  = new FakeTagService();
            FakeUserService userService = new FakeUserService();
            Guid            areaID      = Guid.NewGuid();

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

            service.NewPost(areaID.ToString(), "test", "test", new Post(), false);

            Oxite.Model.Post newPost = postService.AddedPosts[0];
            Assert.Equal("test", newPost.Creator.Name);
        }
        public void NewPostSetsPublishDateToNullIfPublishFalse()
        {
            FakePostService postService = new FakePostService();
            FakeAreaService areaService = new FakeAreaService();
            FakeTagService  tagService  = new FakeTagService();
            FakeUserService userService = new FakeUserService();
            Guid            areaID      = Guid.NewGuid();

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

            Post newPost = new Post()
            {
                title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test"
            };

            service.NewPost(areaID.ToString(), "test", "test", newPost, false);

            Assert.Null(postService.AddedPosts[0].Published);
        }
        public void NewPostAddsExcerptAsBodyShort()
        {
            FakePostService postService = new FakePostService();
            FakeAreaService areaService = new FakeAreaService();
            FakeTagService  tagService  = new FakeTagService();
            FakeUserService userService = new FakeUserService();
            Guid            areaID      = Guid.NewGuid();

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

            Post newPost = new Post()
            {
                mt_excerpt = "Preview", title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test"
            };

            service.NewPost(areaID.ToString(), "test", "test", newPost, false);

            Assert.Equal(newPost.mt_excerpt, postService.AddedPosts[0].BodyShort);
        }
        public void NewPostSetsPublishDateIfPublishTrue()
        {
            FakePostService postService = new FakePostService();
            FakeAreaService areaService = new FakeAreaService();
            FakeTagService  tagService  = new FakeTagService();
            FakeUserService userService = new FakeUserService();
            Guid            areaID      = Guid.NewGuid();

            areaService.StoredAreas.Add("test", new Oxite.Models.Area()
            {
                ID = areaID
            });

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

            Post newPost = new Post()
            {
                title = "Test", description = "A Test", dateCreated = DateTime.Now, mt_basename = "test"
            };

            service.NewPost(areaID.ToString(), "test", "test", newPost, true);

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

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

            userService.Authenticate = false;

            Assert.Throws <System.Security.Authentication.InvalidCredentialException>(() => service.NewPost(Guid.NewGuid().ToString(), "test", "test", null, false));
        }