public void Get_All_Returns_All_Books()
        {
            // Arrange
            buildBooks();
            FilledBookRepository repo = new FilledBookRepository(starterBooks);
            Book newBook = new Book()
            {
                Title = "Test" + starterBooks.Count
            };
            Book newNewBook = new Book()
            {
                Title = "Test" + (starterBooks.Count + 1)
            };

            repo.Add(newBook);
            repo.Add(newNewBook);
            starterBooks.Add(newBook);
            starterBooks.Add(newNewBook);

            // Act
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(starterBooks, books);
        }
コード例 #2
0
        public void Get_All_Returns_All_Books()
        {
            // Arrange
            LibraryContextMock   mockContext = new LibraryContextMock();
            FilledBookRepository repo        = new FilledBookRepository(mockContext);
            Book book1 = new Book {
                id = 0, title = "Tennis", isbn = "11111", author = "Andy Murray", publishDate = "01/01/2001"
            };
            Book book2 = new Book {
                id = 1, title = "All about tennis", isbn = "22222", author = "Tim Henman", publishDate = "02/02/2002"
            };
            Book book3 = new Book {
                id = 2, title = "Yeah tennis", isbn = "33333", author = "Boris Becker", publishDate = "03/03/2003"
            };
            Book newBook1 = new Book()
            {
                title = "Test1"
            };
            Book newBook2 = new Book()
            {
                title = "Test2"
            };

            repo.Add(newBook1);
            repo.Add(newBook2);

            // Act
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(new Book[] { book1, book2, book3, newBook1, newBook2 }, books.ToArray());
        }
コード例 #3
0
        public void Get_Returns_Specific_Book()
        {
            // Arrange
            LibraryContextMock   mockContext = new LibraryContextMock();
            FilledBookRepository repo        = new FilledBookRepository(mockContext);
            Book newBook1 = new Book()
            {
                id = 0, title = "Test1"
            };
            Book newBook2 = new Book()
            {
                id = 1, title = "Test2"
            };

            repo.Add(newBook1);
            repo.Add(newBook2);

            // Act
            Book book = repo.Get(1);

            // Asert
            Assert.Equal(newBook2, book);
        }
        public void Get_Returns_Specific_Book()
        {
            // Arrange
            buildBooks();
            FilledBookRepository repo = new FilledBookRepository(starterBooks);
            Book newBook = new Book()
            {
                Title = "Test" + starterBooks.Count
            };
            Book newNewBook = new Book()
            {
                Title = "Test" + (starterBooks.Count + 1)
            };

            repo.Add(newBook);
            repo.Add(newNewBook);

            // Act
            Book book = repo.Get(starterBooks.Count);

            // Asert
            Assert.Equal(newBook, book);
        }
コード例 #5
0
        public void Add_Inserts_New_Book()
        {
            // Arrange
            LibraryContextMock   mockContext = new LibraryContextMock();
            FilledBookRepository repo        = new FilledBookRepository(mockContext);
            Book newBook = new Book()
            {
                title = "Test"
            };

            // Act
            repo.Add(newBook);
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(books.Count(), 4);
        }
        public void Add_Sets_New_Id()
        {
            // Arrange
            buildBooks();
            FilledBookRepository repo = new FilledBookRepository(starterBooks);
            Book newBook = new Book()
            {
                Title = "Test" + starterBooks.Count
            };

            // Act
            repo.Add(newBook);
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(starterBooks.Count, books.Last().Id);
        }
コード例 #7
0
        public void Update_updates_Correct_Book()
        {
            // Arrange
            LibraryContextMock   mockContext = new LibraryContextMock();
            FilledBookRepository repo        = new FilledBookRepository(mockContext);
            Book book1 = new Book {
                id = 0, title = "Tennis", isbn = "11111", author = "Andy Murray", publishDate = "01/01/2001"
            };
            Book book2 = new Book {
                id = 1, title = "All about tennis", isbn = "22222", author = "Tim Henman", publishDate = "02/02/2002"
            };
            Book book3 = new Book {
                id = 2, title = "Yeah tennis", isbn = "33333", author = "Boris Becker", publishDate = "03/03/2003"
            };
            Book newBook = new Book()
            {
                id          = 3,
                title       = "New title",
                author      = "New author",
                isbn        = "22222",
                publishDate = "2001"
            };
            Book oldBook = new Book()
            {
                id          = 3,
                title       = "Old title",
                author      = "Old author",
                isbn        = "11111",
                publishDate = "2000"
            };

            repo.Add(oldBook);

            // Act
            repo.Update(newBook, 3);
            IEnumerable <Book> books = repo.GetAll();

            // Asert
            Assert.Equal(new Book[] { book1, book2, book3, newBook }, books.ToArray());
        }