private async Task AddNewVote(VoteDto voteDto, CancellationToken ct) { var vote = _mapper.Map <Vote>(voteDto); _context.Votes.Add(vote); await _context.SaveChangesAsync(ct); if (vote.Value > 0) { await _context.AddUpVoteAsync(voteDto.CommentId, ct).ConfigureAwait(false); } else { await _context.AddDownVoteAsync(voteDto.CommentId, ct).ConfigureAwait(false); } }
public async Task AddDownVote_AddsOneTo_DownVoteCount() { var comment = new Comment { Text = "IncrementCommentCountTest", User = "******" }; using (var context = new CommentContext(Options)) { context.Comments.Add(comment); await context.SaveChangesAsync(); await context.AddDownVoteAsync(comment.Id); await context.Entry(comment).ReloadAsync(); Assert.Equal(1, comment.DownVoteCount); } }