public void SerializeToFileCustom()
        {
            DataRepository  repo     = new DataRepository();
            Book            bok      = new Book("kartofle", "stefan");
            Book            bok2     = new Book("kartofle2", "stefan2");
            BookDescription bokDesc  = new BookDescription("bla", bok);
            BookDescription bokDesc2 = new BookDescription("bla2", bok2);
            Reader          red      = new Reader("zenek", "cos", 666126161);
            Reader          red2     = new Reader("zenek2", "cos2", 40445454);
            Borrow          bor      = new Borrow(red, bokDesc);

            repo.AddReader(red);
            repo.AddReader(red2);
            repo.AddBook(bok);
            repo.AddBook(bok2);
            repo.AddBookDescription(bokDesc);
            repo.AddBookDescription(bokDesc2);
            repo.AddBorrow(bor);
            repo.AddBookNumber(bokDesc, 5000);


            repo.SaveDataCustom("saveData");

            DataRepository repo2 = new DataRepository();

            repo2.LoadDataCustom("saveData");

            Assert.IsTrue(CheckIfSame(repo, repo2));
        }
Пример #2
0
        public void FindBookByAuthorTest()
        {
            repo        = new DataRepository(new ContextFiller());
            dataService = new DataService(repo);

            Book book = new Book(4, "testtitle", "testauthor", new LiteraryGenre[] { LiteraryGenre.Comedy });

            repo.AddBook(book.Id, book.Title, book.Author, book.Genres);

            Book book2 = new Book(5, "testtitle2", "testauthor2", new LiteraryGenre[] { LiteraryGenre.Comedy });

            repo.AddBook(book2.Id, book2.Title, book2.Author, book2.Genres);

            Book book3 = new Book(6, "testtitle3", "testauthor2", new LiteraryGenre[] { LiteraryGenre.Comedy });

            repo.AddBook(book3.Id, book3.Title, book3.Author, book3.Genres);

            IEnumerable <Book> result = dataService.FindBooksByAuthor("testauthor2");

            Assert.AreEqual(2, result.Count());
            foreach (Book wbook in result)
            {
                Assert.AreEqual("testauthor2", wbook.Author);
            }
        }
        public void AddBookTest()
        {
            Writer writer = new Writer("authorFirstname", "authorLastname");
            Book   book   = new Book("Tytul", writer, 320, 4, "type");

            dataRepository.AddBook(book);
            Assert.AreEqual(dataContext.books[4], book);
        }
Пример #4
0
        public void AddBookTest2()
        {
            Book           newBook  = new Book(1, 1, "title", "desc");
            Book           newBook2 = new Book(1, 2, "title2", "desc2");
            DataRepository repo     = new DataRepository();

            repo.AddBook(newBook);

            Assert.IsFalse(repo.AddBook(newBook2));
        }
Пример #5
0
        public void AddBookTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            Book book = new Book("Bk name", "Bk author", 2010);

            dataRepository.AddBook(book);
            Assert.AreEqual(5, dataRepository.FindBook(book));
            Assert.IsTrue(dataRepository.GetAllBooks().Last().Equals(book));
            Assert.ThrowsException <ArgumentException>(() => dataRepository.AddBook(book));
        }
Пример #6
0
        public void GetAllBookTest()
        {
            Book           newBook  = new Book(1, 1, "title", "desc");
            Book           newBook2 = new Book(2, 1, "title", "desc");
            DataRepository repo     = new DataRepository();

            repo.AddBook(newBook);
            repo.AddBook(newBook2);
            var restoredBook = repo.GetAllBook();

            Assert.AreEqual(2, restoredBook.Count);
        }
Пример #7
0
        public void DataRepositoryAddDuplicateBookTest()
        {
            Guid guid = Guid.NewGuid();
            Book book = new Book("Hobbit", "J. R. R. Tolkien", guid);


            DataRepository dataRepository = new DataRepository(new ConstFiller());

            dataRepository.AddBook(book);
            var exc = Assert.ThrowsException <Exception>(() => dataRepository.AddBook(book));

            Assert.AreEqual("Data already exists", exc.Message);
        }
Пример #8
0
        public void AddBookTest()
        {
            repo = new DataRepository(new ContextFiller());
            Book book = new Book(4, "testtitle", "testautthor", new LiteraryGenre [] { LiteraryGenre.Comedy });

            Assert.AreEqual(3, repo.GetAllBooks().Count());
            repo.AddBook(book.Id, book.Title, book.Author, book.Genres);
            Assert.AreEqual(4, repo.GetAllBooks().Count());
            Assert.AreEqual(4, repo.GetBook(4).Id);
            Assert.AreEqual(book.Title, repo.GetBook(4).Title);
            Assert.AreEqual(book.Author, repo.GetBook(4).Author);
            Assert.AreEqual(true, book.Genres.SequenceEqual(repo.GetBook(4).Genres));
            Assert.ThrowsException <ArgumentException>(() => repo.AddBook(book.Id, book.Title, book.Author, book.Genres));
        }
