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 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(publishedDate)
            {
                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.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 AddReturnsSuccessResult()
        {
            FakePostService postService = new FakePostService();

            Guid postId = Guid.NewGuid();

            postService.AddedPosts.Add(new Post()
            {
                ID = postId, Trackbacks = new List <Trackback>(new[] { new Trackback()
                                                                       {
                                                                           Url = "http://test"
                                                                       } })
            });

            FormCollection form = new FormCollection();

            form.Add("url", "http://test");
            form.Add("title", "Test");
            form.Add("blog_name", "Test Blog");
            form.Add("excerpt", "Test excerpt");

            TrackbackController controller = new TrackbackController(postService);

            TrackbackViewModel result = controller.Add(postId, form);

            Assert.Equal(0, result.ErrorCode);
            Assert.True(string.IsNullOrEmpty(result.ErrorMessage));
        }
Beispiel #7
0
        public void ListByAreaSetsAreaAsContainer()
        {
            FakePostService postService = new FakePostService();
            FakeAreaService areaService = new FakeAreaService();

            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()
            });

            areaService.StoredAreas.Add("test", new Area());

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

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

            Assert.Same(areaService.StoredAreas["test"], result.Container);
        }
Beispiel #8
0
        public void PingReturnsSuccessIfTrackbackFound()
        {
            FakePostService postService = new FakePostService();

            postService.AddedPosts.Add(new Oxite.Model.Post()
            {
                Slug = "test", Trackbacks = new List <Trackback>(new[] { new Trackback()
                                                                         {
                                                                             Url = "http://test.com/foo"
                                                                         } })
            });

            RouteCollection routes = new RouteCollection();

            routes.Add("Post", new Route("{slug}/{areaName}", null));

            AbsolutePathHelper helper = new AbsolutePathHelper(new Site()
            {
                Host = new Uri("http://foo.com")
            }, routes);

            PingbackService service = new PingbackService(postService, helper);

            string result = service.Ping("http://test.com/foo", "http://foo.com/test/area");

            Assert.Null(postService.AddedTrackback);
        }
Beispiel #9
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]);
        }
Beispiel #10
0
        public void ListSetsHomePageContainer()
        {
            FakePostService postService = new FakePostService();

            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()
            });

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

            OxiteModelList <ParentAndChild <PostBase, Comment> > result = controller.List();

            Assert.IsType <HomePageContainer>(result.Container);
        }
        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 AddUpdatesTrackbackIfExistingTrackbackFound()
        {
            FakePostService postService = new FakePostService();

            Guid postId = Guid.NewGuid();

            postService.AddedPosts.Add(new Post()
            {
                ID = postId, Trackbacks = new List <Trackback>(new[] { new Trackback()
                                                                       {
                                                                           Url = "http://test"
                                                                       } })
            });

            FormCollection form = new FormCollection();

            form.Add("url", "http://test");
            form.Add("title", "Test");
            form.Add("blog_name", "Test Blog");
            form.Add("excerpt", "Test excerpt");

            TrackbackController controller = new TrackbackController(postService);

            controller.Add(postId, form);

            Assert.NotNull(postService.AddedTrackback);
            Assert.Equal("Test", postService.AddedTrackback.Title);
            Assert.Equal("Test Blog", postService.AddedTrackback.BlogName);
            Assert.Equal("Test excerpt", postService.AddedTrackback.Body);
            Assert.Null(postService.AddedTrackback.IsTargetInSource);
        }
        public void ListByPostReturnsNullOnBadPostAddress()
        {
            FakePostService postService = new FakePostService();

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

            Assert.Null(controller.ListByPost(new PostAddress("test", "test")));
        }
Beispiel #14
0
        public void TestsCleanup()
        {
            this.postService    = null;
            this.commentService = null;
            this.storageService = null;
            this.dialogService  = null;

            this.postViewModel = null;
        }
        public void GetPostFaultsOnBadID()
        {
            FakePostService postService = new FakePostService();
            FakeUserService userService = new FakeUserService();

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

            Assert.Throws <ArgumentOutOfRangeException>(() => service.GetPost(Guid.NewGuid().ToString(), "test", "test"));
        }
        public void GetPostReturnsPost()
        {
            FakePostService postService = new FakePostService();
            FakeUserService userService = new FakeUserService();

            DateTime now = DateTime.Now;

            Oxite.Models.Post fakePost = new Oxite.Models.Post()
            {
                Title     = "Title",
                Body      = "Body",
                Created   = DateTime.Now,
                Published = DateTime.Now,
                ID        = Guid.NewGuid(),
                Creator   = new Oxite.Models.User()
                {
                    DisplayName = "Test User", Name = "user"
                },
                BodyShort = "Excerpt",
                Slug      = "Slug"
            };
            fakePost.Area = new Oxite.Models.Area()
            {
                ID = Guid.NewGuid(), Name = "Blog1", DisplayName = "Blog One"
            };
            fakePost.Tags =
                new List <Oxite.Models.Tag>(new[]
            {
                new Oxite.Models.Tag()
                {
                    ID = Guid.NewGuid(), Name = "Tag1"
                },
                new Oxite.Models.Tag()
                {
                    ID = Guid.NewGuid(), Name = "Tag2"
                }
            });

            postService.AddedPosts.Add(fakePost);

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

            Post post = service.GetPost(fakePost.ID.ToString(), "test", "test");

            Assert.NotNull(post);
            Assert.Equal(fakePost.Title, post.title);
            Assert.Equal(fakePost.Body, post.description);
            Assert.Equal(fakePost.Created, post.dateCreated);
            Assert.Equal(fakePost.Creator.ID, new Guid(post.userid));
            Assert.Equal(fakePost.BodyShort, post.mt_excerpt);
            Assert.Equal(fakePost.Slug, post.mt_basename);
            foreach (string category in post.categories)
            {
                Assert.Contains <string>(category, fakePost.Tags.Select(t => t.Name));
            }
        }
