public async Task Vote(VoteType type, RequestType request) { VoteSettings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new VoteSettings { Enabled = true, MovieVoteMax = 10 }); var votes = F.CreateMany <Votes>().ToList(); VoteRepository.Setup(x => x.GetAll()).Returns(new EnumerableQuery <Votes>(votes) .AsQueryable() .BuildMock().Object); var result = new VoteEngineResult(); if (type == VoteType.Downvote) { result = await Engine.DownVote(1, request); } else { result = await Engine.UpVote(1, request); } Assert.That(result.Result, Is.True); VoteRepository.Verify(x => x.Add(It.Is <Votes>(c => c.UserId == "abc" && c.VoteType == type)), Times.Once); VoteRepository.Verify(x => x.Delete(It.IsAny <Votes>()), Times.Never); MovieRequestEngine.Verify(x => x.ApproveMovieById(1), Times.Never); }
public async Task Voting_Disabled(RequestType type) { VoteSettings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new VoteSettings { Enabled = false, MovieVoteMax = 10 }); var result = await Engine.UpVote(1, type); Assert.That(result.Result, Is.True); VoteRepository.Verify(x => x.Add(It.IsAny <Votes>()), Times.Never); }
/// <summary> /// Initializes a new instance of the <see cref="Settings"/> class. /// </summary> public InstanceSettings(GlobalSettings globalSettings) { Global = globalSettings; Away = new AwaySettings(); BadNickname = new BadNicknameSettings(); Control = new ControlSettings(); Event = new EventSettings(); Idle = new IdleSettings(); Message = new MessageSettings(); Record = new RecordSettings(); Sticky = new StickySettings(); TeamSpeak = new TeamSpeakServerSettings(); Vote = new VoteSettings(); }
/// <summary> /// Initializes a new instance of the <see cref="Settings"/> class. /// </summary> public InstanceSettings(GlobalSettings globalSettings) { Global = globalSettings; Away = new AwaySettings(); BadNickname = new BadNicknameSettings(); Control = new ControlSettings(); Event = new EventSettings(); Idle = new IdleSettings(); Message = new MessageSettings(); Record = new RecordSettings(); Sticky = new StickySettings(); TeamSpeak = new TeamSpeakServerSettings(); Vote = new VoteSettings(); }
public async Task New_Upvote() { VoteSettings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new VoteSettings()); var votes = F.CreateMany <Votes>().ToList(); votes.Add(new Votes { RequestId = 1, RequestType = RequestType.Movie, UserId = "abc" }); VoteRepository.Setup(x => x.GetAll()).Returns(new EnumerableQuery <Votes>(votes)); var result = await Engine.UpVote(1, RequestType.Movie); Assert.That(result.Result, Is.True); VoteRepository.Verify(x => x.Add(It.Is <Votes>(c => c.UserId == "abc" && c.VoteType == VoteType.Upvote)), Times.Once); VoteRepository.Verify(x => x.Delete(It.IsAny <Votes>()), Times.Once); MovieRequestEngine.Verify(x => x.ApproveMovieById(1), Times.Never); }
public async Task <IWriterResult <bool> > AdminUpdateVoteSettings(string userId, UpdateVoteSettingsModel model) { using (var context = DataContextFactory.CreateContext()) { var votesettings = await context.VoteSetting.FirstOrDefaultNoLockAsync(); if (votesettings == null) { votesettings = new VoteSettings(); context.VoteSetting.Add(votesettings); await context.SaveChangesAsync(); } votesettings.Next = model.Next; votesettings.IsPaidEnabled = model.IsPaidEnabled; votesettings.IsFreeEnabled = model.IsFreeEnabled; votesettings.CurrencyId = model.CurrencyId; var contextResults = await context.SaveChangesWithLoggingAsync(); return(WriterResult <bool> .ContextResult(contextResults)); } }
public async Task <bool> VoteSettings([FromBody] VoteSettings settings) { return(await Save(settings)); }