Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        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);
        }