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 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 ListByTagReturnsListOfComments()
        {
            FakeCommentService commentService = new FakeCommentService();
            FakePostService    postService    = new FakePostService();
            FakeTagService     tagService     = new FakeTagService();

            commentService.AllComments.Add(new Comment());
            commentService.AllComments.Add(new Comment());

            tagService.StoredTags.Add("test", new Tag());

            CommentController controller = new CommentController(postService, commentService, tagService, null)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteViewModelItems <Comment> result = controller.ListByTag(new Tag()
            {
                Name = "test"
            });

            Assert.Equal(2, result.Items.Count());
            Assert.Same(commentService.AllComments[0], result.Items.ElementAt(0));
            Assert.Same(commentService.AllComments[1], result.Items.ElementAt(1));
        }
        public void ListByTagSetsTagAsContainer()
        {
            FakeCommentService commentService = new FakeCommentService();
            FakePostService    postService    = new FakePostService();
            FakeTagService     tagService     = new FakeTagService();

            commentService.AllComments.Add(new Comment());
            commentService.AllComments.Add(new Comment());

            tagService.StoredTags.Add("test", new Tag());

            CommentController controller = new CommentController(postService, commentService, tagService, null)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteViewModelItems <Comment> result = controller.ListByTag(new Tag()
            {
                Name = "test"
            });

            Assert.Same(tagService.StoredTags["test"], result.Container);
        }
Пример #6
0
        public void ListByTagReturnsListOfComments()
        {
            FakePostService postService = new FakePostService();
            FakeTagService  tagService  = new FakeTagService();

            postService.AllComments.Add(new ParentAndChild <PostBase, Comment>()
            {
                Parent = new Post(), Child = new Comment()
            });
            postService.AllComments.Add(new ParentAndChild <PostBase, Comment>()
            {
                Parent = new Post(), Child = new Comment()
            });

            tagService.StoredTags.Add("test", new Tag());

            CommentController controller = new CommentController(postService, tagService, null)
            {
                ControllerContext = new System.Web.Mvc.ControllerContext()
                {
                    RouteData = new System.Web.Routing.RouteData()
                }
            };

            OxiteModelList <ParentAndChild <PostBase, Comment> > result = controller.ListByTag(new Tag()
            {
                Name = "test"
            });

            Assert.Equal(2, result.List.Count);
            Assert.Same(postService.AllComments[0], result.List[0]);
            Assert.Same(postService.AllComments[1], result.List[1]);
        }
Пример #7
0
        public void ListByTagReturnsNullOnBadTag()
        {
            FakeTagService tagService = new FakeTagService();

            CommentController controller = new CommentController(null, tagService, null);

            Assert.Null(controller.ListByTag(new Tag()
            {
                Name = "test"
            }));
        }
Пример #8
0
        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 GetCategoriesReturnsAllTags()
        {
            FakeTagService  tagService  = new FakeTagService();
            FakeUserService userService = new FakeUserService();

            tagService.StoredTags.Add("test", new Oxite.Models.Tag()
            {
                Name = "test"
            });

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

            CategoryInfo[] categories = service.GetCategories(null, "test", "test");

            Assert.Equal(1, categories.Length);
            Assert.Equal("test", categories[0].description);
        }
Пример #10
0
        public void ListByTagReturnsNullForInvalidArea()
        {
            FakePostService postService = new FakePostService();
            FakeTagService  tagService  = new FakeTagService();

            Tag tag = new Tag()
            {
                Name = "Test"
            };

            PostController controller = new PostController(postService, tagService, null, null);

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(new FakeHttpContext("~/"), new RouteData(), controller);

            OxiteModelList <Post> result = controller.ListByTag(null, 0, tag, null);

            Assert.Null(result);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        public void ListByTagSetsTagOnModel()
        {
            FakePostService postService = new FakePostService();
            FakeTagService  tagService  = new FakeTagService();

            Tag tag = new Tag()
            {
                Name = "Test"
            };

            tagService.StoredTags.Add("Test", tag);

            PostController controller = new PostController(postService, tagService, null, null);

            controller.ControllerContext = new System.Web.Mvc.ControllerContext(new FakeHttpContext("~/"), new RouteData(), controller);

            OxiteModelList <Post> result = controller.ListByTag(null, 0, tag, null);

            Assert.Equal(tag.Name, result.Container.Name);
        }
        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);
        }