Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }