public void Generate_Category_Specific_Game_Count() { /// Организация (arrange) Mock <ISerialRepository> mock = new Mock <ISerialRepository>(); mock.Setup(m => m.Serials).Returns(new List <Serial> { new Serial { Id = 1, Serial_title = "Игра1", Category = "Cat1" }, new Serial { Id = 2, Serial_title = "Игра2", Category = "Cat2" }, new Serial { Id = 3, Serial_title = "Игра3", Category = "Cat1" }, new Serial { Id = 4, Serial_title = "Игра4", Category = "Cat2" }, new Serial { Id = 5, Serial_title = "Игра5", Category = "Cat3" } }); SerialController controller = new SerialController(mock.Object); controller.pageSize = 3; // Действие - тестирование счетчиков товаров для различных категорий int res1 = ((SerialsListViewModel)controller.List("Cat1").Model).PagingInfo.TotalItems; int res2 = ((SerialsListViewModel)controller.List("Cat2").Model).PagingInfo.TotalItems; int res3 = ((SerialsListViewModel)controller.List("Cat3").Model).PagingInfo.TotalItems; int resAll = ((SerialsListViewModel)controller.List(null).Model).PagingInfo.TotalItems; // Утверждение Assert.AreEqual(res1, 2); Assert.AreEqual(res2, 2); Assert.AreEqual(res3, 1); Assert.AreEqual(resAll, 5); }
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); }
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"); }
public void Can_Filter_Games() { // Организация (arrange) Mock <ISerialRepository> mock = new Mock <ISerialRepository>(); mock.Setup(m => m.Serials).Returns(new List <Serial> { new Serial { Id = 1, Serial_title = "Сериал1", Category = "Cat1" }, new Serial { Id = 2, Serial_title = "Сериал2", Category = "Cat2" }, new Serial { Id = 3, Serial_title = "Сериал3", Category = "Cat1" }, new Serial { Id = 4, Serial_title = "Сериал4", Category = "Cat2" }, new Serial { Id = 5, Serial_title = "Сериал5", Category = "Cat3" } }); SerialController controller = new SerialController(mock.Object); controller.pageSize = 3; // Action List <Serial> result = ((SerialsListViewModel)controller.List("Cat2", 1).Model) .Serials.ToList(); // Assert Assert.AreEqual(result.Count(), 2); Assert.IsTrue(result[0].Serial_title == "Сериал2" && result[0].Category == "Cat2"); Assert.IsTrue(result[1].Serial_title == "Сериал4" && result[1].Category == "Cat2"); }