Esempio n. 1
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()
            {
                FileExtension = expectedSongExtension
            });

            GetUnapprovedSongForPlaying query = new GetUnapprovedSongForPlaying();

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

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

            // Assert
            Assert.AreSame(expectedSongExtension, actualSongExtension);
        }
Esempio n. 2
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());

            GetUnapprovedSongForPlaying query = new GetUnapprovedSongForPlaying();

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

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

            // Assert
            Assert.AreSame(expectedSongFile, actualSongFile);
        }
Esempio n. 3
0
        public void ThrowsNotFoundExceptionWhenTheSongDoesNotExists()
        {
            var songProviderStub   = new Mock <ISongProvider>();
            var songRepositoryStub = new Mock <IEfRepository <Song> >();

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

            GetUnapprovedSongForPlaying query = new GetUnapprovedSongForPlaying();

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

            // Act && Assert
            Assert.ThrowsAsync <NotFoundException>(() => sut.ExecuteAsync(query));
        }
Esempio n. 4
0
        public void SavePassedSongRepositoryWhenIsNotNull()
        {
            var songRepositoryStub = new Mock <IEfRepository <Song> >();
            var songProviderStub   = new Mock <ISongProvider>();

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

            // Assert
            var actualSongProvider = sut.GetType()
                                     .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                     .First(fi => fi.FieldType == typeof(IEfRepository <Song>))
                                     .GetValue(sut);

            Assert.AreSame(songRepositoryStub.Object, actualSongProvider);
        }