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 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); }