public async Task Should_Check_IfUserVotedInPoll() { var poll = new PolicyChangePoll { Name = "test", Active = true, CreateTime = DateTime.UtcNow, QuestionBody = "test dfs", TenantId = "test" }; _context.Polls.Add(poll); var userList = new List <ApplicationUser> { 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 = 20, LanguagePreference = "tr" } }, new ApplicationUser { Email = "*****@*****.**", FirstName = "test", LastName = "Test", TenantId = "test", CreatedAt = DateTime.UtcNow, SecurityStamp = new Guid().ToString(), EmailConfirmed = false, Id = 2.ToString(), IsDeleted = false, UserDetail = new UserDetail { AuthorityPercent = 30, LanguagePreference = "tr" } } }; _context.Users.AddRange(userList); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 1, VoterId = 1.ToString() }); _context.SaveChanges(); var res1 = await _voteService.UserVotedInPoll(1.ToString(), poll.Id); var res2 = await _voteService.UserVotedInPoll(2.ToString(), poll.Id); Assert.True(res1); Assert.False(res2); }
public async Task Should_Add_Poll_And_PollSetting() { var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); var poll = new PolicyChangePoll { Name = "test", Active = true, CreateTime = DateTime.UtcNow, QuestionBody = "test dfs", TenantId = "test" }; var addedPoll = await pollService.AddPoll(poll); var pollSetting = _context.PollSetting.FirstOrDefault(x => x.PollId == addedPoll.Id); Assert.NotNull(pollSetting); var settingList = JsonConvert.DeserializeObject <List <Setting> >(pollSetting.SettingJsonString); Assert.Equal(1, _context.PolicyChangePolls.Count()); Assert.Equal(VotingFrequency.ToString(), settingList.FirstOrDefault(x => x.Key == Settings.VotingFrequency.ToString())?.Value); Assert.Equal(AuthorityVotingRequiredUserPercentage.ToString(), settingList.FirstOrDefault(x => x.Key == Settings.AuthorityVotingRequiredUserPercentage.ToString()) ?.Value); Assert.Equal(VotingDuration.ToString(), settingList.FirstOrDefault(x => x.Key == Settings.VotingDuration.ToString())?.Value); Assert.Equal(poll.CreateTime.AddHours(VotingDuration).ToString("dd.MM.yyyy HH:mm"), addedPoll.Deadline.ToString("dd.MM.yyyy HH:mm")); }
public async Task Should_Remove_PollAndVotes() { var completedPoll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow, Deadline = DateTime.UtcNow.AddDays(2), QuestionBody = "PolicyChangePoll test", UserId = 1.ToString() }; _context.Polls.Add(completedPoll); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = completedPoll.Id, Value = -1, VoterId = _currentUser.Id }); _context.SaveChanges(); var result = await _controller.RemovePoll(completedPoll.Id); Assert.IsType <OkObjectResult>(result); var poll = _context.Polls.FirstOrDefault(x => x.Id == completedPoll.Id); var votes = _context.Votes.Where(x => x.PollId == completedPoll.Id); Assert.Null(poll); Assert.Equal(0, votes.Count()); }
public void Should_Check_IfPollIsCompleted() { var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; var poll2 = new PolicyChangePoll { Name = "test", Active = false, CreateTime = new DateTime(2018, 7, 3), Deadline = DateTime.UtcNow.AddHours(-24), QuestionBody = "test 123" }; _context.Polls.Add(poll); _context.Polls.Add(poll2); _context.SaveChanges(); var res1 = pollService.IsCompleted(poll); var res2 = pollService.IsCompleted(poll2); Assert.False(res1); Assert.True(res2); }
public async Task Should_Get_PolicyChangePollValues() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow.AddHours(1), Deadline = DateTime.UtcNow.AddDays(1), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); var result = await _controller.GetPollValues(poll.Id); var actionResult = Assert.IsType <OkObjectResult>(result); var actionResultObj = actionResult.Value as PollListViewModel; 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); }
public async Task Should_Save_Vote() { _currentUser.UserDetail.AuthorityPercent = 30; var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow.AddHours(1), Deadline = DateTime.UtcNow.AddDays(1), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); var model = new PolicyChangePollVoteViewModel { PollId = poll.Id, PollValue = 1 }; var result = await _controller.Vote(model); var vote = _context.Votes.FirstOrDefault(x => x.PollId == poll.Id && x.Value == model.PollValue); var actionResult = Assert.IsType <OkObjectResult>(result); var actionResultObj = actionResult.Value as PollListViewModel; Assert.NotNull(vote); Assert.True(actionResultObj.UserVoted); }
public async Task Should_Get_TenantPollCount_ByType() { var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; var poll2 = new PolicyChangePoll { Name = "test", Active = false, CreateTime = new DateTime(2018, 7, 3), Deadline = DateTime.UtcNow.AddHours(-24), QuestionBody = "test 123" }; _context.Polls.Add(poll); _context.Polls.Add(poll2); _context.SaveChanges(); var count = await pollService.GetPollCountByType <PolicyChangePoll>("test"); Assert.Equal(2, count); }
public async Task Should_Get_Poll_Voting_Duration() { var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; var pollSetting = new List <Setting> { new Setting { Key = Settings.VotingDuration.ToString(), Value = "12", IsVisible = true } }; var pollSettingJson = JsonConvert.SerializeObject(pollSetting); poll.PollSetting = new PollSetting { SettingJsonString = pollSettingJson }; _context.Polls.Add(poll); _context.SaveChanges(); var duration = await pollService.GetPollVotingDuration(poll.Id); Assert.Equal(12, duration); }
public async Task Shouldnt_Remove_Poll_IfCurrentUserDidntStartPoll() { var completedPoll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow, Deadline = DateTime.UtcNow.AddDays(2), QuestionBody = "PolicyChangePoll test", UserId = 2.ToString() }; _context.Polls.Add(completedPoll); _context.SaveChanges(); var key = "RemovePollUserError"; var localizedString = new LocalizedString(key, key); _pollLocalizerMock.Setup(_ => _[key]).Returns(localizedString); var result = await _controller.RemovePoll(completedPoll.Id); var actionResult = Assert.IsType <BadRequestObjectResult>(result); var actionResultList = actionResult.Value as List <ErrorViewModel>; Assert.NotNull(actionResultList); Assert.Equal(key, actionResultList[0].Description); }
public async Task Should_Get_LatestPoll_ByType() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = false, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddDays(-2), QuestionBody = "PolicyChangePoll test" }; var poll2 = new PolicyChangePoll { Name = "test", Active = false, CreateTime = new DateTime(2018, 7, 3), Deadline = DateTime.UtcNow.AddDays(-1), QuestionBody = "test 123" }; _context.Add(poll); _context.Add(poll2); _context.SaveChanges(); var pollService = new PollService(_pollRepository, null, null, null, null, null, null); var getPoll = await pollService.GetLastPollOfType <PolicyChangePoll>(null); Assert.Equal(poll2.Id, getPoll.Id); }
public async Task Should_Return_Error_IfUserAddedAfterPollStarted() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow.AddHours(-1), Deadline = DateTime.UtcNow.AddDays(1), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); var model = new PolicyChangePollVoteViewModel { PollId = poll.Id, PollValue = 1 }; var key = "UserCannotVoteAfterAddedPollStart"; var localizedString = new LocalizedString(key, key); _policyChangeLocalizerMock.Setup(_ => _[key]).Returns(localizedString); var result = await _controller.Vote(model); var actionResult = Assert.IsType <BadRequestObjectResult>(result); var actionResultList = actionResult.Value as List <ErrorViewModel>; Assert.Equal(key, actionResultList[0].Description); }
public async Task Should_Return_Error_IfUserVotedInPoll() { _currentUser.UserDetail.AuthorityPercent = 30; var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow.AddHours(1), Deadline = DateTime.UtcNow.AddDays(1), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 1, VoterId = 1.ToString() }); _context.SaveChanges(); var model = new PolicyChangePollVoteViewModel { PollId = poll.Id, PollValue = 1 }; var key = "PollRecordExist"; var localizedString = new LocalizedString(key, key); _policyChangeLocalizerMock.Setup(_ => _[key]).Returns(localizedString); var result = await _controller.Vote(model); var actionResult = Assert.IsType <BadRequestObjectResult>(result); var actionResultList = actionResult.Value as List <ErrorViewModel>; Assert.Equal(key, actionResultList[0].Description); }
public async Task Should_Delete_PollAndVotes() { IAsyncRepository <Vote> voteRepository = new EfRepository <Vote>(_context); IVoteService voteService = new VoteService(voteRepository, null); var pollService = new PollService(_pollRepository, _settingService, null, null, voteService, null, null); var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 1, VoterId = 1.ToString() }); _context.SaveChanges(); await pollService.DeletePoll(poll.Id); var getPoll = _context.Polls.FirstOrDefault(x => x.Id == poll.Id); var getVotes = _context.Votes.Where(x => x.PollId == poll.Id); Assert.Null(getPoll); Assert.Equal(0, getVotes.Count()); }
public async Task Should_Get_CompletedPolls() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = false, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(-2), QuestionBody = "PolicyChangePoll test" }; var poll2 = new PolicyChangePoll { Name = "test", Active = true, CreateTime = new DateTime(2018, 7, 3), Deadline = DateTime.UtcNow.AddHours(25), QuestionBody = "test 123" }; _context.Polls.Add(poll); _context.Polls.Add(poll2); _context.SaveChanges(); var result = await _controller.GetCompletedPolls(); var actionResult = Assert.IsType <OkObjectResult>(result); var actionResultObj = actionResult.Value as IList <CompletedPollListViewModel>; Assert.NotNull(actionResultObj); Assert.Equal(1, actionResultObj.Count); }
public async Task Should_Get_TenantCompleted_PollCount() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = false, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(-2), QuestionBody = "PolicyChangePoll test", TenantId = "test2" }; var poll2 = new PolicyChangePoll { Name = "PolicyChangePoll test2", Active = false, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow, QuestionBody = "PolicyChangePoll test2" }; _context.Polls.Add(poll); _context.Polls.Add(poll2); _context.SaveChanges(); var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); var count = await pollService.GetCompletedPollCount(false, "test2"); Assert.Equal(1, count); }
private Tuple <Poll, Policy, Policy> SetupPolicyPoll(decimal authorityPercent) { _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 = authorityPercent, LanguagePreference = "tr" } }); var oldPolicy = new Policy { Title = "Old Policy", Body = "Old Body", UserId = 1.ToString(), CreatedAt = DateTime.UtcNow, PolicyStatus = PolicyStatus.Active, TenantId = "test" }; var newPolicy = new Policy { Title = "Policy", Body = "New Body", UserId = 1.ToString(), CreatedAt = DateTime.UtcNow, PolicyStatus = PolicyStatus.Voting, TenantId = "test" }; _context.Policies.Add(oldPolicy); _context.Policies.Add(newPolicy); _context.SaveChanges(); var poll = new PolicyChangePoll { Name = "test", Active = true, CreateTime = DateTime.UtcNow.AddHours(-12), PolicyId = newPolicy.Id, QuestionBody = "test dfs", TenantId = "test", Deadline = DateTime.UtcNow.AddHours(-1) }; _context.Polls.Add(poll); _context.SaveChanges(); return(new Tuple <Poll, Policy, Policy>(poll, oldPolicy, newPolicy)); }
public async Task Should_Check_User_Can_Vote() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); _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.Users.Add(new ApplicationUser { Email = "*****@*****.**", FirstName = "test", LastName = "Test", CreatedAt = new DateTime(2018, 5, 2), SecurityStamp = new Guid().ToString(), EmailConfirmed = false, Id = 2.ToString(), IsDeleted = false, UserDetail = new UserDetail { AuthorityPercent = 0, LanguagePreference = "tr" } }); _context.SaveChanges(); var userRepository = new EntityUserRepository(_context, null); var userService = new UserService(userRepository, null); var pollService = new PollService(_pollRepository, _settingService, userService, null, null, null, null); var user1Result = await pollService.UserCanVote(poll.Id, 1.ToString()); var user2Result = await pollService.UserCanVote(poll.Id, 2.ToString()); Assert.False(user1Result); Assert.True(user2Result); }
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); }
public async Task Should_Check_IfPollIsVoted() { IAsyncRepository <Vote> voteRepository = new EfRepository <Vote>(_context); IVoteService voteService = new VoteService(voteRepository, null); var pollService = new PollService(_pollRepository, _settingService, null, null, voteService, null, null); var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; var poll2 = new PolicyChangePoll { Name = "PolicyChangePoll test2", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(24), QuestionBody = "PolicyChangePoll test2" }; _context.Polls.Add(poll); _context.Polls.Add(poll2); _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(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 1, VoterId = 1.ToString() }); _context.SaveChanges(); var res1 = await pollService.IsVotedPoll(1.ToString(), poll); var res2 = await pollService.IsVotedPoll(1.ToString(), poll2); Assert.True(res1); Assert.False(res2); }
public async Task Should_Get_User_Not_Voted_Polls() { var userRepository = new EntityUserRepository(_context, null); var userService = new UserService(userRepository, null); var pollService = new PollService(_pollRepository, _settingService, userService, null, null, null, null); var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; var poll2 = new PolicyChangePoll { Name = "test", Active = true, CreateTime = new DateTime(2018, 7, 3), Deadline = DateTime.UtcNow.AddHours(VotingDuration), QuestionBody = "test 123" }; _context.Polls.Add(poll); _context.Polls.Add(poll2); _context.SaveChanges(); _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(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 1, VoterId = 1.ToString() }); _context.SaveChanges(); var result = await pollService.GetUserNotVotedPolls(1.ToString()); Assert.Equal(1, result.Count); }
public async Task <PolicyChangePoll> NewPolicyChangePoll(PolicyChangePollViewModel model) { var poll = new PolicyChangePoll { UserId = model.UserId, CreateTime = DateTime.UtcNow, Active = true, Name = model.Name, QuestionBody = model.Description, TenantId = _tenantProvider.GetTenantId(), PolicyId = model.PolicyId }; await _pollService.AddPoll(poll); return(poll); }
public async Task Should_Get_Poll() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = new DateTime(2018, 6, 2).AddDays(2), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); var pollService = new PollService(_pollRepository, null, null, null, null, null, null); var getPoll = await pollService.GetPoll(poll.Id, false); Assert.NotNull(getPoll); }
public async Task Should_DeleteVotesOfPoll() { var poll = new PolicyChangePoll { Name = "test", Active = true, CreateTime = DateTime.UtcNow, QuestionBody = "test dfs", TenantId = "test" }; _context.Polls.Add(poll); var userList = new List <ApplicationUser> { 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 = 20, LanguagePreference = "tr" } } }; _context.Users.AddRange(userList); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 1, VoterId = 1.ToString() }); _context.SaveChanges(); await _voteService.DeleteVote(poll.Id); var result = _context.Votes.Where(x => x.PollId == poll.Id); Assert.Equal(0, result.Count()); }
public async Task Should_Add_Vote() { var poll = new PolicyChangePoll { Name = "test", Active = true, CreateTime = DateTime.UtcNow, QuestionBody = "test dfs", TenantId = "test" }; _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(); var vote = new Vote { PollId = poll.Id, Value = 1, VoterId = 1.ToString() }; await _voteService.AddVote(vote); var getVote = _context.Votes.FirstOrDefault(x => x.Id == vote.Id); Assert.Equal(vote.PollId, getVote.PollId); Assert.Equal(vote.Value, getVote.Value); Assert.Equal(vote.VoterId, getVote.VoterId); }
public async Task Should_Set_PollResult() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); await pollService.SetPollResult(poll.Id, "test"); var getPoll = _context.Polls.FirstOrDefault(x => x.Id == poll.Id); Assert.Equal("test", getPoll?.Result); }
public async Task Should_Check_PollStatus_ByType() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = new DateTime(2018, 6, 2).AddDays(2), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); var checkPolicyChange = await pollService.HasActivePollOfType <PolicyChangePoll>(); var checkSalary = await pollService.HasActivePollOfType <SharePoll>(); Assert.True(checkPolicyChange); Assert.False(checkSalary); }
public async Task Should_End_Poll() { var pollService = new PollService(_pollRepository, _settingService, null, null, null, null, null); var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = new DateTime(2018, 6, 2), Deadline = DateTime.UtcNow.AddHours(VotingDuration + 24), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); await pollService.EndPoll(poll.Id); var getPoll = _context.Polls.FirstOrDefault(x => x.Id == poll.Id); Assert.NotNull(getPoll); Assert.False(getPoll.Active); Assert.True(DateTime.UtcNow > getPoll.Deadline); }
public async Task Should_Get_UserVotedPolls() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow.AddHours(1), Deadline = DateTime.UtcNow.AddDays(1), QuestionBody = "PolicyChangePoll test" }; var poll2 = new MultipleChoicePoll { Name = "test", OptionsJsonString = JsonConvert.SerializeObject(new List <string> { "a", "b", "c" }), Active = true, CreateTime = DateTime.UtcNow, Deadline = DateTime.UtcNow.AddDays(1) }; _context.Polls.Add(poll); _context.Polls.Add(poll2); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = poll2.Id, VoterId = _currentUser.Id, Value = -1 }); _context.SaveChanges(); var result = await _controller.GetUserNotVotedPolls(); var actionResult = Assert.IsType <OkObjectResult>(result); var actionResultObj = actionResult.Value as IList <UserNotVotedPollListViewModel>; Assert.NotNull(actionResultObj); Assert.Equal(poll.Id, actionResultObj[0].PollId); }
public async Task Should_Add_Poll() { var context = Helpers.GetContext("test"); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var poll = new PolicyChangePoll { Name = "test", Active = true, CreateTime = DateTime.UtcNow, Deadline = DateTime.UtcNow.AddDays(3), QuestionBody = "test dfs" }; var addedPoll = await pollRepository.AddPoll(poll); var polls = context.PolicyChangePolls; Assert.Equal(1, polls.Count()); Assert.Equal(poll.Id, addedPoll.Id); Assert.True(addedPoll.Active); Assert.Equal("test", addedPoll.TenantId); }
public async Task Should_Reset_Vote() { var poll = new PolicyChangePoll { Name = "PolicyChangePoll test", Active = true, CreateTime = DateTime.UtcNow.AddHours(1), Deadline = DateTime.UtcNow.AddDays(1), QuestionBody = "PolicyChangePoll test" }; _context.Polls.Add(poll); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = -1, VoterId = _currentUser.Id }); _context.SaveChanges(); var result = await _controller.ResetVote(poll.Id); Assert.IsType <OkObjectResult>(result); var votes = _context.Votes.Where(c => c.PollId == poll.Id); Assert.Equal(0, votes.Count()); }