public void SetUp() { var mockPostTagList = new List <PostTag> { new PostTag { PostId = _postId, TagId = _tagId, CreatedAt = _createdAt }, new PostTag { PostId = _postId2, TagId = _tagId2, CreatedAt = _createdAt2 } }; var mockTagList = new List <Tag> { new Tag { Id = _tagId, Title = _tag, CreatedAt = _createdAt }, new Tag { Id = _tagId2, Title = _tag2, CreatedAt = _createdAt } }; _postTagRepositoryMock = new Mock <IBaseRepository <PostTag> >(); _tagRepositoryMock = new Mock <IBaseRepository <Tag> >(); _postTagRepositoryMock.Setup(repo => repo.All()) .Returns(mockPostTagList); _postTagRepositoryMock.Setup(repo => repo.Where(It.IsAny <Expression <Func <PostTag, bool> > >())) .Returns((Expression <Func <PostTag, bool> > expression) => mockPostTagList.AsQueryable().Where(expression)); _tagRepositoryMock.Setup(repo => repo.All()) .Returns(mockTagList); _tagRepositoryMock.Setup(repo => repo.Where(It.IsAny <Expression <Func <Tag, bool> > >())) .Returns((Expression <Func <Tag, bool> > expression) => mockTagList.AsQueryable().Where(expression)); _postTagService = new PostTagService(_postTagRepositoryMock.Object, _tagRepositoryMock.Object); }
public HttpResponseMessage DeleteMulti(HttpRequestMessage request, int[] id) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var PostTagService = new PostTagService(); PostTagService.DeleteAll(id); response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }
public HttpResponseMessage Update(HttpRequestMessage request, PostTagModel PostTagModel) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var PostTagService = new PostTagService(); PostTagService.Update(PostTagModel); response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }
public PostTagsController(PostTagService postTagService) { _postTagService = postTagService; }