コード例 #1
0
        public async void GetInGenreBooksAsync_Test()
        {
            // Arrange
            var genre   = CreateGenre();
            var book    = CreateBook();
            var inGenre = new Relationships.InGenre();

            await _genreRepository.AddOrUpdateGenreAsync(genre);

            await _bookRepository.AddOrUpdateAsync(book);

            await _genreRepository.CreateInGenreRelationshipAsync(genre, book, inGenre);

            // Act
            var genreBooks = await _genreRepository.GetInGenreBookRelationshipAsync(genre, inGenre);

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

            // Clean up
            await _genreRepository.DeleteInGenreRelationshipAsync(genre, book, inGenre);

            await _genreRepository.DeleteGenreAsync(genre);

            await _bookRepository.DeleteBookAsync(book);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public async void RemoveInGenreAsync_Test()
        {
            var genre       = CreateGenre();
            var booktostay1 = CreateBook();
            var booktostay2 = CreateBook();
            var booktogo    = CreateBook();

            await _genreRepository.AddOrUpdateGenreAsync(genre);

            await _bookRepository.AddOrUpdateAsync(booktostay1);

            await _bookRepository.AddOrUpdateAsync(booktostay2);

            await _bookRepository.AddOrUpdateAsync(booktogo);

            var inGenre = new Relationships.InGenre();

            await _genreRepository.CreateInGenreRelationshipAsync(genre, booktostay1, inGenre);

            await _genreRepository.CreateInGenreRelationshipAsync(genre, booktostay2, inGenre);

            await _genreRepository.CreateInGenreRelationshipAsync(genre, booktogo, inGenre);

            // Act
            var allBooksInList = await _genreRepository.GetInGenreBookRelationshipAsync(genre, inGenre);

            await _genreRepository.DeleteInGenreRelationshipAsync(genre, booktogo, inGenre);

            var twoBooksInList = await _genreRepository.GetInGenreBookRelationshipAsync(genre, inGenre);

            // 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 _genreRepository.DeleteInGenreRelationshipAsync(genre, booktostay1, inGenre);

            await _genreRepository.DeleteInGenreRelationshipAsync(genre, booktostay2, inGenre);

            await _genreRepository.DeleteGenreAsync(genre);

            await _bookRepository.DeleteBookAsync(booktostay1);

            await _bookRepository.DeleteBookAsync(booktostay2);

            await _bookRepository.DeleteBookAsync(booktogo);
        }