Exemplo n.º 1
0
        // GET: Books
        public IActionResult Index(string val)
        {
            var books = new List <Book>();

            if (!String.IsNullOrEmpty(val))
            {
                books = _repository.LookupBook(val).ToList();
                return(View(books));
            }
            books = _repository.GetAllBooks().ToList();
            return(View(books));
        }
        public void UpdateCopyOfBookTest()
        {
            ConstObjectsFiller cof = new ConstObjectsFiller();

            _dataLayer            = new LibraryRepository();
            _dataLayer.DataFiller = cof;
            _dataLayer.FillData();
            CopyOfBook newBook = new CopyOfBook(Guid.NewGuid(), _dataLayer.GetAllBooks().ElementAt(0), DateTime.Now, 21);
            Guid       id      = _dataLayer.GetAllCopiesOfBook().ElementAt(0).Id;

            Assert.ThrowsException <ArgumentException>(() => _dataLayer.UpdateCopyOfBook(id, newBook));
            Assert.ThrowsException <ArgumentException>(() => _dataLayer.UpdateCopyOfBook(Guid.NewGuid(), newBook));
            newBook = new CopyOfBook(id, _dataLayer.GetAllBooks().ElementAt(0), DateTime.Now, 21);
            _dataLayer.UpdateCopyOfBook(id, newBook);
            Assert.AreEqual(_dataLayer.GetCopyOfBook(id).PricePerDay, newBook.PricePerDay);
        }
        public void DependencyInjectionTest()
        {
            //Checking DataFiller property is null
            _dataLayer = new LibraryRepository();
            Assert.AreEqual(_dataLayer.DataFiller, null);
            _dataLayer.FillData();
            Assert.AreEqual(0, _dataLayer.GetAllAuthors().Count());
            Assert.AreEqual(0, _dataLayer.GetAllBooks().Count());
            Assert.AreEqual(0, _dataLayer.GetAllReaders().Count());
            Assert.AreEqual(0, _dataLayer.GetAllEmployees().Count());
            Assert.AreEqual(0, _dataLayer.GetAllCopiesOfBook().Count());
            Assert.AreEqual(0, _dataLayer.GetAllEvents().Count());
            //Inject IDataFiller impelentation (Fill with Consts)
            ConstObjectsFiller cof = new ConstObjectsFiller();

            _dataLayer.DataFiller = cof;
            _dataLayer.FillData();
            Assert.AreEqual(2, _dataLayer.GetAllAuthors().Count());
            Assert.AreEqual(3, _dataLayer.GetAllBooks().Count());
            Assert.AreEqual(1, _dataLayer.GetAllReaders().Count());
            Assert.AreEqual(1, _dataLayer.GetAllEmployees().Count());
            Assert.AreEqual(5, _dataLayer.GetAllCopiesOfBook().Count());
            Assert.AreEqual(1, _dataLayer.GetAllEvents().Count());
            //Inject IDatafiller implementation (Fill from Xml)
            XmlFileFiller xml = new XmlFileFiller();

            _dataLayer            = new LibraryRepository();
            _dataLayer.DataFiller = xml;
            _dataLayer.FillData();
            Assert.AreEqual(2, _dataLayer.GetAllAuthors().Count());
            Assert.AreEqual(1, _dataLayer.GetAllBooks().Count());
            Assert.AreEqual(1, _dataLayer.GetAllReaders().Count());
            Assert.AreEqual(1, _dataLayer.GetAllEmployees().Count());
            Assert.AreEqual(1, _dataLayer.GetAllCopiesOfBook().Count());
            Assert.AreEqual(1, _dataLayer.GetAllEvents().Count());
            TxtFileFiller txt = new TxtFileFiller();

            _dataLayer            = new LibraryRepository();
            _dataLayer.DataFiller = txt;
            _dataLayer.FillData();
            Assert.AreEqual(2, _dataLayer.GetAllAuthors().Count());
            Assert.AreEqual(1, _dataLayer.GetAllBooks().Count());
            Assert.AreEqual(1, _dataLayer.GetAllReaders().Count());
            Assert.AreEqual(1, _dataLayer.GetAllEmployees().Count());
            Assert.AreEqual(1, _dataLayer.GetAllCopiesOfBook().Count());
            Assert.AreEqual(1, _dataLayer.GetAllEvents().Count());
        }
