public async void CreateInLibraryRelationship_Test() { // Arrange var newBook = CreateBook(); await _bookRepository.AddOrUpdateAsync(newBook); var newPerson = CreatePerson(); await _personRepository.AddPersonAsync(newPerson); var inLibrary = new Relationships.InLibrary(); // Act await _bookRepository.CreateInLibraryRelationshipAsync(newBook, newPerson, inLibrary); var returnedPerson = (await _bookRepository.GetInLibraryPersonRelationshipAsync(newBook, inLibrary)) .ToList().FirstOrDefault(); // Assert Assert.True(newPerson.Name == returnedPerson.Name); // Clean up await _bookRepository.DeleteInLibraryRelationshipAsync(newBook, newPerson, inLibrary); await _bookRepository.DeleteBookAsync(newBook); await _personRepository.DeletePersonAsync(newPerson); }
public async Task <IActionResult> AddBookToLibrary(string userName, Book book) { await _bookRepository.AddOrUpdateAsync(book); foreach (var genre in book.Genres) { await _genreRepository.CreateInGenreRelationshipAsync(genre, book, new Relationships.InGenre()); } await _bookRepository.CreateInLibraryRelationshipAsync(book, new Person() { Name = userName }, new InLibrary()); return(Ok()); }
public async void PopularLibrary_Test() { //Arrange var newPerson = CreatePerson(); await _personRepository.AddPersonAsync(newPerson); var newPerson2 = CreatePerson(); await _personRepository.AddPersonAsync(newPerson2); var newPerson3 = CreatePerson(); await _personRepository.AddPersonAsync(newPerson3); var newBook = CreateBook(); await _bookRepository.AddOrUpdateAsync(newBook); var newBook2 = CreateBook(); await _bookRepository.AddOrUpdateAsync(newBook2); var newBook3 = CreateBook(); await _bookRepository.AddOrUpdateAsync(newBook3); var inLibrary = new Relationships.InLibrary(); await _bookRepository.CreateInLibraryRelationshipAsync(newBook, newPerson, inLibrary); await _bookRepository.CreateInLibraryRelationshipAsync(newBook2, newPerson, inLibrary); await _bookRepository.CreateInLibraryRelationshipAsync(newBook3, newPerson, inLibrary); await _bookRepository.CreateInLibraryRelationshipAsync(newBook2, newPerson2, inLibrary); await _bookRepository.CreateInLibraryRelationshipAsync(newBook3, newPerson2, inLibrary); await _bookRepository.CreateInLibraryRelationshipAsync(newBook3, newPerson3, inLibrary); //Act var query = (await _recommendationRepository.PopularLibrarys()); //Assert Assert.NotNull(query); //Cleanup await _bookRepository.DeleteInLibraryRelationshipAsync(newBook, newPerson, inLibrary); await _bookRepository.DeleteInLibraryRelationshipAsync(newBook2, newPerson, inLibrary); await _bookRepository.DeleteInLibraryRelationshipAsync(newBook3, newPerson, inLibrary); await _bookRepository.DeleteInLibraryRelationshipAsync(newBook2, newPerson2, inLibrary); await _bookRepository.DeleteInLibraryRelationshipAsync(newBook3, newPerson2, inLibrary); await _bookRepository.DeleteInLibraryRelationshipAsync(newBook3, newPerson3, inLibrary); await _bookRepository.DeleteBookAsync(newBook); await _bookRepository.DeleteBookAsync(newBook2); await _bookRepository.DeleteBookAsync(newBook3); await _personRepository.DeletePersonAsync(newPerson); await _personRepository.DeletePersonAsync(newPerson2); await _personRepository.DeletePersonAsync(newPerson3); }