Exemplo n.º 1
0
        public void Add_AddsBookWithID()
        {
            List <Book>    Books    = new List <Book>();
            LibraryManager Manager  = LibraryManager.Instance;
            Book           TestBook = new Book("name", "author", "category", "language", new LocalDate(2021, 5, 15), "isbn");

            Manager.AddBook(Books, TestBook);
            Manager.AddBook(Books, TestBook);

            TestBook.Id = 0;
            Assert.AreEqual(Books.First(), TestBook);
            TestBook.Id = 1;
            Assert.AreEqual(Books.Last(), TestBook);
        }
        public async Task UpdateBook()
        {
            var options = getDatabase("UpdateBookDB");

            await using (var context = new LibraryContext(options))
            {
                var _manager = new LibraryManager(context);
                await _manager.AddBook(SingleBook());

                await context.SaveChangesAsync();
            }
            await using (var context = new LibraryContext(options))
            {
                var _manager    = new LibraryManager(context);
                var checkUpdate = await _manager.UpdateBook(new Book
                {
                    ISBN          = "ISBNCode",
                    Title         = "UpdatedBookTitle",
                    BookIsRemoved = false,
                    Author        = new Author {
                        Name = "AuthorName"
                    }
                }, 1);

                await context.SaveChangesAsync();

                Assert.Equal(1, checkUpdate);
                Assert.Equal("UpdatedBookTitle", context.Books.Single().Title);
            }
        }
Exemplo n.º 3
0
        public void Take_AssignsReader()
        {
            List <Book>    Books      = new List <Book>();
            LibraryManager Manager    = LibraryManager.Instance;
            Book           TestBook   = new Book("name", "author", "category", "language", new LocalDate(2021, 5, 15), "isbn");
            LibraryReader  TestReader = new LibraryReader("Vardenis", "Pavardenis", new LocalDate(2021, 5, 20));

            Manager.AddBook(Books, TestBook);
            Manager.TakeBook(Books, 0, TestReader);

            Assert.AreEqual(Books.First().Reader, TestReader);
        }
        public async Task AddBookTest()
        {
            var options = getDatabase("AddBookDB");

            await using (var context = new LibraryContext(options))
            {
                var _manager = new LibraryManager(context);
                await _manager.AddBook(SingleBook());

                await context.SaveChangesAsync();

                Assert.Equal(1, await context.Books.CountAsync());
                Assert.Equal("ISBNCode", context.Books.Single().ISBN);
                Assert.Equal("AuthorName", context.Books.Single().Author.Name);
            }
        }
        public async Task DeleteBookTest()
        {
            var options = getDatabase("DeleteBookDB");

            await using (var context = new LibraryContext(options))
            {
                var manager = new LibraryManager(context);
                await manager.AddBook(SingleBook());

                await context.SaveChangesAsync();

                var checkDelete = await manager.DeleteBook(1);

                Assert.Equal(1, checkDelete);
            }
        }
Exemplo n.º 6
0
        public void Take_DateOver2Months_ShouldThrowTakenDatePeriod()
        {
            List <Book>    Books              = new List <Book>();
            LibraryManager Manager            = LibraryManager.Instance;
            Book           TestBook           = new Book("name", "author", "category", "language", new LocalDate(2021, 5, 15), "isbn");
            LibraryReader  TestReader         = new LibraryReader("Vardenis", "Pavardenis", new LocalDate(2023, 5, 20));
            bool           ExceptionWasThrown = false;

            try
            {
                Manager.AddBook(Books, TestBook);
                Manager.TakeBook(Books, 0, TestReader);
            }
            catch (TakeDatePeriodException e)
            {
                ExceptionWasThrown = true;
            }

            Assert.IsTrue(ExceptionWasThrown);
        }
Exemplo n.º 7
0
        public void Take_TakingMoreThan3Books_ShouldThrowTakenBooksLimit()
        {
            const int      BookAmount         = 4;
            List <Book>    Books              = new List <Book>();
            LibraryManager Manager            = LibraryManager.Instance;
            Book           TestBook           = new Book("name", "author", "category", "language", new LocalDate(2021, 5, 15), "isbn");
            LibraryReader  TestReader         = new LibraryReader("Vardenis", "Pavardenis", new LocalDate(2021, 5, 20));
            bool           ExceptionWasThrown = false;

            try
            {
                for (uint i = 0; i < BookAmount; i++)
                {
                    Manager.AddBook(Books, TestBook);
                    Manager.TakeBook(Books, i, TestReader);
                }
            }
            catch (TakenBooksLimitException e)
            {
                ExceptionWasThrown = true;
            }

            Assert.IsTrue(ExceptionWasThrown);
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            LibraryManager manager = new LibraryManager();

            manager.AddBook();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            string         fileName = "Books.json";
            string         filePath = Path.Combine(Environment.CurrentDirectory, fileName);
            LibraryManager Manager  = LibraryManager.Instance;
            Book           newBook;
            LibraryReader  reader;
            List <Book>    Books;

            Filter currentFilter;

            if (!File.Exists(filePath))
            {
                File.Create(filePath).Close();
            }
            try
            {
                switch (args[0])
                {
                case "-h":
                    DisplayHelp();
                    break;

                case "-a":
                    newBook = new Book(args[1], args[2], args[3], args[4], Manager.ParseDate(args[5]), args[6]);
                    Books   = Manager.GetBooks(filePath);
                    Manager.AddBook(Books, newBook);
                    Manager.SetBooks(Books, filePath);
                    break;

                case "-t":
                    reader = new LibraryReader(args[2], args[3], Manager.ParseDate(args[4]));
                    Books  = Manager.GetBooks(filePath);
                    Manager.TakeBook(Books, (uint)Int32.Parse(args[1]), reader);
                    Manager.SetBooks(Books, filePath);
                    break;

                case "-r":
                    reader = new LibraryReader(args[2], args[3]);
                    Books  = Manager.GetBooks(filePath);
                    Manager.ReturnBook(Books, (uint)Int32.Parse(args[1]), reader);
                    Manager.SetBooks(Books, filePath);
                    break;

                case "-l":
                    if (Enum.TryParse(args[1], out currentFilter))
                    {
                        Books = Manager.GetBooks(filePath);
                        if (args.Length == 2)
                        {
                            Console.WriteLine(Manager.ListBooks(Books, currentFilter, null));
                        }
                        else
                        {
                            Console.WriteLine(Manager.ListBooks(Books, currentFilter, args[2]));
                        }
                    }
                    break;

                case "-d":
                    Books = Manager.GetBooks(filePath);
                    Manager.DeleteBook(Books, (uint)Int32.Parse(args[1]));
                    Manager.SetBooks(Books, filePath);
                    break;

                default:
                    Console.WriteLine("Invalid arguments.\n");
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }