public async Task <AuthorComment> AddAuthorComment(AuthorComment authorComment) { authorComment.User = await _applicationContext.Users.FindAsync(authorComment.UserId); authorComment.Author = await _applicationContext.Authors.FindAsync(authorComment.AuthorId); await _applicationContext.AuthorComments.AddAsync(authorComment); await _applicationContext.SaveChangesAsync(); return(await _applicationContext.AuthorComments.FirstOrDefaultAsync(w => string.Equals(w.Id, authorComment.Id))); }
public void DeleteAuthorComment_GoodArgument_Success() { var authorComment = new AuthorComment { Id = "123", Comment = "SomeAuthorComment", UserId = "SomeUserId", AuthorId = "SomeAuthorId1", DateTime = DateTime.Now, Author = new Author(), User = new User(), AuthorCommentLikes = new List <AuthorCommentLike>() }; _mockCommentRepository.Setup(w => w.GetAuthorComment(It.IsAny <string>())).ReturnsAsync(authorComment); using var commentService = new CommentService(_mockCommentRepository.Object, _mapper); var deleteAuthorComment = commentService.DeleteAuthorComment("123"); _mockCommentRepository.Verify(w => w.DeleteAuthorComment(It.IsAny <AuthorComment>()), Times.Once); }
public void Init() { _mockCommentRepository = new Mock <ICommentRepository>(); _mapperConfiguration = new MapperConfiguration(cfg => cfg.AddProfiles(new List <Profile> { new BookCommentProfile(), new AuthorCommentProfile() })); _mapper = new Mapper(_mapperConfiguration); _bookComment = new BookComment { Id = Guid.NewGuid().ToString(), Comment = "SomeBookComment", UserId = "SomeUserId", BookId = "SomeBookId", DateTime = DateTime.Now, Book = new Book(), User = new User(), BookCommentLikes = new List <BookCommentLike>() }; _bookComments = new List <BookComment> { _bookComment, _bookComment, _bookComment }; _authorComment = new AuthorComment { Id = Guid.NewGuid().ToString(), Comment = "SomeAuthorComment", UserId = "SomeUserId", AuthorId = "SomeAuthorId", DateTime = DateTime.Now, Author = new Author(), User = new User(), AuthorCommentLikes = new List <AuthorCommentLike>() }; _authorComments = new List <AuthorComment> { _authorComment, _authorComment, _authorComment }; }
public async Task DeleteAuthorComment(AuthorComment authorComment) { _applicationContext.AuthorComments.Remove(authorComment); await _applicationContext.SaveChangesAsync(); }