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); }
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)); }
public async Task <IActionResult> Edit(string id) { Song song = null; GetSongForEditById query = new GetSongForEditById() { SongId = id }; string message = await this.CallServiceAsync( async() => song = await this.getSongForEdit.ExecuteAsync(query)); if (message != null) { return(View() .WithErrorMessage(message)); } SongFormModel model = Mapper.Map <SongFormModel>(song); return(View(model)); }