InsanelySimpleBlog.Services.Implementation.PostsService.Get C# (CSharp) Method

Get() public method

public Get ( int postId ) : PostViewModel
postId int
return InsanelySimpleBlog.ViewModel.PostViewModel
        public PostViewModel Get(int postId)
        {
            Condition.Requires(postId, "postId").IsGreaterOrEqual(0);
            Post post = null;
            using (IUnitOfWork unitOfWork = _unitOfWorkFactory.Create())
            {
                unitOfWork.Execute(() =>
                {
                    IRepository<Post> repository = unitOfWork.GetRepository<Post>();
                    post= repository
                        .AllIncluding(x => x.Categories, x => x.Author)
                        .Single(x => x.PostID == postId);
                });
            }

            return _postMapper.Map(post);
        }

Usage Example

コード例 #1
0
        public void GetReturnsCorrectPost()
        {
            // Arrange
            PostViewModel mappedPost = new PostViewModel {PostID = 2};
            PostsService service = new PostsService(_unitOfWorkFactory, _mapper);
            _mapper.Stub(x => x.Map(_post2)).Return(mappedPost);

            // Act
            PostViewModel model = service.Get(2);

            // Assert
            Assert.That(model, Is.EqualTo(mappedPost));
        }