Пример #1
0
        public void deleteAll()
        {
            IList all = new Book().findAll();

            foreach (Book book in all) {
                book.delete();
            }
        }
Пример #2
0
 public void initData()
 {
     Console.WriteLine( "------------------------------init data-------------------------------" );
     for (int i = 0; i < 10; i++) {
         Book book = new Book();
         book.Name = "zhangsan" + (i + 1);
         book.Weather = "hao" + ((i + 1) * 2);
         cdb.insert( book );
     }
 }
Пример #3
0
        public void testDeleteAll()
        {
            IList all = new Book().findAll();

            foreach (Book book in all) {
                book.delete();
            }

            int result = new Book().findAll().Count;

            Assert.AreEqual( result, 0 );
        }
Пример #4
0
        public void testDelete()
        {
            Random rd = new Random();

            for (int i = 0; i < 20; i++) {
                int id = rd.Next( 1, 11 );
                Console.WriteLine( "随机ID:" + id );
                Book book = new Book().findById( id ) as Book;
                if (book != null) {
                    book.delete();
                    Console.WriteLine( "删除:" + id );
                }
            }
        }
Пример #5
0
        public void testDelete3()
        {
            Book mybook = new Book();
            IList all = mybook.findAll();
            Assert.AreEqual( 10, all.Count );

            int deleteCount = 0;
            int bookCount = all.Count;
            for (int i = 0; i < bookCount; i++) {
                Book book = all[i] as Book;
                book.delete();
                deleteCount++;
            }

            Assert.AreEqual( bookCount, deleteCount );

            IList results = mybook.findAll();
            Assert.AreEqual( 0, results.Count );
        }
Пример #6
0
        public void testFindBy_Insert()
        {
            Book newBook = new Book {
                Name = "zhangsan5",
                Weather = "hao6"
            };
            cdb.insert( newBook );

            IList<Book> newBooks = cdb.findBy<Book>( "Name", "zhangsan5" );
            Assert.AreEqual( 2, newBooks.Count );
            Assert.AreEqual( "hao6", newBooks[1].Weather );

            IList<Book> newBooks2 = cdb.findBy<Book>( "Weather", "hao6" );
            Assert.AreEqual( 2, newBooks2.Count );
            Assert.AreEqual( "zhangsan5", newBooks2[1].Name );
        }
Пример #7
0
 public void testFindAll()
 {
     IList list = new Book().findAll();
     Assert.AreEqual( 10, list.Count );
 }
Пример #8
0
        public void testFindBy_Update()
        {
            IList books = new Book().findBy( "Name", "zhangsan5" );
            Assert.AreEqual( 1, books.Count );
            Book book = books[0] as Book;

            book.Name = "zhangsan8";
            book.update();

            IList newBooks = new Book().findBy( "Name", "zhangsan5" );
            Assert.AreEqual( 0, newBooks.Count );

            IList newBooks2 = new Book().findBy( "Name", "zhangsan8" );
            Assert.AreEqual( 2, newBooks2.Count );
        }
Пример #9
0
        public void testFindBy_Insert()
        {
            Book newBook = new Book {
                Name = "zhangsan5",
                Weather = "hao6"
            };
            newBook.insert();

            IList newBooks = new Book().findBy( "Name", "zhangsan5" );
            Assert.AreEqual( 2, newBooks.Count );
            Assert.AreEqual( "hao6", ((Book)newBooks[1]).Weather );

            IList newBooks2 = new Book().findBy( "Weather", "hao6" );
            Assert.AreEqual( 2, newBooks2.Count );
            Assert.AreEqual( "zhangsan5", ((Book)newBooks2[1]).Name );
        }
Пример #10
0
        public void testFindBy_Delete()
        {
            IList books = new Book().findBy( "Name", "zhangsan5" );
            Assert.AreEqual( 1, books.Count );
            Book book = books[0] as Book;

            book.delete();

            IList newBooks = new Book().findBy( "Name", "zhangsan5" );
            Assert.AreEqual( 0, newBooks.Count );

            int allCount = new Book().findAll().Count;
            Assert.AreEqual( 9, allCount );
        }
Пример #11
0
        public void testFindById()
        {
            Book book = new Book().findById( 5 ) as Book;
            Assert.IsNotNull( book );
            Assert.AreEqual( "zhangsan5", book.Name );

            Book nullBook = new Book().findById( 999999 ) as Book;
            Assert.IsNull( nullBook );
        }