Exemplo n.º 1
0
        public ViewResult List(string category, int page = 1)
        {
            SerialsListViewModel model = new SerialsListViewModel
            {
                Serials = repository.Serials
                          .Where(p => category == null || p.Category == category)
                          .OrderBy(serial => serial.Id)
                          .Skip((page - 1) * pageSize)
                          .Take(pageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = category == null?
                                   repository.Serials.Count() :
                                       repository.Serials.Where(game => game.Category == category).Count()
                },
                CurrentCategory = category
            };
            string result = "Вы не авторизованы";

            if (User.Identity.IsAuthenticated)
            {
                result = "Здравствуйте, " + User.Identity.Name;
            }
            ViewBag.Authenticated = result;
            return(View(model));
        }
Exemplo n.º 2
0
        public ViewResult Search(string Search)
        {
            SerialsListViewModel model = new SerialsListViewModel
            {
                Serials         = repository.Serials.Where(p => p.Serial_title.Contains(Search)),
                PagingInfo      = null,
                CurrentCategory = null
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public void Can_Send_Pagination_View_Model()
        {
            // Организация (arrange)
            Mock <ISerialRepository> mock = new Mock <ISerialRepository>();

            mock.Setup(m => m.Serials).Returns(new List <Serial>
            {
                new Serial {
                    Id = 1, Serial_title = "Сериал1", Seasons = { new Season {
                                                                      Season_title = "второй сезон 2008"
                                                                  } }
                },
                new Serial {
                    Id = 2, Serial_title = "Сериал2"
                },
                new Serial {
                    Id = 3, Serial_title = "Сериал3"
                },
                new Serial {
                    Id = 4, Serial_title = "Сериал4"
                },
                new Serial {
                    Id = 5, Serial_title = "Сериал5"
                }
            });
            SerialController controller = new SerialController(mock.Object);

            controller.pageSize = 3;

            // Act
            SerialsListViewModel result
                = (SerialsListViewModel)controller.List(null, 2).Model;

            // Assert
            PagingInfo pageInfo = result.PagingInfo;

            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Exemplo n.º 4
0
        public void Can_Paginate()
        {
            // Организация (arrange)
            Mock <ISerialRepository> mock = new Mock <ISerialRepository>();

            mock.Setup(m => m.Serials).Returns(new List <Serial>
            {
                new Serial {
                    Id = 1, Serial_title = "Сериал1", Seasons = { new Season {
                                                                      Season_title = "второй сезон 2008"
                                                                  } }
                },
                new Serial {
                    Id = 2, Serial_title = "Сериал2"
                },
                new Serial {
                    Id = 3, Serial_title = "Сериал3"
                },
                new Serial {
                    Id = 4, Serial_title = "Сериал4"
                },
                new Serial {
                    Id = 5, Serial_title = "Сериал5"
                }
            });
            SerialController controller = new SerialController(mock.Object);

            controller.pageSize = 3;

            // Действие (act)
            SerialsListViewModel result = (SerialsListViewModel)controller.List(null, 2).Model;

            // Утверждение
            List <Serial> serials = result.Serials.ToList();

            Assert.IsTrue(serials.Count == 2);
            Assert.AreEqual(serials[0].Serial_title, "Сериал4");
            Assert.AreEqual(serials[1].Serial_title, "Сериал5");
        }