コード例 #1
0
        public async Task UpdateOrCreate_WithCurrentSong_DoesNotCreateNewCurrentSong()
        {
            // Arrange
            var songWithVoteCount = new SongWithVoteCount
            {
                Song = new Song {
                    DurationInSeconds = 120
                },
                VoteCount = 22
            };

            _currentSongRepository.GetOrDefaultAsync().Returns(Task.FromResult(new CurrentSong()));

            // Act
            var currentSong = await _currentSongService.UpdateOrCreateAsync(songWithVoteCount);

            // Assert
            Assert.That(currentSong.SongId, Is.EqualTo(songWithVoteCount.Song.Id));
            Assert.That(currentSong.Song, Is.EqualTo(songWithVoteCount.Song));
            Assert.That(currentSong.VoteCount, Is.EqualTo(songWithVoteCount.VoteCount));
            Assert.That(currentSong.EndsAtTime.UtcDateTime, Is.EqualTo(_clock.UtcNow.AddSeconds(115)));

            _currentSongRepository.Received(0).Create();
            _currentSongRepository.Received(0).Add(currentSong);
        }
コード例 #2
0
        public async Task CollectResultAndLock_LocksCurrentVotingCandidates()
        {
            // Arrange
            var winnerOfVoting = new SongWithVoteCount
            {
                Song = new Song()
            };

            var currentVotingCandidates = new[]
            {
                new VotingCandidate(),
                new VotingCandidate(),
                new VotingCandidate()
            };

            _votingCandidateRepository.GetWinnerOfVotingWithVoteCountOrDefaultAsync().Returns(winnerOfVoting);
            _votingCandidateRepository.Get().Returns(currentVotingCandidates);

            // Act
            await _votingFinisher.CollectResultAndLockAsync();

            // Assert
            Assert.That(currentVotingCandidates[0].IsActive, Is.False);
            Assert.That(currentVotingCandidates[1].IsActive, Is.False);
            Assert.That(currentVotingCandidates[2].IsActive, Is.False);
        }
コード例 #3
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);
        }
コード例 #4
0
 public void Map(SongWithVoteCount songWithVoteCount, IClock clock)
 {
     SongId     = songWithVoteCount.Song.Id;
     Song       = songWithVoteCount.Song;
     VoteCount  = songWithVoteCount.VoteCount;
     EndsAtTime = new DateTimeOffset(clock.UtcNow)
                  .AddSeconds(songWithVoteCount.Song.DurationInSeconds - Constants.App.CROSSFADE_DURATION_IN_SECONDS);
 }
コード例 #5
0
        public async Task <CurrentSong> UpdateOrCreateAsync(SongWithVoteCount song)
        {
            var currentSong = await _currentSongRepository.GetOrDefaultAsync();

            if (currentSong == null)
            {
                currentSong = _currentSongRepository.Create();
                _currentSongRepository.Add(currentSong);
            }

            currentSong.Map(song, _clock);

            return(currentSong);
        }
コード例 #6
0
        public void Map_MapsAllProperties()
        {
            // Arrange
            var currentSong       = new CurrentSong();
            var songWithVoteCount = new SongWithVoteCount
            {
                Song = new Song {
                    DurationInSeconds = 120
                },
                VoteCount = 22
            };

            // Act
            currentSong.Map(songWithVoteCount, _clock);

            // Assert
            Assert.That(currentSong.SongId, Is.EqualTo(songWithVoteCount.Song.Id));
            Assert.That(currentSong.Song, Is.EqualTo(songWithVoteCount.Song));
            Assert.That(currentSong.VoteCount, Is.EqualTo(songWithVoteCount.VoteCount));
            Assert.That(currentSong.EndsAtTime.UtcDateTime, Is.EqualTo(_clock.UtcNow.AddSeconds(115)));
        }
コード例 #7
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));
        }