public void TestGetAuthorsForBookThatDoesntExist() { var authors = new List <Author>() { new Author("AuthorA"), new Author("AuthorB"), }; var book = new Book("BookTitle", authors); bookDatabase = new BookDatabase(new List <Book>() { book }); try { bookDatabase.GetAuthorsForBook(book.Title + "1111"); Assert.Fail("Should throw exception if the book title doesn't exist"); } catch (ArgumentException) { } catch (Exception e) { Assert.Fail("Should throw ArgumentException"); } }
public void TestGetAuthorsForBook() { var authors = new List <Author>() { new Author("AuthorA"), new Author("AuthorB"), }; var book = new Book("BookTitle", authors); bookDatabase = new BookDatabase(new List <Book>() { book }); try { var bookAuthors = bookDatabase.GetAuthorsForBook(book.Title); Assert.AreEqual(2, bookAuthors.Count); var authorNames = authors.Select(a => a.Name).ToList(); CollectionAssert.AreEquivalent(authorNames, bookAuthors); } catch (Exception e) { Assert.Fail("Getting authors should not fail when book exists"); } }
public void TestGetAuthorsForBookNull() { try { bookDatabase.GetAuthorsForBook(null); Assert.Fail("Getting authors for null book should fail"); } catch (ArgumentNullException) { } catch (Exception e) { Assert.Fail("Should throw ArgumentNullException"); } }
public void TestDeleteBooksByAuthorSuccess_Multi() { var authors = new List <Author>() { new Author("AuthorA"), new Author("AuthorB"), }; var book = new Book("BookTitle", authors); bookDatabase = new BookDatabase(new List <Book>() { book }); try { bookDatabase.DeleteBooksByAuthor(authors[0].Name, true); } catch (Exception e) { Assert.Fail(); } // Check book title try { bookDatabase.GetAuthorsForBook(book.Title); Assert.Fail("Book should not exist anymore"); } catch (ArgumentException) { } catch (Exception) { Assert.Fail("Should throw ArgumentException"); } // Check authors try { bookDatabase.GetBookTitlesForAuthor(authors[0].Name); Assert.Fail("Book should not exist anymore"); } catch (ArgumentException) { } catch (Exception) { Assert.Fail("Should throw ArgumentException"); } }
public void TestInitialiseWithBooks() { var authors = new List <Author>() { new Author("AuthorA"), new Author("AuthorB"), }; var book = new Book("BookTitle", authors); var bookDatabase = new BookDatabase(new List <Book>() { book }); var bookAuthors = bookDatabase.GetAuthorsForBook(book.Title); Assert.AreEqual(2, bookAuthors.Count); var bookTitles = bookDatabase.GetBookTitlesForAuthor(authors[0].Name); Assert.AreEqual(1, bookTitles.Count); bookTitles = bookDatabase.GetBookTitlesForAuthor(authors[1].Name); Assert.AreEqual(1, bookTitles.Count); }