public async Task <ActionResult <Posts> > Post(Posts value) { System.Diagnostics.Debug.WriteLine("Testing"); var entity = await _service.Create(value); if (entity != null) { return(Ok(entity)); } else { return(BadRequest("something broke ")); } }
public async Task <ActionResult <Post> > Post([FromBody] Post newPost) { try { Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newPost.CreatorId = userInfo.Id; Post created = _ps.Create(newPost); created.Creator = userInfo; return(Ok(created)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async void Create() { var mock = new ServiceMockFacade <IPostsRepository>(); var model = new ApiPostsRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Posts>())).Returns(Task.FromResult(new Posts())); var service = new PostsService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostsModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostsMapperMock, mock.DALMapperMockFactory.DALPostsMapperMock); CreateResponse <ApiPostsResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PostsModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPostsRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Posts>())); }
public async Task PhotoCreateCountShouldBeOne() { var posts = new List <Post>(); var appUsers = new List <ApplicationUser>(); var mockPostRepo = new Mock <IDeletableEntityRepository <Post> >(); mockPostRepo.Setup(x => x.All()).Returns(posts.AsQueryable()); mockPostRepo.Setup(x => x.AddAsync(It.IsAny <Post>())).Callback((Post post) => posts.Add(post)); var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >(); mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable()); mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU)); var service = new PostsService(mockAppUser.Object, mockPostRepo.Object); await service.Create("Text", "1", "1", "Are you crazy?"); var expectedResult = 1; Assert.Equal(expectedResult, posts.Count()); }
public ActionResult <Post> Create(Post post) { _postsService.Create(post); return(CreatedAtRoute("GetPost", new { id = post.Id.ToString() }, post)); }