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); GetSongForDeleteById query = new GetSongForDeleteById(); // Arrange GetSongForDeleteByIdQueryService sut = new GetSongForDeleteByIdQueryService( songRepository: songRepositoryStub.Object); // Act Song actualSong = await sut.ExecuteAsync(query); // Act && Assert Assert.AreEqual(expectedSong.Id, actualSong.Id); }
public void ThrowsNotFoundExceptionWhenSongDoesNotExists() { var songRepositoryStub = new Mock <IEfRepository <Song> >(); songRepositoryStub .Setup(x => x.GetByIdAsync(It.IsAny <string>())) .ReturnsAsync((Song)null); GetSongForDeleteById query = new GetSongForDeleteById(); // Arrange GetSongForDeleteByIdQueryService sut = new GetSongForDeleteByIdQueryService( songRepository: songRepositoryStub.Object); // Act && Assert Assert.ThrowsAsync <NotFoundException>(() => sut.ExecuteAsync(query)); }