Exemplo n.º 1
0
        public ActionResult Available(string sorting)
        {
            IEnumerable <Book> books = context.Collection().ToList();

            switch (sorting)
            {
            case "titleAscending":
                books = books.OrderBy(a => a.Title);
                break;

            case "titleDescending":
                books = books.OrderByDescending(a => a.Title);
                break;

            case "writerAscending":
                books = books.OrderBy(a => a.WriterLastName);
                break;

            case "writerDescending":
                books = books.OrderByDescending(a => a.WriterLastName);
                break;

            default:
                books = books.OrderBy(a => a.Title);
                break;
            }
            BookListViewModel model = new BookListViewModel();

            model.Books = books;

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Index(string Genre = null, string Format = null)
        {
            List <Book>       books;
            List <BookGenre>  genres  = bookGenres.Collection().ToList();
            List <BookFormat> formats = bookFormats.Collection().ToList();

            if (Genre == null)
            {
                books = context.Collection().ToList();
            }
            else
            {
                books = context.Collection().Where(b => b.Genre == Genre).ToList();
            }

            if (Format == null)
            {
                books = context.Collection().ToList();
            }
            else
            {
                books = context.Collection().Where(b => b.Format == Format).ToList();
            }

            BookListViewModel model = new BookListViewModel();

            model.Books       = books;
            model.BookGenres  = genres;
            model.BookFormats = formats;

            return(View(model));
        }
Exemplo n.º 3
0
        public void Can_Send_Pagination_View_Model()
        {
            //Arrange
            Mock <IBookRepository> mock = new Mock <IBookRepository>();

            mock.Setup(b => b.Books).Returns(
                new Book[]
            {
                new Book {
                    ISBN = 1, Title = "Operating System"
                },
                new Book {
                    ISBN = 2, Title = "Database System"
                }
            });
            BookController controller = new BookController(mock.Object);

            controller.PageSize = 1;
            //Act
            BookListViewModel result = (BookListViewModel)controller.List(null, 2).Model;

            //Assert
            PagingInfo pageInfo = result.PagingInfo;

            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemPerPage, 1);
            Assert.AreEqual(pageInfo.TotalItems, 2);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Exemplo n.º 4
0
        // GET: Movies
        public async Task <IActionResult> Index(string SelStatuss, string searchString)
        {
            IQueryable <string> statusQuery = from m in _context.Books
                                              orderby m.Status
                                              select m.Status;

            var books1 = from m in _context.Books
                         select m;

            if (!string.IsNullOrEmpty(searchString))
            {
                books1 = books1.Where(s => s.Title.Contains(searchString));
            }

            if (!string.IsNullOrEmpty(SelStatuss))
            {
                books1 = books1.Where(x => x.Status == SelStatuss);
            }

            var SelStatussVM = new BookListViewModel
            {
                Statuss = new SelectList(await statusQuery.Distinct().ToListAsync()),
                Books   = await books1.ToListAsync()
            };

            return(View(SelStatussVM));
        }
Exemplo n.º 5
0
        public void SelectionTest()
        {
            IEntityService entityService = Container.GetExportedValue <IEntityService>();

            entityService.Books.Add(new Book()
            {
                Title = "The Fellowship of the Ring"
            });
            entityService.Books.Add(new Book()
            {
                Title = "The Two Towers"
            });

            BookController bookController = Container.GetExportedValue <BookController>();

            bookController.Initialize();

            // Check that Initialize shows the BookListView and BookView
            ShellService shellService = Container.GetExportedValue <ShellService>();

            Assert.IsInstanceOfType(shellService.BookListView, typeof(IBookListView));
            Assert.IsInstanceOfType(shellService.BookView, typeof(IBookView));

            // Check that the first Book is selected
            IBookListView     bookListView      = Container.GetExportedValue <IBookListView>();
            BookListViewModel bookListViewModel = ViewHelper.GetViewModel <BookListViewModel>(bookListView);

            Assert.AreEqual(entityService.Books.First(), bookListViewModel.SelectedBook.Book);

            // Change the selection
            BookViewModel bookViewModel = Container.GetExportedValue <BookViewModel>();

            bookListViewModel.SelectedBook = bookListViewModel.Books.Last();
            Assert.AreEqual(entityService.Books.Last(), bookViewModel.Book);
        }
        public void BuildTestForNormalQuery()
        {
            var query = Guid.NewGuid().ToString();
            var book1 = new BookWrapper(new Book("isbn1", "author1", "title1"), new[] { "provider1" });
            var book2 = new BookWrapper(new Book("isbn2", "author2", "title2"), new[] { "provider1", "provider2" });
            var book3 = new BookWrapper(new Book("isbn3", "author3", "title3"), new[] { "provider2" });

            using (MocksRecord())
            {
                bookIndex.Expect(i => i.Search(query, maxSearchResultsCount)).Return(new[] { book1, book2, book3 });
            }

            var expected = new BookListViewModel
            {
                Query = query,
                Books = new[]
                {
                    new BookViewModel {
                        ISBN = book1.Book.ISBN, Author = book1.Book.Author, Title = book1.Book.Title, Providers = book1.Providers
                    },
                    new BookViewModel {
                        ISBN = book2.Book.ISBN, Author = book2.Book.Author, Title = book2.Book.Title, Providers = book2.Providers
                    },
                    new BookViewModel {
                        ISBN = book3.Book.ISBN, Author = book3.Book.Author, Title = book3.Book.Title, Providers = book3.Providers
                    },
                }
            };
            var actual = bookListViewModelBuilder.Build(query);

            actual.ShouldBeEquivalentTo(expected);
        }
Exemplo n.º 7
0
        public void Can_Paginate()
        {
            Mock <IBookRepository> mock = new Mock <IBookRepository>();

            mock.Setup(m => m.Books).Returns(new List <Book>
            {
                new Book {
                    BookId = 1, Name = "Book1"
                },
                new Book {
                    BookId = 2, Name = "Book2"
                },
                new Book {
                    BookId = 3, Name = "Book3"
                },
                new Book {
                    BookId = 4, Name = "Book4"
                },
                new Book {
                    BookId = 5, Name = "Book5"
                }
            });

            BooksController controller = new BooksController(mock.Object);

            controller.pageSize = 3;

            BookListViewModel result = (BookListViewModel)controller.List(null, 2).Model;

            List <Book> books = result.Books.ToList();

            Assert.IsTrue(books.Count == 2);
            Assert.AreEqual(books[0].Name, "Book4");
            Assert.AreEqual(books[1].Name, "Book5");
        }
Exemplo n.º 8
0
        public IActionResult Index()
        {
            List <Book> books = _bookService.GetList();

            List <BookListViewModel> model = new List <BookListViewModel>();

            foreach (var book in books)
            {
                BookListViewModel bookModel = new BookListViewModel();
                bookModel.Id            = book.Id;
                bookModel.Isbn          = book.Isbn;
                bookModel.CategoryId    = book.CategoryId;
                bookModel.AuthorId      = book.AuthorId;
                bookModel.Title         = book.Title;
                bookModel.BookPublisher = book.BookPublisher;
                bookModel.BookPages     = book.BookPages;
                bookModel.BookImageUrl  = book.BookImageUrl;
                bookModel.DatePublished = book.DatePublished;
                bookModel.Description   = book.Description;
                bookModel.Rating        = book.Rating;
                bookModel.Author        = book.Author;
                bookModel.Category      = book.Category;
                bookModel.CreatedOn     = book.CreatedOn;

                model.Add(bookModel);
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public void Can_Send_Pagination()
        {
            Mock <IBookRepository> mock = new Mock <IBookRepository>();

            mock.Setup(m => m.Books).Returns(new List <Book> {
                new Book {
                    BookID = 1, Name = "Book1"
                },
                new Book {
                    BookID = 2, Name = "Book2"
                },
                new Book {
                    BookID = 3, Name = "Book3"
                },
                new Book {
                    BookID = 4, Name = "Book4"
                },
                new Book {
                    BookID = 5, Name = "Book5"
                },
            });

            BooksController controller = new BooksController(mock.Object);

            controller.pageSize = 3;
            BookListViewModel result     = (BookListViewModel)controller.List(null, 2).Model;
            PagingInfo        pagingInfo = result.PagingInfo;

            Assert.AreEqual(pagingInfo.CurrentPage, 2);
            Assert.AreEqual(pagingInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagingInfo.TotalItems, 5);
            Assert.AreEqual(pagingInfo.TotalPage, 2);
        }
        public void Can_Paginate()
        {
            //Arrange
            Mock <IBookRepository> mock = new Mock <IBookRepository>();

            mock.Setup(b => b.Books).Returns(new Book[] {
                new Book {
                    BookId = 1, Title = "Book1"
                },
                new Book {
                    BookId = 2, Title = "Book2"
                },
                new Book {
                    BookId = 3, Title = "Book3"
                },
                new Book {
                    BookId = 4, Title = "Book4"
                },
                new Book {
                    BookId = 5, Title = "Book5"
                },
            });
            BookController controller = new BookController(mock.Object);

            controller.PageSize = 3;
            //Act
            BookListViewModel result = (BookListViewModel)controller.List(null, 1).Model;

            //Assert
            Book[] bookArray = result.Books.ToArray();
            Assert.IsTrue(bookArray.Length == 3);
            Assert.AreEqual(bookArray[0].Title, "Book1");
            Assert.AreEqual(bookArray[1].Title, "Book2");
            Assert.AreEqual(bookArray[2].Title, "Book3");
        }
Exemplo n.º 11
0
        public IActionResult Index()
        {
            var model = new BookListViewModel();

            model.Books = new List <BookDetailViewModel>();
            model.Books.Add(new BookDetailViewModel()
            {
                Author = "Deflo", CreationDate = DateTime.Now, ISBN = "isbn 1", Title = "abc"
            });
            model.Books.Add(new BookDetailViewModel()
            {
                Author = "Bracke", CreationDate = DateTime.Now, ISBN = "isbn 2", Title = "def"
            });
            model.Books.Add(new BookDetailViewModel()
            {
                Author = "Mansell", CreationDate = DateTime.Now, ISBN = "isbn 3", Title = "ghi"
            });
            model.Books.Add(new BookDetailViewModel()
            {
                Author = "Murphy", CreationDate = DateTime.Now, ISBN = "isbn 4", Title = "jkl"
            });
            model.Books.Add(new BookDetailViewModel()
            {
                Author = "Janssens", CreationDate = DateTime.Now, ISBN = "isbn 3", Title = "mno"
            });
            model.Books.Add(new BookDetailViewModel()
            {
                Author = "Aspe", CreationDate = DateTime.Now, ISBN = "isbn 4", Title = "pqr"
            });

            return(View(model));
        }
Exemplo n.º 12
0
        public ActionResult Index(int?company, string name)
        {
            IQueryable <Book> users = db.Books.Include(p => p.Category);

            if (company != null && company != 0)
            {
                users = users.Where(p => p.CategoryId == company);
            }
            if (!String.IsNullOrEmpty(name))
            {
                users = users.Where(p => p.Name.Contains(name));
            }

            List <Category> categories = db.Categories.ToList();

            // устанавливаем начальный элемент, который позволит выбрать всех
            categories.Insert(0, new Category {
                Name = "Все", Id = 0
            });

            BookListViewModel viewModel = new BookListViewModel
            {
                Books      = users.ToList(),
                Categories = new SelectList(categories, "Id", "Name"),
                Name       = name
            };

            return(View(viewModel));
        }
 public BookListVmTests()
 {
     _bookListViewModel = new BookListViewModel
     {
         Books = new ObservableCollection <Book>
         {
             new Book {
                 Id = 1, Author = "aaa", Title = "aaa"
             },
             new Book {
                 Id = 2
             },
             new Book {
                 Id = 3, Author = "ccc", Title = "ccc"
             },
             new Book {
                 Id = 4, Author = "ddd", Title = "ddd"
             },
             new Book {
                 Id = 5, Author = "eee", Title = "eee"
             },
             new Book {
                 Id = 6, Author = "fff", Title = "fff"
             }
         }
     };
 }
Exemplo n.º 14
0
        public ViewResult List(string category)
        {
            string                 _category  = category;
            IEnumerable <Book>     books      = _bookRepository.Books;
            IEnumerable <Category> categories = _categoryRepository.Categories;

            string currentCategory = string.Empty;

            if (string.IsNullOrEmpty(category))
            {
                books           = _bookRepository.Books.OrderBy(c => c.Id);
                currentCategory = "All books";
            }
            else
            {
                foreach (var item in categories)
                {
                    if (string.Equals(item.CategoryName, _category, StringComparison.OrdinalIgnoreCase))
                    {
                        books = _bookRepository.Books.Where(c => c.Category.CategoryName.Equals(item.CategoryName)).OrderBy(c => c.Name);
                    }
                    currentCategory = _category;
                }
            }

            var bookListViewModel = new BookListViewModel
            {
                Books           = books,
                CurrentCategory = currentCategory,
                Categories      = categories
            };

            return(View(bookListViewModel));
        }
Exemplo n.º 15
0
        public void AddToCart(BookListViewModel book, HttpContext context)
        {
            var cart = GetCart(context);

            var cartItem = (from item in _db.Carts
                            where item.Book.Id == book.Id && item.CartId == cart.ShoppingCartId
                            select item).SingleOrDefault();


            if (cartItem == null)
            {
                cartItem = new Cart
                {
                    BookId      = book.Id,
                    CartId      = cart.ShoppingCartId,
                    Quantity    = 1,
                    DateCreated = DateTime.Now
                };
                _db.Carts.Add(cartItem);
            }
            else
            {
                cartItem.Quantity++;
            }
            _db.SaveChanges();
        }
Exemplo n.º 16
0
        public void AddToCart(BookListViewModel book, HttpContext context)
        {
            var cart = context.User.Identity.Name;

            var cartItem = (from item in _db.Carts
                            where item.Book.Id == book.Id && item.CartId == cart
                            select item).SingleOrDefault();


            if (cartItem == null)
            {
                cartItem = new The_Book_Cave.Data.EntityModels.Cart
                {
                    BookId      = book.Id,
                    CartId      = cart,
                    Quantity    = 1,
                    DateCreated = DateTime.Now
                };
                _db.Carts.Add(cartItem);
            }
            else
            {
                cartItem.Quantity++;
            }
            _db.SaveChanges();
        }
Exemplo n.º 17
0
 public AddEditBookPage()
 {
     _vm = DependencyService.Get <BookListViewModel>();
     InitializeComponent();
     BindingContext = _vm;
     this.Title     = "AddEditBookPage";
 }
Exemplo n.º 18
0
        public BooksListVmTests()
        {
            Books book1 = new();
            Books book2 = new();
            Books book3 = new();

            book1.Id     = 1;
            book1.Title  = "Maly Ksiaze";
            book1.Author = "Saint-Exupery";
            book1.Pages  = 120;
            book1.Genre  = 1;
            book1.Date_of_publication = date_1;
            book2.Id     = 2;
            book2.Title  = "Harry Potter and the Philosopher's Stone";
            book2.Author = "J. K. Rowling";
            book2.Pages  = 667;
            book2.Genre  = 3;
            book2.Date_of_publication = date_2;
            book3.Id     = 3;
            book3.Title  = "Chrobot";
            book3.Author = "Tomasz Michniewicz";
            book3.Pages  = 320;
            book3.Genre  = 6;
            book3.Date_of_publication = date_3;
            model = new BookListViewModel
            {
                Books = new ObservableCollection <Books>
                {
                    book1, book2, book3
                }
            };
        }
Exemplo n.º 19
0
        public IActionResult Index()
        {
            var listBook = new BookListViewModel();

            listBook.books = _bookRepository.GetAllBooks().Take(1);
            return(View(listBook));
        }
Exemplo n.º 20
0
        //首页
        public IActionResult Index(string category, int page = 1)
        {
            IEnumerable <BookDetails> books = null;

            //使用session获取书籍列表
            if (HttpContext.Session != null)
            {
                books = HttpContext.Session.Get <IEnumerable <BookDetails> >("bookDetails");
            }

            if (books == null)
            {
                books = this.LendingInfoDbContext.BookDetail;
                HttpContext.Session?.Set <IEnumerable <BookDetails> >("bookDetails", books);
            }

            BookListViewModel model = new BookListViewModel()
            {
                PagingInfo = new PagingInfo()
                {
                    ItemsPerPage = amout,
                    TotalItems   = books.Count(),
                    CurrentPage  = page
                },
                BookDetailses = books.OrderBy(b => b.FetchBookNumber).Skip((page - 1) * amout).Take(amout)
            };

            return(View(model));
        }
Exemplo n.º 21
0
 public ActionResult SearchBooks(BookListViewModel book)
 {
     if (book.Conditional != null)
     {
         var books = base.Facade.Book.GetBookByCategoryId(book.Conditional.CategoryID);
         var model = books.FirstOrDefault(r => r.PublisherId == book.Conditional.PublisherID);
         if (book.Conditional.PublisherID != 0)
         {
             if (model != null)
             {
                 var result = base.Facade.Book.GetBooksByTitle("Title like'%" + book.Conditional.Keyword + "%'");
                 if (result != null)
                 {
                     return(View(result));
                 }
                 else
                 {
                     //返回错误信息
                 }
             }
             else
             {
                 return(View(model));
             }
         }
         return(View(books));
     }
     return(View(book.Books));
 }
Exemplo n.º 22
0
        public ActionResult GetView()
        {
            BookListViewModel bookListViewModel = new BookListViewModel();

            BookBusinessLayer bookBusinessLayer = new BookBusinessLayer();

            List <Books>         books          = bookBusinessLayer.GetBooks();
            List <BookViewModel> bookViewModels = new List <BookViewModel>();

            foreach (Books book in books)
            {
                BookViewModel bookViewModel = new BookViewModel();
                bookViewModel.BookId = book.BookId;
                bookViewModel.Name   = book.name;
                bookViewModel.Author = book.author;
                bookViewModel.Price  = book.price;
                if (book.price > 10)
                {
                    bookViewModel.AuthorColor = "Red";
                }
                bookViewModels.Add(bookViewModel);
            }
            bookListViewModel.Books    = bookViewModels;
            bookListViewModel.UserName = "******";
            return(View("MyView", bookListViewModel));
        }
Exemplo n.º 23
0
        public ActionResult List(string specialization, int page = 1)
        {
            //2-per Page
            //(2-1)*2=2
            //(3-1)*2=4
            ViewBag.spec = specialization;
            var x = repo.Books.Where(b => b.Specialization == specialization).Skip((page - 1) * PageSize).Take(PageSize).Count();

            BookListViewModel m = new BookListViewModel
            {
                PagingInfo = new PagingInfo {
                    CurrentPage = page, ItemsPerPages = PageSize, TotalItems = repo.Books.Count()
                },
                Books = repo.Books.OrderBy(b => b.ISBN)
                        .Where(b => b.Specialization == null || b.Specialization == specialization)
                        .Skip((page - 1) * PageSize)
                        .Take(PageSize),
                CurrentSpecilization = specialization,

                SearchPagesNumber  = x,
                SpecializationColl = repo.Books.Select(b => b.Specialization).Distinct()
            };

            return(View("listall", m));
        }
Exemplo n.º 24
0
        public ViewResult BookView(string category, int pageno = 1)
        {
            BookListViewModel model = new BookListViewModel {
                Books = repository.Books
                        .Where(b => category == null || b.Category == category)
                        .OrderBy(b => b.ISBN)
                        .Skip((pageno - 1) * pageSize)
                        .Take(pageSize),
                PagingInfo = new PagingInfo {
                    CurrentPage  = pageno,
                    ItemsPerPage = pageSize,
                    TotalItems   = category == null?repository.Books.Count()
                                       : repository.Books
                                       .Where(b => b.Category == category).Count()
                },
                CurrentCategory = category
            };

            return(View(model));
            //return View(repository.Books
            // .OrderBy(b => b.ISBN)
            // .Skip((pageno - 1) * pageSize)
            // .Take(pageSize)
            // );
        }
Exemplo n.º 25
0
        public IActionResult BookSearchList(String BookId, String TitleP, String Title, String Author, String Year)
        {
            // Console.WriteLine(book.Title.GetType());
            var context  = new BookishContext();
            var booklist = context.Books.AsQueryable();

            if (!String.IsNullOrEmpty(BookId))
            {
                booklist = booklist.Where(s => s.BookId == Int32.Parse(BookId));
            }
            if (!String.IsNullOrEmpty(TitleP))
            {
                booklist = booklist.Where(s => s.Title.Contains(TitleP));
            }
            if (!String.IsNullOrEmpty(Title))
            {
                booklist = booklist.Where(s => s.Title == Title);
            }
            if (!String.IsNullOrEmpty(Author))
            {
                booklist = booklist.Where(s => s.Author.Contains(Author));
            }
            if (!String.IsNullOrEmpty(Year))
            {
                booklist = booklist.Where(s => s.Year == Int32.Parse(Year));
            }
            var books = booklist.OrderBy(x => x.Title).ToList();
            var list  = new BookListViewModel(books);

            return(View(list));
            // return RedirectToAction ("BookList");
        }
Exemplo n.º 26
0
        public ViewResult List(string specilization, int pagenum = 1)
        {
            BookListViewModel model = new BookListViewModel {
                Books =
                    repository.Books
                    .Where(b => specilization == null || b.Specizailation == specilization)
                    .OrderBy(b => b.ISBN)
                    .Skip((pagenum - 1) * PageSize)
                    .Take(PageSize)
                ,
                paginginfo = new PagingInfo
                {
                    CurrentPage = pagenum,
                    ItemPerPage = PageSize,
                    TotalItems  = specilization == null?repository.Books.Count() :
                                      repository.Books.Where(b => b.Specizailation == specilization).Count()
                },

                CurrentSpecilization = specilization
            };

            return(View(model));

            //return View(repository.Books
            //    .OrderBy(b =>b.ISBN)
            //    .Skip((pagenum-1)*PageSize)
            //   .Take(PageSize)

            //    );
        }
Exemplo n.º 27
0
        public void BookListViewModelBooksTest()
        {
            List<Book> books = new List<Book>()
            {
                new Book() { Title = "The Fellowship of the Ring" },
                new Book() { Title = "The Two Towers" }
            };

            MockBookListView bookListView = new MockBookListView();
            IList<BookDataModel> bookDataModels = new SynchronizingCollection<BookDataModel, Book>(books, b => new BookDataModel(b, dummyCommand));

            BookListViewModel bookListViewModel = new BookListViewModel(bookListView) { Books = bookDataModels };

            Assert.AreEqual(bookDataModels, bookListViewModel.Books);
            Assert.IsNull(bookListViewModel.SelectedBook);
            Assert.IsFalse(bookListViewModel.SelectedBooks.Any());

            // Select the first book
            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.SelectedBook,
                () => bookListViewModel.SelectedBook = bookDataModels.First());
            Assert.AreEqual(books.First(), bookListViewModel.SelectedBook.Book);

            bookListViewModel.AddSelectedBook(bookDataModels.First());
            Assert.IsTrue(bookListViewModel.SelectedBooks.SequenceEqual(new[] { bookDataModels.First() }));

            // Select both books
            bookListViewModel.AddSelectedBook(bookDataModels.Last());
            Assert.IsTrue(bookListViewModel.SelectedBooks.SequenceEqual(bookDataModels));
        }
Exemplo n.º 28
0
        public async Task <IActionResult> Index(string sortOrder, string direction, string searchString, string currentFilter, int?page)
        {
            BookListViewModel bookList = new BookListViewModel();

            bookList.Filter          = searchString;
            bookList.Order.Column    = sortOrder;
            bookList.Order.Direction = direction ?? "ASC";
            bookList.Page            = page ?? 1;
            if (bookList.Filter != null)
            {
                bookList.Page = 1;
            }
            else
            {
                bookList.Filter = currentFilter;
            }
            var books = _bookRepository.GetPage(bookList.Page, bookList.PageSize, (query) => ApplySortOrder(ApplyFilter(query, searchString), bookList.Order.Column, bookList.Order.Direction));

            bookList.Items = books.Select(x => new BookGridModel
            {
                Id            = x.Id,
                Caption       = x.Caption,
                PublishedDate = x.PublishedDate,
                Writers       = x.WriterBooks.Select(w => new WriterGridModel {
                    FullName = $"{w.Writer.LastName} {w.Writer.FirstName}", Id = w.Writer.Id
                }).ToList()
            }).ToList();
            bookList.TotalPages = (int)Math.Ceiling(books.TotalCount / (double)bookList.PageSize);
            return(View(bookList));
        }
Exemplo n.º 29
0
        public void Can_Send_Paginate_View_Mode()
        {
            Mock <IBookRepository> mock = new Mock <IBookRepository>();

            mock.Setup(b => b.Books).Returns(new Domain.Book[]
            {
                new Domain.Book {
                    BookID = 1, Title = "Operating System"
                },
                new Domain.Book {
                    BookID = 2, Title = "web Applicatons ASP.NET"
                },
                new Domain.Book {
                    BookID = 3, Title = "Android Mobile Applications"
                },
                new Domain.Book {
                    BookID = 4, Title = "Database System"
                },
                new Domain.Book {
                    BookID = 5, Title = "MIS"
                }
            }
                                             );
            BookController Controller = new BookController(mock.Object);

            Controller.PageSize = 3;
            BookListViewModel result   = (BookListViewModel)Controller.Pagination(null, 2).Model;
            PagingInfo        pageInfo = result.PagingInfo;

            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.Totalltems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Exemplo n.º 30
0
        public void Can_Paginate()
        {
            Mock <IBookRepository> mock = new Mock <IBookRepository>();

            mock.Setup(b => b.Books).Returns(new Domain.Book[]
            {
                new Domain.Book {
                    BookID = 1, Title = "Book1"
                },
                new Domain.Book {
                    BookID = 2, Title = "Book2"
                },
                new Domain.Book {
                    BookID = 3, Title = "Book3"
                },
                new Domain.Book {
                    BookID = 4, Title = "Book4"
                },
                new Domain.Book {
                    BookID = 5, Title = "Book5"
                }
            });
            BookController controller = new BookController(mock.Object);

            controller.PageSize = 3;
            BookListViewModel result = (BookListViewModel)controller.Pagination(null, 2).Model;
            //Book[] bookArray = result.Books.ToArray();
            //Assert.IsTrue(bookArray.Length == 2);
            //Assert.AreEqual(bookArray[0].Title, "Book4");
            //Assert.AreEqual(bookArray[1].Title, "Book5");
        }
Exemplo n.º 31
0
        public IActionResult Index(int page = 1)
        {
            IEnumerable <BookDetails> books = null;

            if (HttpContext.Session != null)
            {
                books = HttpContext.Session.Get <IEnumerable <BookDetails> >("bookDetails");
            }
            if (books == null)
            {
                books = _lendingInfoDbContext.BooksDetail.AsNoTracking();
                HttpContext.Session?.Set <IEnumerable <BookDetails> >("books", books);
            }
            BookListViewModel model = new BookListViewModel()
            {
                PagingInfo = new PagingInfo()
                {
                    ItemsPerPage = amout,
                    TotalItems   = books.Count(),
                    CurrentPage  = page,
                },
                BookDetails = books.OrderBy(b => b.FetchBookNumber).Skip((page - 1) * amout).Take(amout)
            };

            return(View(model));
        }
Exemplo n.º 32
0
 public BookController(IShellService shellService, IEntityService entityService,
     BookListViewModel bookListViewModel, BookViewModel bookViewModel, ExportFactory<LendToViewModel> lendToViewModelFactory)
 {
     this.shellService = shellService;
     this.entityService = entityService;
     this.bookListViewModel = bookListViewModel;
     this.bookViewModel = bookViewModel;
     this.lendToViewModelFactory = lendToViewModelFactory;
     this.addNewCommand = new DelegateCommand(AddNewBook, CanAddNewBook);
     this.removeCommand = new DelegateCommand(RemoveBook, CanRemoveBook);
     this.lendToCommand = new DelegateCommand(p => LendTo((Book)p));
 }
Exemplo n.º 33
0
        public void BookListViewModelCommandsTest()
        {
            MockBookListView bookListView = new MockBookListView();
            BookListViewModel bookListViewModel = new BookListViewModel(bookListView) { Books = new List<BookDataModel>() };

            DelegateCommand mockCommand = new DelegateCommand(() => { });
            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.AddNewCommand, () =>
                bookListViewModel.AddNewCommand = mockCommand);
            Assert.AreEqual(mockCommand, bookListViewModel.AddNewCommand);

            mockCommand = new DelegateCommand(() => { });
            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.RemoveCommand, () =>
                bookListViewModel.RemoveCommand = mockCommand);
            Assert.AreEqual(mockCommand, bookListViewModel.RemoveCommand);
        }
Exemplo n.º 34
0
        public void Initialize()
        {
            bookViewModel.LendToCommand = lendToCommand;
            AddWeakEventListener(bookViewModel, BookViewModelPropertyChanged);

            IBookListView bookListView = container.GetExportedValue<IBookListView>();
            bookDataModels = new SynchronizingCollection<BookDataModel, Book>(entityService.Books, 
                b => new BookDataModel(b, lendToCommand));
            bookListViewModel = new BookListViewModel(bookListView, bookDataModels);
            bookListViewModel.AddNewCommand = addNewCommand;
            bookListViewModel.RemoveCommand = removeCommand;
            AddWeakEventListener(bookListViewModel, BookListViewModelPropertyChanged);

            shellService.BookListView = bookListViewModel.View;
            shellService.BookView = bookViewModel.View;

            bookListViewModel.SelectedBook = bookListViewModel.Books.FirstOrDefault();
        }
Exemplo n.º 35
0
        public void BookListViewModelFilterTest()
        {
            IList<Book> books = new ObservableCollection<Book>()
            {
                new Book() { Title = "The Fellowship of the Ring", Author = "J.R.R. Tolkien" },
                new Book() { Title = "The Two Towers", Author = "J.R.R. Tolkien" }
            };

            MockBookListView bookListView = new MockBookListView();
            var bookDataModels = new SynchronizingCollection<BookDataModel, Book>(books, b => new BookDataModel(b, dummyCommand));
            BookListViewModel bookListViewModel = new BookListViewModel(bookListView) { Books = bookDataModels };

            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.FilterText, () => bookListViewModel.FilterText = "J.");
            Assert.AreEqual("J.", bookListViewModel.FilterText);
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "J.R.R. Tolkien";
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "Fell";
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "Tow";
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[1]));

            bookListViewModel.FilterText = "xyz";
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[0]));
            Assert.IsFalse(bookListViewModel.Filter(bookDataModels[1]));

            books.Add(new Book());
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[2]));
            books[2].Title = "Serenity, Vol 1: Those Left Behind";
            Assert.IsTrue(bookListViewModel.Filter(bookDataModels[2]));
        }
Exemplo n.º 36
0
 private void CheckCommand(ICommand command, BookListViewModel bookListViewModel, BookViewModel bookViewModel)
 {
     Assert.IsTrue(command.CanExecute(null));
     AssertHelper.CanExecuteChangedEvent(command, () => bookListViewModel.IsValid = false);
     Assert.IsFalse(command.CanExecute(null));
     AssertHelper.CanExecuteChangedEvent(command, () => bookListViewModel.IsValid = true);
     Assert.IsTrue(command.CanExecute(null));
     AssertHelper.CanExecuteChangedEvent(command, () => bookViewModel.IsValid = false);
     Assert.IsFalse(command.CanExecute(null));
     AssertHelper.CanExecuteChangedEvent(command, () => bookViewModel.IsValid = true);
     Assert.IsTrue(command.CanExecute(null));
 }