public async Task Should_Get_PollStatus()
        {
            var poll = new PolicyChangePoll
            {
                Name         = "PolicyChangePoll test",
                Active       = true,
                CreateTime   = new DateTime(2018, 6, 2),
                Deadline     = DateTime.UtcNow.AddHours(26),
                QuestionBody = "PolicyChangePoll test"
            };

            _context.Add(poll);
            _context.SaveChanges();
            _context.Users.Add(new ApplicationUser
            {
                Email          = "*****@*****.**",
                FirstName      = "test",
                LastName       = "Test",
                CreatedAt      = DateTime.UtcNow,
                SecurityStamp  = new Guid().ToString(),
                EmailConfirmed = false,
                Id             = 1.ToString(),
                IsDeleted      = false,
                UserDetail     = new UserDetail {
                    AuthorityPercent = 1, LanguagePreference = "tr"
                }
            });

            _context.Users.Add(new ApplicationUser
            {
                Email          = "*****@*****.**",
                FirstName      = "Test",
                LastName       = "Test",
                CreatedAt      = DateTime.UtcNow,
                SecurityStamp  = new Guid().ToString(),
                EmailConfirmed = false,
                Id             = 2.ToString(),
                IsDeleted      = false,
                UserDetail     = new UserDetail {
                    AuthorityPercent = 1, LanguagePreference = "tr"
                }
            });
            _context.SaveChanges();
            _context.Votes.Add(new Vote {
                PollId = poll.Id, Value = 1, VoterId = 1.ToString()
            });
            _context.SaveChanges();
            var result = await _pollApiViewModelService.GetPollStatus(poll.Id);

            Assert.Single(result.NotVotedUsers);
            Assert.Single(result.VotedUsers);
            Assert.Equal(poll.Id, result.PollId);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetPollStatus(long pollId)
        {
            var poll = await _pollService.GetPoll(pollId);

            if (poll == null)
            {
                ModelState.AddModelError("", _localizer["PollNotFound"]);
                return(BadRequest(Errors.GetErrorList(ModelState)));
            }

            var polls = await _pollViewModelService.GetPollStatus(pollId);

            return(Ok(polls));
        }