示例#1
0
        public async Task ApplyResult_WithVotingCandidates_AppliesWinnerCandidate()
        {
            // Arrange
            var songId          = Guid.NewGuid();
            var votingCandidate = new SongWithVoteCount
            {
                Song = new Song {
                    Id = songId
                },
                VoteCount = 3
            };

            var currentSong = new CurrentSong
            {
                Song      = votingCandidate.Song,
                VoteCount = votingCandidate.VoteCount
            };

            _votingCandidateRepository.GetWithVoteCountBySongOrDefaultAsync(songId).Returns(Task.FromResult(votingCandidate));
            _currentSongService.UpdateOrCreateAsync(Arg.Any <SongWithVoteCount>()).Returns(Task.FromResult(currentSong));

            // Act
            await _votingFinisher.ApplyResultAsync(songId);

            // Assert
            await _currentSongService.Received(1).UpdateOrCreateAsync(votingCandidate);
        }
        public async Task ApplyResultAsync(Guid votingResultSongId)
        {
            var votingCandidateToApply = await _votingCandidateRepository.GetWithVoteCountBySongOrDefaultAsync(votingResultSongId);

            if (votingCandidateToApply == null)
            {
                // If there are no voting candidates yet, we have to construct a new song with default vote count
                var song = await _songRepository.GetByIdAsync(votingResultSongId);

                votingCandidateToApply = SongWithDefaultVoteCount(song);
            }

            var newVotingCandidateSongs = await _songRepository.GetRandomAsync(take : Constants.App.NUMBER_OF_VOTING_CANDIDATES);

            var currentSong = await _currentSongService.UpdateOrCreateAsync(votingCandidateToApply);

            await _votingCandidateService.UpdateOrCreateAsync(newVotingCandidateSongs);

            _logger.LogInformation("Changing current song to {0}. Estimated end is {1}", currentSong.Song.FileName, currentSong.EndsAtTime.ToString());
        }