public void T12_SearchByAuthor_SearchForBookByAuthor() { Author testAuthor1 = new Author("Franzen"); testAuthor1.Save(); Author testAuthor2 = new Author("Rowling"); testAuthor2.Save(); Book testBook1 = new Book("Freedom"); testBook1.Save(); Book testBook2 = new Book("Harry Potter and the Deathly Hallows"); testBook2.Save(); Book testBook3 = new Book("Harry Potter and the Chamber of Secrets"); testBook3.Save(); testBook1.AddAuthor(testAuthor1); testBook2.AddAuthor(testAuthor2); testBook3.AddAuthor(testAuthor2); List<Book> result = Book.SearchByAuthor("Rowling"); List<Book> testBooks = new List<Book> {testBook2, testBook3}; // Console.WriteLine(testBooks[0].GetTitle()); // Console.WriteLine(result[0].GetTitle()); // Console.WriteLine(testBooks[1].GetTitle()); // Console.WriteLine(result[1].GetTitle()); Assert.Equal(testBooks, result); }
public void T10_AddExistingAuthor() { Author testAuthor1 = new Author("Franzen"); testAuthor1.Save(); Author testAuthor2 = new Author("Franzen"); testAuthor2.Save(); Book testBook = new Book("Freedom"); testBook.Save(); Book testBook2 = new Book("Example"); testBook2.Save(); testBook.AddAuthor(testAuthor1); testBook.AddAuthor(testAuthor2); int result = testBook.GetAuthors().Count; Assert.Equal(1, result); }
public void Test_GetAuthors() { Author a = new Author("Allen"); a.Save(); Book newbook = new Book("2a", "Sf", "The blob"); newbook.Save(); newbook.AddAuthor(a.id); Assert.Equal(a.id, newbook.GetAuthors()[0].id); }
public void Test_AddAuthor_AddsAuthorToBook() { Book newBook = new Book ("Redwall"); newBook.Save(); Author newAuthor = new Author ("Brian Jacques"); newAuthor.Save(); newBook.AddAuthor(newAuthor); List<Author> testAuthor = new List<Author> {newAuthor}; List<Author> allAuthors = newBook.GetAuthors(); Assert.Equal(testAuthor, allAuthors); }
public HomeModule() { Get["/"] = _ => { Dictionary<string, object> model = new Dictionary<string, object>(); List<Book> booksByTitle = Book.SearchByTitle("VOID-SEARCH-TO-PREVENT-DATA"); List<Book> booksByAuthor = Book.SearchByAuthor("VOID-SEARCH-TO-PREVENT-DATA"); model.Add("booksByTitle", booksByTitle); model.Add("booksByAuthor", booksByAuthor); return View["index.cshtml", model]; }; Get["/librarian"] = _ => { return View["librarian.cshtml"]; }; Post["/success"] = _ => { Book newBook = new Book(Request.Form["title-input"]); newBook.Save(); Author newAuthor = new Author(Request.Form["author-input"]); newAuthor.Save(); newBook.AddAuthor(newAuthor); Dictionary<string, object> model = new Dictionary<string, object>(); model.Add("addedBook", newBook); model.Add("addedAuthor", newAuthor); return View["success.cshtml", model]; }; Post["/results"] = _ => { string input = Request.Form["search-input"]; Dictionary<string, object> model = new Dictionary<string, object>(); List<Book> booksByTitle = Book.SearchByTitle(input.ToString()); List<Book> booksByAuthor = Book.SearchByAuthor(input.ToString()); model.Add("booksByTitle", booksByTitle); model.Add("booksByAuthor", booksByAuthor); return View["index.cshtml", model]; }; }
public void UpdateAuthor_OneBook_BookAndNewAuthor() { Book testBook1 = new Book("Alice in Wonderland"); testBook1.Save(); Author testAuthor1 = new Author("example author1"); testAuthor1.Save(); Author testAuthor2 = new Author("example author2"); testAuthor2.Save(); testBook1.AddAuthor(testAuthor1.GetId()); testBook1.UpdateAuthor(testAuthor1, testAuthor2); List <Author> allAuthors = testBook1.GetAuthor(); List <Author> expected = new List <Author> { testAuthor2 }; Assert.Equal(expected, allAuthors); }
public void Test_Search() { Author a = new Author("Allen"); a.Save(); Book newbook = new Book("2a", "Sf", "The blob"); newbook.Save(); newbook.AddAuthor(a.id); List<Book> search= Book.Search("Allen", "author"); Assert.Equal(1,search.Count); }
public HomeModule() { Get["/"] =_=>{ return View["index.cshtml"]; }; Get["/references"] =_=>{ List<Book> search = new List<Book> {}; return View["references.cshtml",search]; }; Get["/patrons"]=_=>{ List<Book> search = new List<Book> {}; return View["patrons.cshtml",search]; }; Get["/books/{id}"] =parameters=> { Book b = Book.Find(parameters.id); return View["book.cshtml", b]; }; Get["/patronview/books/{id}"] =parameters=> { Book b = Book.Find(parameters.id); return View["patronview-book.cshtml", b]; }; Get["/copies/{id}"] =parameters=> { Copy c = Copy.Find(parameters.id); return View["copy.cshtml", c]; }; Get["/patronview/copies/{id}"] =parameters=> { Copy c = Copy.Find(parameters.id); return View["patronview-copy.cshtml", c]; }; Delete["/copies/delete/{id}"] =parameters=> { Copy c = Copy.Find(parameters.id); c.Delete(new string[] {"checkouts"}, new string[] {"copy_id"}); return View["book.cshtml", Book.Find(c.book_id)]; }; Patch["/books/edit/{id}"] =parameters=> { Book b = Book.Find(parameters.id); b.Update(new List<string> {"call_number", "collection", "title"}, new List<object> {(string)Request.Form["callNumber"], (string)Request.Form["collection"], (string)Request.Form["title"]}); b.RemoveAuthors(); for(int i = 0; i<Request.Form["number-of-authors"]; i++) { Author a = Author.FindByName(Request.Form["author" + i]); if(a==null) { a = new Author(Request.Form["author" + i]); a.Save(); } b.AddAuthor(a.id); } return View["book.cshtml", b]; }; Get["/circulation"] =_=>{ return View["circulation.cshtml"]; }; Post["/patron/new"] =_=> { Patron p = new Patron(0, (string)Request.Form["name"], ""); p.Save(); return View["patron.cshtml", p]; }; Post["/check-out/{id}"] =parameters=> { Patron p = Patron.Find(parameters.id); Copy c = Copy.Find((int)Request.Form["itemId"]); if(c!=null) { p.Checkout(c.id); } return View["patron.cshtml", p]; }; Get["/check-in"] =_=> { return View["check-in.cshtml"]; }; Post["/check-in/new"] =_=> { int copyId = (int)Request.Form["id"]; Copy c = Copy.Find(copyId); if(c!=null) { c.Checkin(); } return View["check-in.cshtml"]; }; Get["/check-out"] =_=> { return View["check-out.cshtml", ""]; }; Post["/patron"] =_=> { Patron p = Patron.Find((int)Request.Form["patronId"]); if(p==null) { return View["check-out.cshtml", "No Patron Found"]; } else { return View["patron.cshtml", p]; } }; Post["/patronview"] =_=> { Patron p = Patron.Find((int)Request.Form["patronId"]); if(p==null) { return View["check-out.cshtml", "No Patron Found"]; } else { return View["patronview.cshtml", p]; } }; Get["/catalog"] =_=>{ return View["catalog.cshtml"]; }; Post["books/new"] =_=> { Book newBook = new Book(Request.Form["callNumber"], Request.Form["collection"], Request.Form["title"]); newBook.Save(); Copy newCopy = new Copy(newBook.id, new DateTime(1900,1,1), 0); newCopy.Save(); for(int i = 0; i<Request.Form["number-of-authors"]; i++) { Author a = Author.FindByName(Request.Form["author" + i]); if(a==null) { a = new Author(Request.Form["author" + i]); a.Save(); } newBook.AddAuthor(a.id); } return View["book.cshtml", newBook]; }; Post["copies/new"] =_=> { int bookId = (int)Request.Form["book_id"]; Copy newCopy = new Copy(bookId, new DateTime(1900,1,1), 0); newCopy.Save(); return View["copy.cshtml", newCopy]; }; Post["/search"] =_=> { string search = Request.Form["search"]; string searchType = Request.Form["searchdef"]; List<Book> booksearch = Book.Search(search,searchType); return View["references.cshtml",booksearch]; }; Post["/patronview/search"] =_=> { string search = Request.Form["search"]; string searchType = Request.Form["searchdef"]; List<Book> booksearch = Book.Search(search,searchType); return View["patrons.cshtml",booksearch]; }; Get["/patron/edit/{id}"]=parameters=>{ Patron findpatron = Patron.Find(parameters.id); return View["updatepatron.cshtml", findpatron]; }; Patch["/patron/edit/{id}"]=parameters=>{ Patron findpatron = Patron.Find(parameters.id); findpatron.Update(new List<string>{"name", "notes"}, new List<object>{(string)Request.Form["patronname"], (string)Request.Form["notes"]}); return View["patron.cshtml", findpatron]; }; Patch["/patron/payfines/{id}"]=parameters=> { Patron p = Patron.Find(parameters.id); p.PayFines(Request.Form["amount"]); return View["patron.cshtml", p]; }; Get["/overdue"]=_=> { List<Copy> overDueBooks = Copy.OverdueBooks(); return View["overdue.cshtml",overDueBooks]; }; Get["/patron/{id}"] = parameters => { Patron p = Patron.Find(parameters.id); return View["patron.cshtml", p]; }; }
public void Test_FindByAuthor_FindsBookByAuthor() { Book testBook = new Book ("Redwall"); testBook.Save(); Author newAuthor = new Author ("Brian Jacques"); newAuthor.Save(); testBook.AddAuthor(newAuthor); List<Book> testBookList = new List<Book> {testBook}; List<Book> resultBookList = Book.FindByAuthor("Jac.Ques"); Assert.Equal(testBookList, resultBookList); }
public void T13_SearchByAuthor_SearchForBookByAuthor() { Author testAuthor1 = new Author("Franzen"); testAuthor1.Save(); Author testAuthor2 = new Author("J. K. Rowling"); testAuthor2.Save(); Author testAuthor3 = new Author("Fred Rowling Jr."); testAuthor3.Save(); Book testBook1 = new Book("Freedom"); testBook1.Save(); Book testBook2 = new Book("Harry Potter and the Deathly Hallows"); testBook2.Save(); Book testBook3 = new Book("How to Make Pizza"); testBook3.Save(); testBook1.AddAuthor(testAuthor1); testBook2.AddAuthor(testAuthor2); testBook3.AddAuthor(testAuthor3); List<Book> result = Book.SearchByAuthor("Rowling"); List<Book> testBooks = new List<Book> {testBook2, testBook3}; Assert.Equal(testBooks, result); }
public void T9_GetAuthors_ReturnsAllBookAuthors() { Book testBook = new Book("Freedom"); testBook.Save(); Author testAuthor1 = new Author("Franzen"); testAuthor1.Save(); Author testAuthor2 = new Author("Oprah"); testAuthor2.Save(); Author testAuthor3 = new Author("Franco"); testAuthor3.Save(); Author testAuthor4 = new Author("Oprahhhhh"); testAuthor4.Save(); testBook.AddAuthor(testAuthor1); List<Author> result = testBook.GetAuthors(); List<Author> testList= new List<Author>{testAuthor1}; Assert.Equal(testList,result); }
public void T8_AddAuthor_Adds1AuthorToBook() { Book testBook = new Book("Freedom"); testBook.Save(); Author testAuthor = new Author("Franzen"); testAuthor.Save(); testBook.AddAuthor(testAuthor); List<Author> result = testBook.GetAuthors(); List<Author> testList = new List<Author> {testAuthor}; Assert.Equal(testList, result); }
public HomeModule() { Get["/"] = _ => { return(View["patron_login.cshtml"]); }; Post["/home"] = _ => { //make newPatron object with more information like password and username Patron newPatron = new Patron(Request.Form["new-name"]); newPatron.Save(); return(View["patron_home.cshtml", newPatron]); }; Get["/search/books"] = _ => { return(View["search_books.cshtml"]); }; Post["/search/books"] = _ => { Book foundBook = Book.Search(Request.Form["title"]); return(View["search_books.cshtml", foundBook]); }; Get["/checkout/{id}"] = parameters => { Book foundBook = Book.Find(parameters.id); return(View["checkout.cshtml", foundBook]); }; //////////////////////////////////////////////////////////////// Get["/admin/login"] = _ => { return(View["admin_login.cshtml"]); }; Post["/admin/home"] = _ => { //make newPatron object with more information like password and username Patron newPatron = new Patron(Request.Form["admin-new-name"]); newPatron.Save(); return(View["admin_home.cshtml", newPatron]); }; Get["/admin/books"] = _ => { return(View["admin_books.cshtml", ModelMaker()]); }; Post["/admin/books"] = _ => { Author newAuthor = new Author(Request.Form["author"]); newAuthor.Save(); Book newBook = new Book(Request.Form["title"]); newBook.Save(); newBook.AddAuthor(newAuthor.GetId()); for (int i = 1; i <= Request.Form["copy"]; i++) { Copy newCopy = new Copy(newBook.GetId(), i); newCopy.Save(); } return(View["admin_books.cshtml", ModelMaker()]); }; Get["/admin/books/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Book newBook = Book.Find(parameters.id); model.Add("Book", newBook); List <Author> newBookAuthor = newBook.GetAuthor(); model.Add("Authors", newBookAuthor); List <Copy> newBookCopies = newBook.GetCopy(); model.Add("Copies", newBookCopies); return(View["book.cshtml", model]); }; // that works -V Delete["/admin/book/{id}"] = parameters => { Book selectedBook = Book.Find(parameters.id); selectedBook.Delete(); return(View["admin_books.cshtml", ModelMaker()]); }; Patch["/admin/book/{id}"] = parameters => { Book selectedBook = Book.Find(parameters.id); selectedBook.UpdateTitle(Request.Form["name"]); return(View["admin_books.cshtml", ModelMaker()]); }; // Post["/admin/home"] = _ => // { // model = // return view["admin_home.cshtml", ModelMaker()]; // }; }
public HomeModule() { string thisDay = "1"; Get["/"] = _ => { return(View["index.cshtml", ModelMaker()]); }; Post["/overdue-date"] = _ => { thisDay = Request.Form["current-day"]; Dictionary <string, object> model = ModelMaker(); model.Add("Overdue", Checkout.GetAllOverdue(thisDay)); return(View["overdue.cshtml", model]); }; Post["/add-book"] = _ => { Book newBook = new Book(Request.Form["book-name"], Request.Form["copies"]); newBook.Save(); if (Request.Form["author-name"] != null) { Author newAuthor = new Author(Request.Form["author-name"]); newAuthor.Save(); newBook.AddAuthor(newAuthor.GetId()); } Dictionary <string, object> model = ModelMaker(); model.Add("Book", newBook); return(View["book.cshtml", model]); }; Post["/add-author"] = _ => { Author newAuthor = new Author(Request.Form["author-name"]); newAuthor.Save(); Dictionary <string, object> model = ModelMaker(); model.Add("Author", newAuthor); return(View["author.cshtml", model]); }; Post["/patron/{patronId}/return/{id}"] = parameters => { Checkout.Return(parameters.id); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.patronId)); model.Add("Patron Checkouts", Patron.Find(parameters.patronId).GetCheckouts()); return(View["patron.cshtml", model]); }; Post["/add-patron"] = _ => { Patron newPatron = new Patron(Request.Form["patron-name"], Request.Form["patron-phone"]); newPatron.Save(); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", newPatron); model.Add("Patron Checkouts", newPatron.GetCheckouts()); return(View["patron.cshtml", model]); }; Get["/patron/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.id)); model.Add("Patron Checkouts", Patron.Find(parameters.id).GetCheckouts()); return(View["patron.cshtml", model]); }; Post["/patron/{id}"] = parameters => { Checkout newCheckout = new Checkout(Request.Form["due-date"], parameters.id, Request.Form["booklist"]); newCheckout.Save(Book.Find(Request.Form["booklist"])); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.id)); model.Add("Patron Checkouts", Patron.Find(parameters.id).GetCheckouts()); return(View["patron.cshtml", model]); }; Patch["/patron/{id}"] = parameters => { Patron.Find(parameters.id).Update(Request.Form["new-name"], Request.Form["new-phone"]); Dictionary <string, object> model = ModelMaker(); model.Add("Patron", Patron.Find(parameters.id)); model.Add("Patron Checkouts", Patron.Find(parameters.id).GetCheckouts()); return(View["patron.cshtml", model]); }; Get["/author/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Author", Author.Find(parameters.id)); return(View["author.cshtml", model]); }; Post["/author/{id}"] = parameters => { Author.Find(parameters.id).AddBook(Request.Form["book-id"]); Dictionary <string, object> model = ModelMaker(); model.Add("Author", Author.Find(parameters.id)); return(View["author.cshtml", model]); }; Patch["/author/{id}"] = parameters => { Author.Find(parameters.id).Update(Request.Form["new-name"]); Dictionary <string, object> model = ModelMaker(); model.Add("Author", Author.Find(parameters.id)); return(View["author.cshtml", model]); }; Delete["/author/{id}"] = parameters => { Author.Delete(parameters.id); return(View["index.cshtml", ModelMaker()]); }; Get["/book/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; Delete["/book/{id}"] = parameters => { Dictionary <string, object> model = ModelMaker(); model.Add("Overdue", Checkout.GetAllOverdue(thisDay)); Book.Delete(parameters.id); return(View["index.cshtml", model]); }; Post["/book/{id}"] = parameters => { Book.Find(parameters.id).AddAuthor(Request.Form["author-id"]); Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; Post["/book/{id}/remove_author"] = parameters => { Book.Find(parameters.id).RemoveAuthor(Request.Form["author-id"]); Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; Patch["/book/{id}"] = parameters => { Book.Find(parameters.id).Update(Request.Form["new-name"], Request.Form["new-copies"]); Dictionary <string, object> model = ModelMaker(); model.Add("Book", Book.Find(parameters.id)); return(View["book.cshtml", model]); }; }
public HomeModule() { Get["/"] = _ => { // List<Stylist> AllLists = Stylist.GetAll(); return(View["index.cshtml"]); }; Get["/books"] = _ => { var AllBooks = Book.GetAll(); return(View["books.cshtml", AllBooks]); }; Get["/patrons"] = _ => { List <Patron> allPatrons = Patron.GetAll(); return(View ["patrons.cshtml", allPatrons]); }; Get["/books/new"] = _ => { return(View["books_form.cshtml"]); }; Post["/books/new"] = _ => { Book newBook = new Book(Request.Form["title"]); newBook.Save(); Copy newCopy = new Copy(newBook.GetId(), Request.Form["number-of"], DateTime.Today); newCopy.Save(); Author newAuthor = new Author(Request.Form["author"]); newAuthor.Save(); newBook.AddAuthor(newAuthor); List <Author> allAuthors = Author.GetAll(); List <Copy> allCopies = Copy.GetAll(); List <Book> allBooks = Book.GetAll(); return(View["success.cshtml"]); }; Get["/books/search"] = _ => { return(View["books_search.cshtml"]); }; Get["/books/found"] = _ => { List <Author> selectAuthors = new List <Author> { }; List <Book> foundBooks = new List <Book> { }; string authorName = Request.Form["name"]; List <Author> allAuthors = Author.GetAll(); foreach (Author listAuthor in allAuthors) { if (listAuthor.GetName() == authorName) { selectAuthors.Add(listAuthor); } } foreach (Author newAuthor in selectAuthors) { foundBooks = newAuthor.GetBooks(); } return(View["/books_found.cshtml", foundBooks]); }; Get["/patrons/new"] = _ => { List <Patron> AllPatrons = Patron.GetAll(); return(View["patrons_form.cshtml", AllPatrons]); }; Post["/patrons/new"] = _ => { Patron newPatron = new Patron(Request.Form["name"]); newPatron.Save(); return(View["success.cshtml"]); }; Get["/books/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var selectedBook = Book.Find(parameters.id); List <Author> author = selectedBook.GetAuthors(); selectedBook.AddAuthor(author[0]); var copies = selectedBook.GetCopies(); model.Add("book", selectedBook); model.Add("author", author); model.Add("copies", copies); return(View["book.cshtml", model]); }; Get["/patron/{id}"] = parameters => { Patron selectedPatron = Patron.Find(parameters.id); List <object> model = new List <object> { }; List <Book> bookList = Book.GetAll(); model.Add(selectedPatron); model.Add(bookList); return(View["patron.cshtml", model]); }; Get["patron/checkout/{id}"] = parameters => { List <Book> bookList = new List <Book> { }; Patron selectedPatron = Patron.Find(parameters.id); Book newBook = Book.Find(int.Parse(Request.Form("book"))); Console.WriteLine(newBook); bookList.Add(newBook); return(View["patron_checkout.cshtml", bookList]); }; // Patch["patron/checkout/{id}"] = parameters => { // Patron selectedPatron = Patron.Find(parameters.id); // Book newBook = Book.Find(Request.Form("book")); // return View["success.cshtml"]; // }; Get["/book/edit/{id}"] = parameters => { Book selectedBook = Book.Find(parameters.id); return(View["book_edit.cshtml", selectedBook]); }; Patch["/book/edit/{id}"] = parameters => { Book selectedBook = Book.Find(parameters.id); selectedBook.Update(Request.Form["book-title"]); return(View["success.cshtml"]); }; Get["/patron/edit/{id}"] = parameters => { Patron selectedPatron = Patron.Find(parameters.id); return(View["patron_edit.cshtml", selectedPatron]); }; Patch["/patron/edit/{id}"] = parameters => { Patron selectedPatron = Patron.Find(parameters.id); selectedPatron.Update(Request.Form["name"]); return(View["success.cshtml"]); }; Get["/book/delete/{id}"] = parameters => { Book selectedBook = Book.Find(parameters.id); return(View["/book_delete.cshtml", selectedBook]); }; Delete["book/delete/{id}"] = parameters => { Book selectedBook = Book.Find(parameters.id); selectedBook.Delete(); return(View["success.cshtml"]); }; Get["/patron/delete/{id}"] = parameters => { Patron selectedPatron = Patron.Find(parameters.id); return(View["/patron_delete.cshtml", selectedPatron]); }; Delete["/patron/delete/{id}"] = parameters => { Patron selectedPatron = Patron.Find(parameters.id); selectedPatron.Delete(); return(View["success.cshtml"]); }; }