Ejemplo n.º 1
0
        public async Task <IActionResult> AddBooksToWishList(string userName, Book book)
        {
            await _bookRepository.AddOrUpdateAsync(book);

            foreach (var genre in book.Genres)
            {
                await _genreRepository.CreateInGenreRelationshipAsync(genre, book, new Relationships.InGenre());
            }

            await _bookRepository.CreateWishlistRelationshipAsync(book, new Person()
            {
                Name = userName
            }, new WishList());

            return(Ok());
        }
        public async void PopularWishList_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 wishList = new Relationships.WishList();

            await _bookRepository.CreateWishlistRelationshipAsync(newBook, newPerson, wishList);

            await _bookRepository.CreateWishlistRelationshipAsync(newBook2, newPerson, wishList);

            await _bookRepository.CreateWishlistRelationshipAsync(newBook3, newPerson, wishList);

            await _bookRepository.CreateWishlistRelationshipAsync(newBook2, newPerson2, wishList);

            await _bookRepository.CreateWishlistRelationshipAsync(newBook3, newPerson2, wishList);

            await _bookRepository.CreateWishlistRelationshipAsync(newBook3, newPerson3, wishList);

            //Act
            var query = (await _recommendationRepository.PopularWishLists());

            //Assert
            Assert.NotNull(query);
            //Cleanup
            await _bookRepository.DeleteWishListRelationshipAsync(newBook, newPerson, wishList);

            await _bookRepository.DeleteWishListRelationshipAsync(newBook2, newPerson, wishList);

            await _bookRepository.DeleteWishListRelationshipAsync(newBook3, newPerson, wishList);

            await _bookRepository.DeleteWishListRelationshipAsync(newBook2, newPerson2, wishList);

            await _bookRepository.DeleteWishListRelationshipAsync(newBook3, newPerson2, wishList);

            await _bookRepository.DeleteWishListRelationshipAsync(newBook3, newPerson3, wishList);

            await _bookRepository.DeleteBookAsync(newBook);

            await _bookRepository.DeleteBookAsync(newBook2);

            await _bookRepository.DeleteBookAsync(newBook3);

            await _personRepository.DeletePersonAsync(newPerson);

            await _personRepository.DeletePersonAsync(newPerson2);

            await _personRepository.DeletePersonAsync(newPerson3);
        }