コード例 #1
0
        public async Task Wall_GetPagedWall_Should_Return_View_Model()
        {
            var wallId = 1;
            var page   = 1;

            IEnumerable <PostDto> posts = new List <PostDto>
            {
                new PostDto
                {
                    Id = 0
                },
                new PostDto
                {
                    Id = 1
                }
            };

            _wallService.GetWallAsync(wallId, null).Returns(new WallDto {
                Type = WallType.UserCreated
            });
            _wallService.GetWallPostsAsync(page, WebApiConstants.DefaultPageSize, null, wallId).ReturnsForAnyArgs(Task.Run(() => posts));

            var response = await _wallController.GetPagedWall(wallId, page);

            Assert.IsInstanceOf <OkNegotiatedContentResult <PagedWallViewModel <WallPostViewModel> > >(response);
        }
コード例 #2
0
        public async Task <IHttpActionResult> GetPagedWall(int wallId, int page = 1)
        {
            if (wallId <= 0)
            {
                return(BadRequest());
            }

            try
            {
                var userAndOrg = GetUserAndOrganization();
                var wall       = await _wallService.GetWallAsync(wallId, userAndOrg);

                if (!await _permissionService.UserHasPermissionAsync(userAndOrg, BasicPermissions.Post) && wall.Type != WallType.Events)
                {
                    return(Forbidden());
                }

                var wallPosts = await _wallService.GetWallPostsAsync(page, WebApiConstants.DefaultPageSize, userAndOrg, wallId);

                var mappedPosts    = _mapper.Map <IEnumerable <WallPostViewModel> >(wallPosts);
                var pagedViewModel = new PagedWallViewModel <WallPostViewModel>
                {
                    PagedList = await mappedPosts.ToPagedListAsync(1, WebApiConstants.DefaultPageSize),
                    PageSize  = WebApiConstants.DefaultPageSize
                };
                return(Ok(pagedViewModel));
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }
        }