protected override async Task RunAsync() { await _pollJobService.CheckPollCompletion(); }
public async Task Should_Calculate_AuthorityPercents() { var tenant = new Tenant { Id = "test", HostName = "test.decidehub.com", InActive = false, Lang = "tr" }; _tenantsDbContext.Tenants.Add(tenant); _tenantsDbContext.SaveChanges(); var poll = new AuthorityPoll { Name = "test", Active = true, CreateTime = DateTime.UtcNow.AddHours(-12), QuestionBody = "test dfs", TenantId = "test", Deadline = DateTime.UtcNow.AddHours(-1) }; _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 = 0, InitialAuthorityPercent = 5, LanguagePreference = "tr" } }); _context.Users.Add(new ApplicationUser { Email = "*****@*****.**", FirstName = "test2", LastName = "test2", TenantId = "test", CreatedAt = DateTime.UtcNow, SecurityStamp = new Guid().ToString(), EmailConfirmed = true, Id = 2.ToString(), IsDeleted = false, UserDetail = new UserDetail { AuthorityPercent = 0, InitialAuthorityPercent = 3, LanguagePreference = "tr" } }); _context.Users.Add(new ApplicationUser { Email = "*****@*****.**", FirstName = "test3", LastName = "test3", TenantId = "test", CreatedAt = DateTime.UtcNow, SecurityStamp = new Guid().ToString(), EmailConfirmed = true, Id = 3.ToString(), IsDeleted = false, UserDetail = new UserDetail { AuthorityPercent = 0, InitialAuthorityPercent = 10, LanguagePreference = "tr" } }); _context.SaveChanges(); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 500, VoterId = 1.ToString(), VotedUserId = "2" }); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 500, VoterId = 1.ToString(), VotedUserId = "3" }); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 500, VoterId = 2.ToString(), VotedUserId = 1.ToString() }); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 500, VoterId = 2.ToString(), VotedUserId = 3.ToString() }); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 500, VoterId = 3.ToString(), VotedUserId = 1.ToString() }); _context.Votes.Add(new Vote { PollId = poll.Id, Value = 500, VoterId = 3.ToString(), VotedUserId = 2.ToString() }); _context.SaveChanges(); await _pollJobService.CheckPollCompletion(); var user1 = _context.UserDetails.First(u => u.UserId == "1").AuthorityPercent; var user2 = _context.UserDetails.First(u => u.UserId == "2").AuthorityPercent; var user3 = _context.UserDetails.First(u => u.UserId == "3").AuthorityPercent; Assert.Equal(34.0M, Math.Round(user1, 1)); Assert.Equal(35.4M, Math.Round(user2, 1)); Assert.Equal(30.6M, Math.Round(user3, 1)); }