public async Task Should_Get_User_VotedPolls() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); 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 = 1, Value = 1, VoterId = 1.ToString() }); context.SaveChanges(); var votedPolls = await pollRepository.GetUserVotedPolls(1.ToString()); Assert.Equal(1, votedPolls.Count); Assert.Contains(votedPolls, x => x.Id == 1); }
public PollJobServiceTests() { _context = Helpers.GetContext("test"); _tenantsDbContext = Helpers.GetTenantContext(); IPollRepository pollRepository = new EntityPollRepository(_context, _tenantsDbContext); IUserRepository userRepository = new EntityUserRepository(_context, null); IUserService userService = new UserService(userRepository, null); IAsyncRepository <Vote> voteRepository = new EfRepository <Vote>(_context); var voteService = new VoteService(voteRepository, userService); ITenantRepository tenantRepository = new EntityTenantRepository(_tenantsDbContext); IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context); ISettingService settingService = new SettingService(settingRepository); ITenantService tenantService = new TenantService(tenantRepository, settingService, null); var policyService = new PolicyService(new EfRepository <Policy>(_context)); var emailSenderMock = new Mock <IEmailSender>(); emailSenderMock.Setup(serv => serv.SendEmailAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); var genericServiceMock = new Mock <IGenericService>(); genericServiceMock.Setup(serv => serv.GetBaseUrl(It.IsAny <string>())) .Returns(Task.FromResult("decidehub.com")); IPollService pollService = new PollService(pollRepository, settingService, userService, tenantService, voteService, emailSenderMock.Object, genericServiceMock.Object); _pollJobService = new PollJobService(pollService, userService, voteService, settingService, pollRepository, tenantService, policyService); }
public async Task Should_Get_Poll_Since_Inclusive() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var polls = await pollRepository.GetPollsSince(new DateTime(2018, 7, 4), null); Assert.Equal(3, polls.Count); }
public async Task Should_Get_Poll() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var poll = await pollRepository.GetPoll(1); Assert.NotNull(poll); }
public async Task Should_Get_CompletedPolls_SpecifiedCount() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var completedPolls = await pollRepository.GetCompletedPolls(2); Assert.Equal(2, completedPolls.Count()); }
public async Task Should_Get_TenantCompleted_Poll_Count() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var count = await pollRepository.GetCompletedPollCount(tenantId : "test2"); Assert.Equal(1, count); }
public async Task Should_Get_AllActivePolls() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var activePolls = await pollRepository.GetActivePolls(true, null); Assert.Equal(3, activePolls.Count); }
public async Task Should_Get_ActivePoll_Count() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var count = await pollRepository.GetActivePollCount(); Assert.Equal(2, count); }
public async Task Should_Get_TenantPollCount_ByType() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var count = await pollRepository.GetPollCountByType <SharePoll>("test2"); Assert.Equal(1, count); }
public PollServiceTests() { _context = Helpers.GetContext("test"); IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context); var tenantsContext = Helpers.GetTenantContext(); _pollRepository = new EntityPollRepository(_context, tenantsContext); _settingService = new SettingService(settingRepository); }
public async Task Should_Get_DifferentTenant_ActivePolls() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var activePolls = await pollRepository.GetActivePolls(true, "test2"); Assert.Equal(1, activePolls.Count); Assert.Equal("test2", activePolls[0].TenantId); }
public async Task Should_Get_Poll_TenantIndependent() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var poll = await pollRepository.GetPoll(5, true); Assert.NotNull(poll); Assert.NotEqual("test", poll.TenantId); }
public async Task Should_Get_LatestVote_ByType() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var latestPoll = await pollRepository.GetLastPollOfType <PolicyChangePoll>(null); Assert.NotNull(latestPoll); Assert.Equal("test2", latestPoll.Name); }
public ApiPollControllerTests() { _context = Helpers.GetContext("test"); _currentUser = new ApplicationUser { Email = "*****@*****.**", FirstName = "test", LastName = "Test", CreatedAt = DateTime.UtcNow, SecurityStamp = new Guid().ToString(), EmailConfirmed = true, Id = 1.ToString(), IsDeleted = false, UserDetail = new UserDetail { AuthorityPercent = 30, LanguagePreference = "tr" } }; _context.Users.Add(_currentUser); _context.SaveChanges(); var tenantsDbContext = Helpers.GetTenantContext(); IPollRepository pollRepository = new EntityPollRepository(_context, tenantsDbContext); IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context); ISettingService settingService = new SettingService(settingRepository); IUserRepository userRepository = new EntityUserRepository(_context, null); IUserService userService = new UserService(userRepository, null); ITenantRepository tenantRepository = new EntityTenantRepository(tenantsDbContext); IAsyncRepository <Vote> voteRepository = new EfRepository <Vote>(_context); var voteService = new VoteService(voteRepository, userService); ITenantService tenantService = new TenantService(tenantRepository, settingService, null); IPollService pollService = new PollService(pollRepository, settingService, userService, tenantService, voteService, null, null); var mapper = Helpers.GetMapper(); var tenantProviderMock = new Mock <ITenantProvider>(); tenantProviderMock.Setup(serv => serv.GetTenantId()).Returns("test"); _pollLocalizerMock = new Mock <IStringLocalizer <ApiPollController> >(); IPollApiViewModelService pollApiViewModelService = new PollApiViewModelService(tenantProviderMock.Object, pollService, mapper, voteService, userService, settingService); var genericServiceMock = new Mock <IGenericService>(); genericServiceMock.Setup(serv => serv.GetBaseUrl(null)).Returns(Task.FromResult("decidehub.com")); _controller = new ApiPollController(pollService, mapper, userService, pollApiViewModelService, _pollLocalizerMock.Object, voteService, genericServiceMock.Object, tenantProviderMock.Object); var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.PrimarySid, "1") })); _controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } }; }
public async Task Should_Set_PollResult() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); await pollRepository.SetPollResult(1, "test"); var poll = context.Polls.FirstOrDefault(x => x.Id == 1); Assert.Equal("test", poll.Result); }
public async Task Should_Delete_Poll() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); await pollRepository.DeletePoll(1); var poll = context.Polls.FirstOrDefault(x => x.Id == 1); Assert.Null(poll); }
public async Task Should_Check_Active_Poll() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var hasActivePolicyChangePoll = await pollRepository.HasActivePollOfType <PolicyChangePoll>(); var hasActiveSharePoll = await pollRepository.HasActivePollOfType <SharePoll>(); Assert.True(hasActivePolicyChangePoll); Assert.False(hasActiveSharePoll); }
public async Task Should_End_Poll() { var context = GetContextAndPollTestData(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); await pollRepository.EndPoll(1); var poll = context.Polls.FirstOrDefault(x => x.Id == 1); Assert.False(poll.Active); Assert.True(DateTime.UtcNow > poll.Deadline); }
public async Task Should_Get_AllPublic_Polls() { var context = Helpers.GetContext("test"); var pollList = new List <Poll> { new PolicyChangePoll { Id = 1, Name = "test", Active = true, CreateTime = new DateTime(2018, 7, 3), Deadline = DateTime.UtcNow.AddDays(2), QuestionBody = "test 123" }, new PolicyChangePoll { Id = 2, Name = "test2", Active = false, CreateTime = new DateTime(2018, 7, 2), Deadline = new DateTime(2018, 7, 2).AddDays(2), QuestionBody = "test 1234" }, new PolicyChangePoll { Id = 3, Name = "test3", Active = false, CreateTime = new DateTime(2018, 7, 1), Deadline = new DateTime(2018, 7, 1).AddDays(2), QuestionBody = "test 12345", TenantId = "test2" } }; context.Polls.AddRange(pollList); context.SaveChanges(); var tenantsContext = Helpers.GetTenantContext(); var pollRepository = new EntityPollRepository(context, tenantsContext); var publicPolls = await pollRepository.GetPublicPolls(); Assert.Equal(3, publicPolls.Count); }
public PollApiViewModelServiceTests() { var tenantProviderMock = new Mock <ITenantProvider>(); tenantProviderMock.Setup(serv => serv.GetTenantId()).Returns("test"); _context = Helpers.GetContext("test"); var tenantsDbContext = Helpers.GetTenantContext(); ITenantRepository tenantRepository = new EntityTenantRepository(tenantsDbContext); IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context); IPollRepository pollRepository = new EntityPollRepository(_context, tenantsDbContext); ISettingService settingService = new SettingService(settingRepository); ITenantService tenantService = new TenantService(tenantRepository, settingService, null); IUserRepository userRepository = new EntityUserRepository(_context, null); IUserService userService = new UserService(userRepository, null); IAsyncRepository <Vote> voteRepository = new EfRepository <Vote>(_context); var voteService = new VoteService(voteRepository, userService); IPollService pollService = new PollService(pollRepository, settingService, userService, tenantService, voteService, null, null); var mapper = Helpers.GetMapper(); _pollApiViewModelService = new PollApiViewModelService(tenantProviderMock.Object, pollService, mapper, voteService, userService, settingService); }
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); }