Exemplo n.º 4
0
        private void Filter_Checked(object sender, RoutedEventArgs e)
        {
            Listbox.ItemsSource = null;
            List <Library> filteredItems = new List <Library>();

            if (BookFilter.IsChecked == true)
            {
                filteredItems.AddRange(libraryRepository.GetAllBooks());
            }
            else
            {
                foreach (Library item in libraryRepository.GetAllBooks())
                {
                    filteredItems.Remove(item);
                }
            }

            if (CDFilter.IsChecked == true)
            {
                filteredItems.AddRange(libraryRepository.GetAllCds());
            }
            else
            {
                foreach (Library item in libraryRepository.GetAllCds())
                {
                    filteredItems.Remove(item);
                }
            }

            if (DVDFilter.IsChecked == true)
            {
                filteredItems.AddRange(libraryRepository.GetAllDvds());
            }
            else
            {
                foreach (Library item in libraryRepository.GetAllDvds())
                {
                    filteredItems.Remove(item);
                }
            }
            if (CDFilter.IsChecked == false && DVDFilter.IsChecked == false && BookFilter.IsChecked == false)
            {
                filteredItems = libraryRepository.GetAllLibraryItems();
            }

            Listbox.ItemsSource = filteredItems;
        }
Exemplo n.º 5
0
        public void ShouldReturnBooksFromDbSet()
        {
            var expectedBooks = new List <Book>
            {
                new Book {
                    Id = 0, Title = "Gra Endera", Author = "Orson Scott Card", Localisation = "Gliwice", ISBN = "9788376482514"
                },
                new Book {
                    Id = 1, Title = "Cień Endera", Author = "Orson Scott Card", Localisation = "Gliwice", ISBN = "9788378397649"
                }
            };

            _booksDbSetMock.As <IQueryable <Book> >().Setup(x => x.ElementType).Returns(expectedBooks.AsQueryable().ElementType);
            _booksDbSetMock.As <IQueryable <Book> >().Setup(x => x.Expression).Returns(expectedBooks.AsQueryable().Expression);
            _booksDbSetMock.As <IQueryable <Book> >().Setup(x => x.Provider).Returns(expectedBooks.AsQueryable().Provider);
            _booksDbSetMock.As <IQueryable <Book> >().Setup(x => x.GetEnumerator()).Returns(expectedBooks.GetEnumerator());

            _contextMock.Setup(x => x.Books).Returns(_booksDbSetMock.Object);

            var booksFromRepository = _libraryRepository.GetAllBooks();

            Assert.Equal(expectedBooks, booksFromRepository);
        }
 public void InitTest()
 {
     Assert.IsNull(_dataLayer.DataFiller);
     Assert.AreEqual(0, _dataLayer.GetAllAuthors().Count());
     Assert.AreEqual(0, _dataLayer.GetAllBooks().Count());
     Assert.AreEqual(0, _dataLayer.GetAllCopiesOfBook().Count());
     Assert.AreEqual(0, _dataLayer.GetAllReaders().Count());
     Assert.AreEqual(0, _dataLayer.GetAllEmployees().Count());
     Assert.AreEqual(0, _dataLayer.GetAllEvents().Count());
 }
 private void ShowBooksInListbox()
 {
     CatalogusListbox.ItemsSource = null;
     CatalogusListbox.ItemsSource = libraryRepository.GetAllBooks();
 }
Exemplo n.º 8
0
 public ActionResult Index()
 {
     return(View(BookRepo.GetAllBooks()));
 }