Exemple #1
0
        public async Task ReturnsCorrectSongWhenTheSongExists()
        {
            Song expectedSong = new Song()
            {
                Id = "SongId"
            };

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

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

            GetSongForEditById query = new GetSongForEditById();

            // Arrange
            GetSongForEditByIdQueryService sut = new GetSongForEditByIdQueryService(
                songRepository: songRepositoryStub.Object);

            // Act
            Song actualSong = await sut.ExecuteAsync(query);

            // Act && Assert
            Assert.AreEqual(expectedSong.Id, actualSong.Id);
        }
Exemple #2
0
        public void ThrowsNotFoundExceptionWhenSongDoesNotExists()
        {
            var songRepositoryStub = new Mock <IEfRepository <Song> >();

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

            GetSongForEditById query = new GetSongForEditById();

            // Arrange
            GetSongForEditByIdQueryService sut = new GetSongForEditByIdQueryService(
                songRepository: songRepositoryStub.Object);

            // Act && Assert
            Assert.ThrowsAsync <NotFoundException>(() => sut.ExecuteAsync(query));
        }
Exemple #3
0
        public void SavePassedSongRepositoryWhenIsNotNull()
        {
            var songRepositoryStub = new Mock <IEfRepository <Song> >();

            // Arrange && Act
            GetSongForEditByIdQueryService sut =
                new GetSongForEditByIdQueryService(
                    songRepository: songRepositoryStub.Object);

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

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