Пример #9
0
        public void AddBookInvalidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book book = new Book("Year 1984", "George Orwell", 1949);

            dataRepository.AddBook(book);

            Assert.Equal(6, dataRepository.GetAllBooks().Count());
            Assert.Equal(book, dataRepository.GetBook(6));


            Assert.Throws <ArgumentException>(() => dataRepository.AddBook(book));
        }
Пример #10
0
        public void AddBookTest()
        {
            IDataRepository dataRepository = new DataRepository(new DataFillerConstants());

            dataRepository.AddBook(new Book(1, "example"));
            Assert.AreEqual(1, dataRepository.GetAllBooks().Count);
        }
Пример #11
0
        public void AddBookTest()
        {
            Book           newBook = new Book(1, 1, "title", "desc");
            DataRepository repo    = new DataRepository();

            Assert.IsTrue(repo.AddBook(newBook));
        }
Пример #12
0
        public void GetAllBooksTest()
        {
            DataRepository dataRepository = new DataRepository();
            Author         author         = new Author("George", "Orwell");

            dataRepository.AddBook(new Book("Title 1", new List <Author> {
                author
            }, "1234_1", "Desc"));
            dataRepository.AddBook(new Book("Title 2", new List <Author> {
                author
            }, "1234_2", "Desc"));

            Dictionary <string, Book> books = dataRepository.GetAllBooks();

            Assert.AreEqual(2, books.Count);
        }
Пример #13
0
        public void AddBookTest()
        {
            int beforeSize     = context.books.Count;
            var beforeLastBook = context.books.Last();
            var bookToAdd      = new Book()
            {
                Isbn        = "76548152305",
                Title       = "Uczta",
                Author      = "Platon",
                ReleaseYear = 2012
            };

            repository.AddBook(bookToAdd);
            int afterSize     = context.books.Count;
            var afterLastBook = context.books.Last();

            // check sizes
            Assert.AreNotEqual(beforeSize, afterSize);

            // check if last books aren't equal
            Assert.AreNotEqual(beforeLastBook, afterLastBook);

            // check if the book is in the list
            Assert.IsTrue(context.books.ContainsKey(bookToAdd.Isbn));
        }
        public void AddBookTest()
        {
            int beforeSize     = context.books.Count;
            var beforeLastBook = context.books.Last();
            var bookToAdd      = new Book()
            {
                Isbn        = "9788327152305",
                Title       = "Człowiek nietoperz",
                Author      = "Jo Nesbo",
                ReleaseYear = 2014
            };

            repository.AddBook(bookToAdd);
            int afterSize     = context.books.Count;
            var afterLastBook = context.books.Last();

            // check sizes
            Assert.AreNotEqual(beforeSize, afterSize);

            // check if last books aren't equal
            Assert.AreNotEqual(beforeLastBook, afterLastBook);

            // check if the book is in the list
            Assert.IsTrue(context.books.ContainsKey(bookToAdd.Isbn));
        }
Пример #15
0
        public void GetBookTest()
        {
            DataRepository dataRepository = new DataRepository();
            Author         author         = new Author("George", "Orwell");
            Book           expectedBook   = new Book("Title 1", new List <Author> {
                author
            }, "1234_1", "Desc");

            dataRepository.AddBook(expectedBook);
            dataRepository.AddBook(new Book("Title 2", new List <Author> {
                author
            }, "1234_2", "Desc"));

            Book actualBook = dataRepository.GetBook("1234_1");

            Assert.AreEqual(expectedBook, actualBook);
        }
Пример #16
0
        public IActionResult AddBook(Book book)
        {
            var repo = new DataRepository(new DataContext());

            repo.AddBook(book);

            return(RedirectToAction(nameof(Index)));
        }
Пример #17
0
        public void AddBookTest()
        {
            DataRepository dataRepository = new DataRepository(new ConstFiller());
            Book           tmp            = new Book(5, "Fotel");

            dataRepository.AddBook(tmp);
            Assert.AreEqual(tmp.GetHashCode(), dataRepository.GetBook(tmp.BookID).GetHashCode());
        }
Пример #18
0
        public void AddBook_BookInTheRepository_ExceptionThrown()
        {
            _repo = new DataRepository(new ConstDataFiller(books: _booksInDataFiller));

            Assert.ThrowsException <DataAlreadyExistsException>(
                () => _repo.AddBook(_booksInDataFiller.First())
                );
        }
