示例#1
0
        public async Task CollectResultAndLock_WithWinnerOfVoting_ReturnsWinnerOfVoting()
        {
            // Arrange
            var winnerOfVoting = new SongWithVoteCount
            {
                Song = new Song {
                    Id = Guid.NewGuid()
                },
                VoteCount = 22
            };

            _votingCandidateRepository.GetWinnerOfVotingWithVoteCountOrDefaultAsync().Returns(Task.FromResult(winnerOfVoting));

            // Act
            var result = await _votingFinisher.CollectResultAndLockAsync();

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.SameAs(winnerOfVoting));
            Assert.That(result.Song.Id, Is.EqualTo(winnerOfVoting.Song.Id));
            Assert.That(result.VoteCount, Is.EqualTo(winnerOfVoting.VoteCount));
        }
        public async Task <SongWithVoteCount> CollectResultAndLockAsync()
        {
            var votingResult = await _votingCandidateRepository.GetWinnerOfVotingWithVoteCountOrDefaultAsync();

            if (votingResult == null)
            {
                // If there are no voting candidates yet, we have to choose a random song.
                var randomSong = await _songRepository.GetRandomAsync(take : 1);

                votingResult = SongWithDefaultVoteCount(randomSong.First());
            }

            var currentVotingCandidates = _votingCandidateRepository.Get();

            foreach (var votingCandidate in currentVotingCandidates)
            {
                votingCandidate.IsActive = false;
            }

            _logger.LogInformation("The winner is {0}. Voting is locked now.", votingResult.Song.FileName);

            return(votingResult);
        }