예제 #1
0
        public async Task UpdateOrCreate_WithNoCurrentSong_CreatesNewCurrentSong()
        {
            // Arrange
            var songWithVoteCount = new SongWithVoteCount
            {
                Song = new Song {
                    DurationInSeconds = 120
                },
                VoteCount = 22
            };

            _currentSongRepository.GetOrDefaultAsync().Returns(Task.FromResult(default(CurrentSong)));
            _currentSongRepository.Create().Returns(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(1).Create();
            _currentSongRepository.Received(1).Add(currentSong);
        }
        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);
        }
예제 #3
0
        public async Task <CurrentSongDto> GetCurrentSongAsync()
        {
            var currentSong = await _currentSongRepository.GetOrDefaultAsync();

            return(_mapper.Map <CurrentSongDto>(currentSong));
        }