Пример #19
0
        public void GetBookTest()
        {
            IDataRepository dataRepository = new DataRepository(new DataFillerConstants());
            Book            katalog        = new Book(1, "example");

            dataRepository.AddBook(katalog);
            Assert.AreEqual(katalog, dataRepository.GetBook(1));
        }
Пример #20
0
        public void DeleteBookTest2()
        {
            Book           newBook = new Book(1, 1, "title", "desc");
            DataRepository repo    = new DataRepository();

            repo.AddBook(newBook);

            Assert.IsFalse(repo.DeleteBook(2));
        }
Пример #21
0
        public void DeleteBookTest()
        {
            IDataRepository dataRepository = new DataRepository(new DataFillerConstants());
            Book            book           = new Book(1, "example");

            dataRepository.AddBook(book);
            dataRepository.DeleteBook(book);
            Assert.AreEqual(0, dataRepository.GetAllBooks().Count);
        }
Пример #22
0
        public void GetAllBooksTest()
        {
            IDataRepository        dataRepository = new DataRepository(new DataFillerConstants());
            Dictionary <int, Book> dictionary     = dataRepository.GetAllBooks();
            Book book = new Book(1, "example");

            dataRepository.AddBook(book);
            Assert.AreEqual(dictionary, dataRepository.GetAllBooks());
        }
Пример #23
0
        public void GetBookValidValue()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Book            book = new Book("Year 1984", "George Orwell", 1949);

            dataRepository.AddBook(book);

            Assert.NotNull(dataRepository.GetBook(dataRepository.FindBook(book)));
        }
Пример #24
0
        public void GetBookTest()
        {
            ConstantDataFiller filler         = new ConstantDataFiller();
            IDataRepository    dataRepository = new DataRepository(filler.Fill(new DataContext()));
            Book book = new Book("Bk name", "Bk author", 2010);

            Assert.ThrowsException <ArgumentException>(() => dataRepository.GetBook(5));
            dataRepository.AddBook(book);
            Assert.AreEqual(dataRepository.GetBook(5), book);
        }
Пример #25
0
        public void GetBookTest()
        {
            Book           newBook = new Book(1, 1, "title", "desc");
            DataRepository repo    = new DataRepository();

            repo.AddBook(newBook);
            Book restoredBook = repo.GetBook(newBook.BookId);

            Assert.AreEqual(newBook, restoredBook);
        }
Пример #26
0
        public void FindBookValidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);

            Book book = new Book("Year 1984", "George Orwell", 1949);

            dataRepository.AddBook(book);
            Assert.StrictEqual(6, dataRepository.FindBook(book));
        }
Пример #27
0
        public void GetAllBookTest()
        {
            DataRepository dataRepository = new DataRepository();
            Book           tmp            = new Book(5, "Fotel");
            Book           tmp2           = new Book(8, "Motel");

            dataRepository.AddBook(tmp);
            dataRepository.AddBook(tmp2);

            Dictionary <int, Book> BooksDictionary = dataRepository.GetAllBooks();

            Book outtmp = null;

            BooksDictionary.TryGetValue(tmp.BookID, out outtmp);
            Book outtmp2 = null;

            BooksDictionary.TryGetValue(tmp2.BookID, out outtmp2);
            Assert.AreEqual(outtmp.GetHashCode(), tmp.GetHashCode());
        }
        public void GetBookTest()
        {
            DataRepository dataRepository = new DataRepository();
            var            MockBook       = RandomBook();

            dataRepository.AddBook(MockBook.Object);

            Book book = dataRepository.GetBook(0);

            Assert.AreEqual(book, MockBook.Object);
        }
Пример #29
0
        public void DeleteBookValidValueTest()
        {
            IDataFiller     constantDataFiller = new ConstantDataFiller();
            IDataRepository dataRepository     = new DataRepository(constantDataFiller);
            Book            book = new Book("Year 1984", "George Orwell", 1949);

            dataRepository.AddBook(book);
            Assert.Equal(6, dataRepository.GetAllBooks().Count());
            dataRepository.DeleteBook(book);
            Assert.Equal(5, dataRepository.GetAllBooks().Count());
        }
Пример #30
0
        public void UpdateBookTest()
        {
            IDataRepository dataRepository = new DataRepository(new DataFillerConstants());
            Book            book           = new Book(1, "example");

            dataRepository.AddBook(book);
            Book book2 = new Book(1, "hello");

            dataRepository.UpdateBook(1, book2);
            Assert.AreEqual(book2, dataRepository.GetBook(1));
        }