public async void CreateInGenreRelationship_Test() { // Arrange var newBook = CreateBook(); await _bookRepository.AddOrUpdateAsync(newBook); var newGenre = CreateGenre(); await _genreRepository.AddOrUpdateGenreAsync(newGenre); var inGenre = new Relationships.InGenre(); // Act await _genreRepository.CreateInGenreRelationshipAsync(newGenre, newBook, inGenre); var returnedBook = (await _genreRepository.GetInGenreBookRelationshipAsync(newGenre, inGenre)) .ToList().FirstOrDefault(); // Assert Assert.True(newBook.Title == returnedBook.Title); // Clean up await _genreRepository.DeleteInGenreRelationshipAsync(newGenre, newBook, inGenre); await _bookRepository.DeleteBookAsync(newBook); await _genreRepository.DeleteGenreAsync(newGenre); }
public async Task <IActionResult> AddUpdateBookAsync(Book book) { await _bookRepository.AddOrUpdateAsync(book); foreach (var genre in book.Genres) { await _genreRepository.CreateInGenreRelationshipAsync(genre, book, new Relationships.InGenre()); } return(Ok()); }