Beispiel #17
0
        public void TestsInitialize()
        {
            this.postService    = new FakePostService();
            this.commentService = new FakeCommentService();
            this.storageService = new FakeStorageService();
            this.dialogService  = new FakeDialogService();

            this.postViewModel = new PostViewModel(this.postService, this.commentService,
                                                   this.storageService, this.dialogService);
        }
        public void TestsCleanup()
        {
            this.storageService      = null;
            this.navigationService   = null;
            this.postService         = null;
            this.localizationService = null;
            this.dialogService       = null;

            this.homeViewModel = null;
        }
Beispiel #19
0
        public void TestsCleanup()
        {
            this.postService       = null;
            this.boxService        = null;
            this.navigationService = null;
            this.storageService    = null;
            this.dialogService     = null;

            this.boxViewModel = null;
        }
        public void TestsInitialize()
        {
            this.storageService      = new FakeStorageService();
            this.navigationService   = new FakeNavigationService();
            this.postService         = new FakePostService();
            this.localizationService = new FakeLocalizationService();
            this.dialogService       = new FakeDialogService();

            this.homeViewModel = new HomeViewModel(this.storageService, this.navigationService,
                                                   this.postService, this.localizationService, this.dialogService);
        }
        public void ListReturnsNullListOnRequestForNonExistantPage()
        {
            FakePostService postService = new FakePostService();
            Guid            postID      = Guid.NewGuid();

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

            OxiteModelList <Post> result = controller.List(2, 10, null);

            Assert.Null(result.List);
        }
        public void AddFaultsIfPostIsNotFound()
        {
            FakePostService postService = new FakePostService();

            TrackbackController controller = new TrackbackController(postService);

            TrackbackViewModel result = controller.Add(Guid.NewGuid(), null);

            Assert.NotNull(result);
            Assert.Equal(0, result.ErrorCode);
        }
Beispiel #23
0
        public void TestsInitialize()
        {
            this.postService       = new FakePostService();
            this.boxService        = new FakeBoxService();
            this.navigationService = new FakeNavigationService();
            this.storageService    = new FakeStorageService();
            this.dialogService     = new FakeDialogService();

            this.boxViewModel = new BoxViewModel(this.postService, this.boxService,
                                                 this.navigationService, this.storageService, this.dialogService);
        }
        public void ListBySearchReturnsHomePageOnEmptySearch()
        {
            FakePostService postService = new FakePostService();

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

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

            OxiteModelList <Post> result = controller.ListBySearch(null, 0, new SearchCriteria(), null);

            Assert.IsType <HomePageContainer>(result.Container);
        }
        public void ItemReturnsNullOnNotFoundPost()
        {
            FakeAreaService areaService = new FakeAreaService();
            FakePostService postService = new FakePostService();

            areaService.StoredAreas.Add("test", new Area());

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

            OxiteViewModelItem <Post> result = controller.Item(new PostAddress("test", "Some-Post"), null);

            Assert.Null(result);
        }
        public void ListByArchiveSetsHomePageContainerOnModel()
        {
            FakePostService postService = new FakePostService();

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

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

            OxiteModelList <Post> result = controller.ListByArchive(0, new ArchiveData());

            Assert.IsType <ArchiveContainer>(result.Container);
            Assert.Equal(new ArchiveData(), ((ArchiveContainer)result.Container).ArchiveData);
        }
        public void ListBySearchSetsSearchContainerOnModel()
        {
            FakePostService postService = new FakePostService();

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

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

            OxiteModelList <Post> result = controller.ListBySearch(null, 0, new SearchCriteria()
            {
                Term = "test"
            }, null);

            Assert.IsType <SearchPageContainer>(result.Container);
        }
        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);
        }
Beispiel #29
0
        public void PingFaultsForNotFoundPost()
        {
            FakePostService postService = new FakePostService();
            RouteCollection routes      = new RouteCollection();

            routes.Add("Post", new Route("{slug}/{areaName}", null));

            AbsolutePathHelper helper = new AbsolutePathHelper(new Site()
            {
                Host = new Uri("http://foo.com")
            }, routes);

            PingbackService service = new PingbackService(postService, helper);

            Assert.Throws <ArgumentException>(() => service.Ping("http://test.com/foo", "http://foo.com/test/area"));
        }
        public void ItemReturnsNullOnNotFoundPost()
        {
            FakeAreaService areaService = new FakeAreaService();
            FakePostService postService = new FakePostService();

            areaService.StoredAreas.Add("test", new Area());

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

            OxiteModelItem <Post> result = controller.Item(new Area()
            {
                Name = "test"
            }, new Post());

            Assert.Null(result);
        }