public async Task PostVote_ShouldNotFindOption()
        {
            // Arrange
            var poll       = CreatePoll();
            var votePostVM = new VotePostVM {
                Id = int.MaxValue
            };

            // Act
            var result = await _pollController.PostVote(poll.Id, votePostVM);

            // Assert
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> PostVote(int pollId, [FromBody] VotePostVM votePostVM)
        {
            try
            {
                var option = await _pollRepository.GetOptionAsync(pollId, votePostVM.Id);

                _pollRepository.IncrementVotesQty(option);
                return(CreatedAtAction(nameof(GetStats), new { pollId },
                                       new { option_id = votePostVM.Id }));
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }
            catch (Exception e)
            {
                return(Problem(e.Message));
            }
        }
        public async Task PostVote_ShouldAddOneToVotesQty()
        {
            // Arrange
            var poll       = CreatePoll();
            var option     = poll.Options.First();
            var votePostVM = new VotePostVM {
                Id = option.Id
            };

            // Act
            await _pollController.PostVote(poll.Id, votePostVM);

            await _pollController.PostVote(poll.Id, votePostVM);

            await _pollController.PostVote(poll.Id, votePostVM);

            // Assert
            Assert.AreEqual(option.VotesQty, 3L);
        }