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]); }
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 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); }
private static OxiteModelList <KeyValuePair <Tag, int> > getTagList(INamedEntity container, Func <IList <KeyValuePair <Tag, int> > > serviceCall) { var result = new OxiteModelList <KeyValuePair <Tag, int> > { Container = container, List = serviceCall() }; return(result); }
private static OxiteModelList <Post> GetPostList(INamedEntity container, Func <IPageOfList <Post> > serviceCall) { OxiteModelList <Post> result = new OxiteModelList <Post> { Container = container, List = serviceCall() }; return(result); }
private static OxiteModelList <ParentAndChild <PostBase, Comment> > getCommentList(INamedEntity container, Func <IPageOfList <ParentAndChild <PostBase, Comment> > > serviceCall) { OxiteModelList <ParentAndChild <PostBase, Comment> > result = new OxiteModelList <ParentAndChild <PostBase, Comment> > { Container = container, List = serviceCall() }; return(result); }
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 virtual OxiteModelList <Area> FindQuery(AreaSearchCriteria searchCriteria) { IList <Area> foundAreas = areaService.FindAreas(searchCriteria); OxiteModelList <Area> model = new OxiteModelList <Area> { List = foundAreas }; model.AddModelItem(searchCriteria); return(model); }
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 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 ListReturnsPageNOnRequestForPageN() { FakePostService postService = new FakePostService(); Guid postID = Guid.NewGuid(); postService.PostPages.Add(3, new List <Post>(new[] { new Post() { ID = postID } })); PostController controller = new PostController(postService, null, null, null); OxiteModelList <Post> result = controller.List(4, 10, null); Assert.Equal(1, result.List.Count); Assert.Equal(postID, result.List[0].ID); }
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); }
//TODO: (erikpo) This method is lame, but not sure how to cast model as OxiteModelList of T private static int getModelListCount(object model) { OxiteModelList <Post> postListModel = model as OxiteModelList <Post>; if (postListModel != null) { return(postListModel.List.Count); } OxiteModelList <Comment> commentListModel = model as OxiteModelList <Comment>; if (commentListModel != null) { return(commentListModel.List.Count); } throw new ArgumentException("Unable to determine count from model"); }
public void ListUsesIfModifiedSince() { FakePostService postService = new FakePostService(); Guid postID = Guid.NewGuid(); postService.PostPages.Add(0, new List <Post>(new[] { new Post() { ID = postID } })); PostController controller = new PostController(postService, null, null, null); DateTime sinceDate = DateTime.Now; OxiteModelList <Post> result = controller.List(null, 10, sinceDate); Assert.Equal(sinceDate, postService.LastRequestedSinceDate); }
public void ListByAreaReturnsNullForInvalidArea() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); Area area = new Area() { Name = "test" }; PostController controller = new PostController(postService, null, areaService, null); controller.ControllerContext = new System.Web.Mvc.ControllerContext(new FakeHttpContext("~/"), new RouteData(), controller); OxiteModelList <Post> result = controller.ListByArea(null, 10, area, null); Assert.Null(result); }
public void ListReturnsPageOneOnNullPageNumber() { FakePostService postService = new FakePostService(); Guid postID = Guid.NewGuid(); postService.PostPages.Add(0, new List <Post>(new[] { new Post() { ID = postID } })); PostController controller = new PostController(postService, null, null, null); OxiteModelList <Post> result = controller.List(null, 10, null); Assert.Equal(1, result.List.Count); Assert.Equal(postID, result.List[0].ID); Assert.IsType <HomePageContainer>(result.Container); Assert.Equal(10, postService.LastRequestedPageSize); }
public void ListByPostReturnsListOfComments() { 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() }); postService.AddedPosts.Add(new Post() { Slug = "test" }); 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.ListByPost(new Area() { Name = "test" }, new Post() { Slug = "test" }); Assert.Equal(2, result.List.Count); Assert.Same(postService.AllComments[0].Child, result.List[0].Child); Assert.Same(postService.AllComments[1].Child, result.List[1].Child); Assert.Same(postService.AddedPosts[0], result.List[0].Parent); Assert.Same(postService.AddedPosts[0], result.List[1].Parent); }
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 ListByAreaSetsAreaOnModel() { FakePostService postService = new FakePostService(); FakeAreaService areaService = new FakeAreaService(); Area area = new Area() { Name = "test" }; areaService.StoredAreas.Add("test", area); PostController controller = new PostController(postService, null, areaService, null); controller.ControllerContext = new System.Web.Mvc.ControllerContext(new FakeHttpContext("~/"), new RouteData(), controller); OxiteModelList <Post> result = controller.ListByArea(null, 10, area, null); Assert.Equal(area.Name, result.Container.Name); }
public void OnResultExecuting(ResultExecutingContext filterContext) { OxiteModelList <Post> model = filterContext.Controller.ViewData.Model as OxiteModelList <Post>; if (model != null) { UrlHelper urlHelper = new UrlHelper(filterContext.RequestContext); ResponseFilter responseFilter = new ResponseFilter(filterContext.HttpContext.Response.Filter, filterContext.HttpContext); for (int i = 0; i < model.List.Count; i++) { Post post = model.List[i]; string imgTag = HttpUtility.HtmlEncode(string.Format("<div><img src=\"{0}\" width=\"1\" height=\"1\" alt=\"\" /></div>", urlHelper.AbsolutePath(urlHelper.PostViewBug(post, viewType)))); int index = i; responseFilter.Inserts.Add(new ResponseInsert(imgTag, ResponseInsertMode.AppendTo, doc => findElements(doc, index), (elements, mode, value) => insertValue(elements, mode, value))); } filterContext.HttpContext.Response.Filter = responseFilter; } }