Ejemplo n.º 1
0
        public void CheckConstructorsToDatabase_Theory(String title, String[] author, String publisher)
        {
            Book book = new Book(title, author.ToList(), publisher);

            ConsoleBooks.ReadingList expected = new ConsoleBooks.ReadingList();
            expected.AddBook(book);

            ConsoleBooks.ReadingList actual = new ConsoleBooks.ReadingList(title, author.ToList(), publisher);

            var expectedReadingList = expected.GetReadingList();
            var actualReadingList   = actual.GetReadingList();

            var diff = expectedReadingList.Zip(actualReadingList, (e, a) => new { Expected = e, Actual = a });

            foreach (var d in diff)
            {
                Assert.Equal(d.Expected.title, d.Actual.title);
                Assert.Equal(d.Expected.author, d.Actual.author);
                Assert.Equal(d.Expected.publisher, d.Actual.publisher);

                // Assert.Equal(expected.RemoveBook(d.Expected), d.Actual);
                // Assert.Equal(expected.RemoveBook(d.Expected), null);
            }
            // Cleanup DB
            expected.RemoveBook(book);
        }
Ejemplo n.º 2
0
        public void CheckAddBookToDatabase_Theory(String title, String[] author, String publisher)
        {
            ReadingList expected = new ReadingList(title, author.ToList(), publisher);

            ConsoleBooks.ReadingList actual = new ConsoleBooks.ReadingList();
            actual.AddBook(title, author.ToList(), publisher);

            var expectedReadingList = expected.GetReadingList();
            var actualReadingList   = actual.GetReadingList();

            var diff = expectedReadingList.Zip(actualReadingList, (e, a) => new { Expected = e, Actual = a });

            foreach (var d in diff)
            {
                Assert.Equal(d.Expected.title, d.Actual.title);
                Assert.Equal(d.Expected.author, d.Actual.author);
                Assert.Equal(d.Expected.publisher, d.Actual.publisher);
            }
            // Cleanup DB
            // expected.RemoveBook(title,author.ToList(), publisher);  <== This SHOULD work (TODO)
            expected.RemoveBook(new Book(title, author.ToList(), publisher));
        }
Ejemplo n.º 3
0
        private String Menu()
        {
            string[] permittedAnswers = { "s", "search", "v", "view", "q", "quit" };
            string   choice           = "";

            do
            {
                Console.WriteLine(
                    " _________________\r\n" +
                    "|                 |\r\n" +
                    "|    MAIN MENU    |\r\n" +
                    "|_________________|\r\n" +
                    "[s]earch:  Search the library\r\n" +
                    "[v]iew:    View your reading list\r\n" +
                    "[q]uit:    Quit");

                choice = Console.ReadLine();

                if (choice == "s" || choice == "search")
                {
                    List <Book> bookQuery = SearchLibrary();

                    int index = 1;
                    foreach (Book book in bookQuery)
                    {
                        book.PrintBookWithIndex(index); ++index;
                    }

                    String confirm = InputYesOrNo("Would you like to add any books to your reading List?\r\n" +
                                                  "Answer [Y]es, or [N]o.", new string[] { "yes", "y", "no", "n" });

                    if (expressionsForYes.Contains(confirm.ToLower()))
                    {
                        int bookNumber = InputIntegerList("Please enter the number of the book you would like to add (1-5), type 'r' to return to the main menu, or 'q' to leave the library.",
                                                          new List <String> {
                            "1", "2", "3", "4", "5"
                        });

                        if (bookNumber == -1)
                        {
                            this.Quit();
                        }
                        else if (bookNumber == -2)
                        {
                            continue; // Return to menu
                        }

                        Console.WriteLine("Book being added to reading list: ");
                        bookQuery[bookNumber - 1].PrintBookWithIndex(bookNumber);
                        readingList.AddBook(bookQuery[bookNumber - 1]);
                    }
                    else
                    {
                        Console.WriteLine("No book was selected to add to the reading list.");
                    }
                    Console.WriteLine("Redirecting back to the main menu.");
                    continue;
                }
                else if (choice == "v" || choice == "view")
                {
                    Console.WriteLine(
                        " ____________________\r\n" +
                        "|                    |\r\n" +
                        "|    READING LIST    |\r\n" +
                        "|____________________|\r\n");
                    readingList.Print();
                }
                else if (choice == "q" || choice == "quit")
                {
                    Quit();
                }
                else
                {
                    Console.WriteLine(choice, " is not a valid action. Please try again.");
                }
            } while (Array.Exists(permittedAnswers, permitted => permitted == choice));

            return(choice);
        }