Ejemplo n.º 1
0
        public void Test_PatronsEmptyAtFirst()
        {
            //Arrange, Act
            int result = Patron.GetAll().Count;

            //Assert
            Assert.Equal(0, result);
        }
Ejemplo n.º 2
0
        public void Patron_Delete_RemoveFromDatabase_4()
        {
            Patron newPatron = new Patron("Johnny English", "555-555-5555");

            newPatron.Save();

            Patron.Delete(newPatron.GetId());

            Assert.Equal(0, Patron.GetAll().Count);
        }
Ejemplo n.º 3
0
        public Dictionary <string, object> ModelMaker()
        {
            Dictionary <string, object> model = new Dictionary <string, object> {
                { "Books", Book.GetAll() },
                { "Authors", Author.GetAll() },
                { "Patrons", Patron.GetAll() }
            };

            return(model);
        }
Ejemplo n.º 4
0
        public void T4_Save_AssignsIdToPatron()
        {
            Patron testPatron = new Patron("Judy");

            testPatron.Save();

            Patron savedPatron = Patron.GetAll()[0];
            int    result      = savedPatron.GetId();
            int    testId      = testPatron.GetId();

            Assert.Equal(testId, result);
        }
Ejemplo n.º 5
0
        public void T3_Save_SavesToDB()
        {
            Patron testPatron = new Patron("Judy");

            testPatron.Save();

            List <Patron> result   = Patron.GetAll();
            List <Patron> testList = new List <Patron> {
                testPatron
            };

            Assert.Equal(testList, result);
        }
Ejemplo n.º 6
0
        public void Update_UpdateNameAndPhone_UpdatedInfo()
        {
            Patron newPatron = new Patron("Johnny English", "555-555-5555");

            newPatron.Save();
            string updatedName  = "Billy English";
            string updatedPhone = "555-444-5555";

            newPatron.Update(updatedName, updatedPhone);

            Assert.Equal(updatedName, Patron.GetAll()[0].GetName());
            Assert.Equal(updatedPhone, Patron.GetAll()[0].GetPhone());
        }
Ejemplo n.º 7
0
        public void Save_SavesPatronToDatabase_2()
        {
            Patron newPatron = new Patron("Johnny English", "555-555-5555");

            newPatron.Save();

            List <Patron> expectedList = new List <Patron> {
                newPatron
            };
            List <Patron> actualList = Patron.GetAll();

            Assert.Equal(expectedList, actualList);
        }
Ejemplo n.º 8
0
        public void Delete_DeletesPatronFromDatabase()
        {
            Patron newPatron = new Patron("Joe");

            newPatron.Save();

            newPatron.Delete();

            List <Patron> expectedResult = new List <Patron> {
            };
            List <Patron> actualResult   = Patron.GetAll();

            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 9
0
        public void Save_SavesNewPatron()
        {
            Patron newPatron = new Patron("Joe");

            newPatron.Save();

            List <Patron> expectedResult = new List <Patron> {
                newPatron
            };
            List <Patron> actual = Patron.GetAll();


            Assert.Equal(expectedResult, actual);
        }
Ejemplo n.º 10
0
        public void GetAll_true()
        {
            //Arrange
            Patron patronOne = new Patron("James McGee");

            patronOne.Save();
            Patron patronTwo = new Patron("Penny Flowers");

            patronTwo.Save();
            // Act
            int result = Patron.GetAll().Count;

            //Assert
            Assert.Equal(2, result);
        }
Ejemplo n.º 11
0
        public void Test_Save_AssignsIdToPatronObject()
        {
            //Arrange
            Patron testPatron = new Patron("Britton");

            testPatron.Save();

            //Act
            Patron savedPatron = Patron.GetAll()[0];

            int result = savedPatron.GetId();
            int testId = testPatron.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Ejemplo n.º 12
0
        public void Save_SavesToDatabase_true()
        {
            //Arrange
            Patron testPatron = new Patron("Penny Flowers");

            testPatron.Save();
            //Act

            List <Patron> result   = Patron.GetAll();
            List <Patron> testList = new List <Patron> {
                testPatron
            };

            //Assert
            Assert.Equal(testList, result);
        }
Ejemplo n.º 13
0
        public void Delete_OnePatron_PatronDeleted()
        {
            Patron testPatron1 = new Patron("Britton");

            testPatron1.Save();
            Patron testPatron2 = new Patron("Megan Britney");

            testPatron2.Save();

            testPatron1.Delete();

            List <Patron> allPatrons = Patron.GetAll();
            List <Patron> expected   = new List <Patron> {
                testPatron2
            };

            Assert.Equal(expected, allPatrons);
        }
Ejemplo n.º 14
0
        public void T7_Delete_DeletesPatronFromDB()
        {
            //Always remember to save to DB (Save())
            Patron testPatron1 = new Patron("Judy");

            testPatron1.Save();
            Patron testPatron2 = new Patron("Barb");

            testPatron2.Save();

            testPatron1.Delete();

            List <Patron> result      = Patron.GetAll();
            List <Patron> testPatrons = new List <Patron> {
                testPatron2
            };

            Assert.Equal(testPatrons, result);
        }
Ejemplo n.º 15
0
        public HomeModule()
        {
            Get["/"] = _ => View["index.cshtml"];

            Get["/patrons"] = _ => {
                List <Patron> AllPatrons = Patron.GetAll();
                return(View["Patron/patron_index.cshtml", AllPatrons]);
            };


            Post["/patron/new"] = _ => {
                Patron newPatron = new Patron(Request.Form["name"]);
                newPatron.Save();
                List <Patron> AllPatrons = Patron.GetAll();
                return(View["Patron/patron_index.cshtml", AllPatrons]);
            };

            Get["/patron/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                var         SelectedPatron        = Patron.FindById(parameters.id);
                List <Copy> PatronCheckouts       = SelectedPatron.GetAllCheckedOutCopies();
                model.Add("patron", SelectedPatron);
                model.Add("copies", PatronCheckouts);
                return(View["Patron/patron.cshtml", model]);
            };

            Post["/patron/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                var         SelectedPatron        = Patron.FindById(parameters.id);
                List <Copy> PatronCheckouts       = SelectedPatron.GetCheckedOutCopies(Request.Form["today-date"]);
                model.Add("patron", SelectedPatron);
                model.Add("copies", PatronCheckouts);
                return(View["Patron/patron.cshtml", model]);
            };
        }
Ejemplo n.º 16
0
        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"]);
            };
        }
Ejemplo n.º 17
0
 public void Patron_EmptyOnLoad_0()
 {
     Assert.Equal(0, Patron.GetAll().Count);
 }
Ejemplo n.º 18
0
        public void T1_DBEmptyAtFirst()
        {
            int result = Patron.GetAll().Count;

            Assert.Equal(0, result);
        }