Ejemplo n.º 1
0
        public async Task ReturnDtoWithCorrectSongFileWhenTheSongExists()
        {
            byte[] expectedSongFile = new byte[128];

            var songProviderStub = new Mock <ISongProvider>();

            songProviderStub
            .Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(() => expectedSongFile);

            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new Song()
            {
                IsApproved = true
            });

            GetSongForPlaying query = new GetSongForPlaying();

            // Arrange
            GetSongForPlayingQueryService sut = new GetSongForPlayingQueryService(
                songProvider: songProviderStub.Object,
                songRepository: songRepositoryStub.Object);

            // Act
            byte[] actualSongFile = (await sut.ExecuteAsync(query)).File;

            // Assert
            Assert.AreEqual(expectedSongFile, actualSongFile);
        }
Ejemplo n.º 2
0
        public async Task ReturnDtoWithCorrectSongExtensionWhenTheSongExists()
        {
            string expectedSongExtension = ".mp3";

            var songProviderStub   = new Mock <ISongProvider>();
            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(
                new Song()
            {
                IsApproved    = true,
                FileExtension = expectedSongExtension
            });

            GetSongForPlaying query = new GetSongForPlaying();

            // Arrange
            GetSongForPlayingQueryService sut = new GetSongForPlayingQueryService(
                songProvider: songProviderStub.Object,
                songRepository: songRepositoryStub.Object);

            // Act
            string actualSongExtension = (await sut.ExecuteAsync(query)).FileExtension;

            // Assert
            Assert.AreEqual(expectedSongExtension, actualSongExtension);
        }
Ejemplo n.º 3
0
        public async Task ReturnDtoWithCorrectSongWhenTheSongExists()
        {
            Song expectedSong = new Song()
            {
                Title      = "Unit Test",
                IsApproved = true
            };

            var songProviderStub = new Mock <ISongProvider>();

            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(expectedSong);

            GetSongForPlaying query = new GetSongForPlaying();

            // Arrange
            GetSongForPlayingQueryService sut = new GetSongForPlayingQueryService(
                songProvider: songProviderStub.Object,
                songRepository: songRepositoryStub.Object);

            // Act
            SongForPlayingDTO actualSongDTO = await sut.ExecuteAsync(query);

            // Assert
            StringAssert.Contains(expectedSong.Title, actualSongDTO.HeadingText);
        }
Ejemplo n.º 4
0
        public void ThrowsNotFoundExceptionWhenSongIsNotApprovedExists()
        {
            var songProviderStub   = new Mock <ISongProvider>();
            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            songRepositoryStub
            .Setup(x => x.GetByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new Song()
            {
                Id = "1", IsApproved = false
            });

            GetSongForPlaying query = new GetSongForPlaying()
            {
                SongId = "1"
            };

            // Arrange
            GetSongForPlayingQueryService sut = new GetSongForPlayingQueryService(
                songProvider: songProviderStub.Object,
                songRepository: songRepositoryStub.Object);

            // Act && Assert
            Assert.ThrowsAsync <NotFoundException>(() => sut.ExecuteAsync(query));
        }
Ejemplo n.º 5
0
        public async Task <SongForPlayingDTO> GetSongAsync(string songId)
        {
            IncrementSongListenings command = new IncrementSongListenings()
            {
                SongId = songId
            };

            await this.incrementSongListenings.ExecuteAsync(command);

            GetSongForPlaying query = new GetSongForPlaying()
            {
                SongId = songId
            };

            SongForPlayingDTO song = await this.getSong.ExecuteAsync(query);

            return(song);
        }