Exemple #1
0
        public async void AddWishListAsync_Test()
        {
            // Arrange
            var person   = CreatePerson();
            var book     = CreateBook();
            var wishList = new Relationships.WishList();

            await _personRepository.AddPersonAsync(person);

            await _bookRepository.AddOrUpdateAsync(book);

            await _bookRepository.CreateWishlistRelationshipAsync(book, person, wishList);

            // Act
            var wishListBooks = await _personRepository.GetWishListRelationshipAsync(person, wishList);

            // Assert
            Assert.True(wishListBooks.Where(b => b.Id == book.Id).ToList().Count == 1);
            Assert.True(wishListBooks.ToList().Count == 1);

            // Clean up
            await _bookRepository.DeleteWishListRelationshipAsync(book, person, wishList);

            await _personRepository.DeletePersonAsync(person);

            await _bookRepository.DeleteBookAsync(book);
        }
        public async void JaccardLibraryRecommendation_Test()
        {
            //Arrange
            var newPerson = CreatePerson();
            await _personRepository.AddPersonAsync(newPerson);

            var newPerson2 = CreatePerson();
            await _personRepository.AddPersonAsync(newPerson2);

            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, newPerson2, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook2, newPerson2, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook3, newPerson2, inLibrary);

            await _bookRepository.CreateInLibraryRelationshipAsync(newBook, newPerson, inLibrary);

            var wishList = new Relationships.WishList();

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

            //Act
            var returnedBook = (await _recommendationRepository.GetJaccardLibrary(p => p.Name == newPerson.Name));

            //Assert
            Assert.NotNull(returnedBook);
            //Cleanup
            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook, newPerson2, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook2, newPerson2, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook3, newPerson2, inLibrary);

            await _bookRepository.DeleteInLibraryRelationshipAsync(newBook, newPerson, inLibrary);

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

            await _bookRepository.DeleteBookAsync(newBook);

            await _bookRepository.DeleteBookAsync(newBook2);

            await _bookRepository.DeleteBookAsync(newBook3);

            await _personRepository.DeletePersonAsync(newPerson);

            await _personRepository.DeletePersonAsync(newPerson2);
        }
Exemple #3
0
        public async void RemoveWishListAsync_Test()
        {
            var person      = CreatePerson();
            var booktostay1 = CreateBook();
            var booktostay2 = CreateBook();
            var booktogo    = CreateBook();

            await _personRepository.AddPersonAsync(person);

            await _bookRepository.AddOrUpdateAsync(booktostay1);

            await _bookRepository.AddOrUpdateAsync(booktostay2);

            await _bookRepository.AddOrUpdateAsync(booktogo);

            var wishList = new Relationships.WishList();

            await _bookRepository.CreateWishlistRelationshipAsync(booktostay1, person, wishList);

            await _bookRepository.CreateWishlistRelationshipAsync(booktostay2, person, wishList);

            await _bookRepository.CreateWishlistRelationshipAsync(booktogo, person, wishList);

            // Act
            var allBooksInList = await _personRepository.GetWishListRelationshipAsync(person, wishList);

            await _bookRepository.DeleteWishListRelationshipAsync(booktogo, person, wishList);

            var twoBooksInList = await _personRepository.GetWishListRelationshipAsync(person, wishList);

            // Assert
            Assert.True(allBooksInList.Where(b => b.Id == booktostay1.Id).ToList().Count == 1);
            Assert.True(allBooksInList.Where(b => b.Id == booktostay2.Id).ToList().Count == 1);
            Assert.True(allBooksInList.Where(b => b.Id == booktogo.Id).ToList().Count == 1);
            Assert.True(allBooksInList.ToList().Count == 3);

            Assert.True(twoBooksInList.Where(b => b.Id == booktostay1.Id).ToList().Count == 1);
            Assert.True(twoBooksInList.Where(b => b.Id == booktostay2.Id).ToList().Count == 1);
            Assert.True(twoBooksInList.Where(b => b.Id == booktogo.Id).ToList().Count == 0);
            Assert.True(twoBooksInList.ToList().Count == 2);

            // CleanUp
            await _bookRepository.DeleteWishListRelationshipAsync(booktostay1, person, wishList);

            await _bookRepository.DeleteWishListRelationshipAsync(booktostay2, person, wishList);

            await _personRepository.DeletePersonAsync(person);

            await _bookRepository.DeleteBookAsync(booktostay1);

            await _bookRepository.DeleteBookAsync(booktostay2);

            await _bookRepository.DeleteBookAsync(booktogo);
        }
        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);
        }