Beispiel #1
0
        public async Task Should_Get_SharePollValues()
        {
            var poll = new SharePoll
            {
                Name = "test",
                OptionsJsonString = JsonConvert.SerializeObject(new List <string> {
                    "a", "b", "c"
                }),
                Active     = true,
                CreateTime = DateTime.UtcNow,
                Deadline   = DateTime.UtcNow.AddDays(2)
            };

            _context.SharePolls.Add(poll);
            _context.SaveChanges();
            var result = await _controller.GetPollValues(poll.Id);

            var actionResult    = Assert.IsType <OkObjectResult>(result);
            var actionResultObj = actionResult.Value as SharePollViewModel;

            Assert.NotNull(actionResultObj);
            Assert.Equal(poll.Id, actionResultObj.PollId);
            Assert.Equal(poll.Name, actionResultObj.Name);
            Assert.Equal(poll.Deadline, actionResultObj.Deadline);
            Assert.Equal(poll.QuestionBody, actionResultObj.Description);
            Assert.Equal(PollListTypes.UserNotVoted.ToString().FirstCharacterToLower(), actionResultObj.ListType);
            Assert.Equal(JsonConvert.DeserializeObject(poll.OptionsJsonString), actionResultObj.Options);
        }
        public async Task Should_Get_PollStatus_For_SharePoll()
        {
            var poll = new SharePoll
            {
                Name         = "sharePoll",
                Active       = false,
                CreateTime   = new DateTime(2018, 7, 2),
                Deadline     = new DateTime(2018, 7, 2).AddDays(-2),
                QuestionBody = "test paylasim"
            };

            _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 = 1000, VoterId = 1.ToString(), VotedUserId = 2.ToString()
            });
            _context.SaveChanges();
            var result = await _pollApiViewModelService.GetPollStatus(poll.Id) as SharePollStatusViewModel;

            Assert.NotNull(result);
            Assert.Single(result.NotVotedUsers);
            Assert.Single(result.VotedUsers);
            Assert.Equal(poll.Id, result.PollId);
        }
Beispiel #3
0
        public SharePollViewModel SharePollToViewModel(SharePoll poll)
        {
            SharePollViewModel model = null;

            if (poll != null)
            {
                model = _mapper.Map <SharePoll, SharePollViewModel>(poll);
            }

            return(model);
        }
Beispiel #4
0
        public async Task Should_Calculate_EmptySharePoll_Result()
        {
            var tenant = new Tenant
            {
                Id       = "test",
                HostName = "test.decidehub.com",
                InActive = false,
                Lang     = "tr"
            };

            _tenantsDbContext.Tenants.Add(tenant);
            _tenantsDbContext.SaveChanges();
            var option = new List <string> {
                "test2", "test1", "test3", "test4"
            };
            var poll = new SharePoll
            {
                Name              = "test",
                Active            = true,
                CreateTime        = DateTime.UtcNow.AddHours(-12),
                QuestionBody      = "test dfs",
                TenantId          = "test",
                Deadline          = DateTime.UtcNow.AddHours(-1),
                OptionsJsonString = JsonConvert.SerializeObject(option)
            };

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

            await _pollJobService.CheckPollCompletion();

            var getPoll = _context.Polls.FirstOrDefault(p => p.Id == poll.Id);

            Assert.NotNull(getPoll);
            Assert.Equal(PollResults.InsufficientAuthority.ToString(), getPoll.Result);
        }
Beispiel #5
0
        public async Task <Poll> NewSharePoll(SharePollViewModel model)
        {
            var poll = new SharePoll
            {
                UserId            = model.UserId,
                CreateTime        = DateTime.UtcNow,
                Active            = true,
                Name              = model.Name,
                TenantId          = _tenantProvider.GetTenantId(),
                OptionsJsonString = JsonConvert.SerializeObject(model.Options),
                QuestionBody      = model.Description
            };
            await _pollService.AddPoll(poll);

            return(poll);
        }