public void Should_Delete_Book() { var booksPath = _projectDir + "/Resources/DeleteTest/book/books.xml"; var bookMetaPath = _projectDir + "/Resources/DeleteTest/book/meta-inf.xml"; var authorsPath = _projectDir + "/Resources/DeleteTest/author/authors.xml"; var authorMetaPath = _projectDir + "/Resources/DeleteTest/author/meta-inf.xml"; var dhb = new DocumentHolder(booksPath, bookMetaPath); var dha = new DocumentHolder(authorsPath, authorMetaPath); var bookDao = DaoFactory.BookDao(dhb, dha); var authorDao = DaoFactory.AuthorDao(dha, dhb); var book1 = bookDao.FindById(1); bookDao.Delete(book1); var book1_1 = bookDao.FindById(1); Assert.IsNull(book1_1); var a1 = authorDao.FindById(1); var a3 = authorDao.FindById(3); Assert.AreEqual(1, a1.Books.Count); Assert.AreEqual(1, a3.Books.Count); }
static ApplicationContext() { _projectDir = GetProjectDirectory(); var booksPath = _projectDir + "\\Data\\book\\books.xml"; var booksMetaInfPath = _projectDir + "\\Data\\book\\meta-inf.xml"; var booksCountPath = _projectDir + "\\Data\\book\\count.xml"; var authorsPath = _projectDir + "\\Data\\author\\authors.xml"; var authorsMetaInfPath = _projectDir + "\\Data\\author\\meta-inf.xml"; var authorDocHolder = new DocumentHolder(authorsPath, authorsMetaInfPath); var bookDocHolder = new DocumentHolder(booksPath, booksMetaInfPath); _bookDao = DaoFactory.BookDao(bookDocHolder, authorDocHolder); _authorDao = DaoFactory.AuthorDao(authorDocHolder, bookDocHolder); _bookService = new BookService() { BookDao = _bookDao }; _authorService = new AuthorService() { AuthorDao = _authorDao }; _bookCounter = new BookCounter(booksCountPath); _bookArranger = new BookArranger(_projectDir + "\\Data\\book\\shelves.xml"); }
private XmlBookDao BookDaoForSearch() { var booksPath = _projectDir + "/Resources/SearchTest/book/books.xml"; var authorsPath = _projectDir + "/Resources/SearchTest/author/authors.xml"; var dhb = new DocumentHolder(booksPath); var dha = new DocumentHolder(authorsPath); var bookDao = DaoFactory.BookDao(dhb, dha); return(bookDao); }
public void Should_Remove_Author_Then_Add_Author() { var booksPath = _projectDir + "/Resources/SaveTest/SaveUpdate/book/books.xml"; var bookMetaPath = _projectDir + "/Resources/SaveTest/SaveUpdate/book/meta-inf.xml"; var authorsPath = _projectDir + "/Resources/SaveTest/SaveUpdate/author/authors.xml"; var authorMetaPath = _projectDir + "/Resources/SaveTest/SaveUpdate/author/meta-inf.xml"; var dhb = new DocumentHolder(booksPath, bookMetaPath); var dha = new DocumentHolder(authorsPath, authorMetaPath); var bookDao = DaoFactory.BookDao(dhb, dha); var authorDao = DaoFactory.AuthorDao(dha, dhb); var book = bookDao.FindById(1); var author = authorDao.FindById(1); // TEST book.RemoveAuthor(author); bookDao.Save(book, SaveOption.UPDATE_IF_EXIST); author = authorDao.FindById(1); Assert.AreEqual(2, author.Books.Count); book = bookDao.FindById(1); Assert.AreEqual(0, book.Authors.Count); book.AddAuthor(author); bookDao.Save(book, SaveOption.UPDATE_IF_EXIST); book = bookDao.FindById(1); Assert.AreEqual(1, book.Authors.Count); author = authorDao.FindById(1); Assert.AreEqual(3, author.Books.Count); }
public void Should_Save_Book() { var booksPath = _projectDir + "/Resources/SaveTest/Full/book/books.xml"; var bookMetaPath = _projectDir + "/Resources/SaveTest/Full/book/meta-inf.xml"; var authorsPath = _projectDir + "/Resources/SaveTest/Full/author/authors.xml"; var authorMetaPath = _projectDir + "/Resources/SaveTest/Full/author/meta-inf.xml"; var dhb = new DocumentHolder(booksPath, bookMetaPath); var dha = new DocumentHolder(authorsPath, authorMetaPath); var bookDao = DaoFactory.BookDao(dhb, dha); var b1 = new Book() { Title = "b1", Description = "Test" }; var b2 = new Book() { Title = "b2", Rating = 7.9f, Description = "Test Book" }; var b3 = new Book() { Title = "b3", Rating = 9.5f, Description = "Book for test purpose" }; var b4 = new Book() { Title = "b4" }; var b5 = new Book() { Title = "b5" }; var a1 = new Author() { FirstName = "a1", LastName = "Smith" }; var a2 = new Author() { FirstName = "a2", LastName = "Miller" }; var a3 = new Author() { FirstName = "a3", LastName = "Cat" }; b1.AddAuthor(a1); b2.AddAuthor(a1); b2.AddAuthor(a2); b3.AddAuthor(a2); b4.AddAuthor(a1); b5.AddAuthor(a2); b5.AddAuthor(a3); bookDao.Save(b1, SaveOption.UPDATE_IF_EXIST); }