Exemple #1
0
        public void Generate_Category_Specific_Tech_Count()
        {
            /// Организация (arrange)
            Mock <ITechRepository> mock = new Mock <ITechRepository>();

            mock.Setup(m => m.Teches).Returns(new List <Tech>
            {
                new Tech {
                    TechID = 1, Name = "Tech1", Category = "Cat1"
                },
                new Tech {
                    TechID = 2, Name = "Tech2", Category = "Cat2"
                },
                new Tech {
                    TechID = 3, Name = "Tech3", Category = "Cat1"
                },
                new Tech {
                    TechID = 4, Name = "Tech4", Category = "Cat2"
                },
                new Tech {
                    TechID = 5, Name = "Tech5", Category = "Cat3"
                }
            });
            TechController controller = new TechController(mock.Object);

            controller.pageSize = 3;

            // Действие - тестирование счетчиков товаров для различных категорий
            int res1   = ((TechListViewModel)controller.List("Cat1").Model).Paging_Info.TotalItems;
            int res2   = ((TechListViewModel)controller.List("Cat2").Model).Paging_Info.TotalItems;
            int res3   = ((TechListViewModel)controller.List("Cat3").Model).Paging_Info.TotalItems;
            int resAll = ((TechListViewModel)controller.List(null).Model).Paging_Info.TotalItems;

            // Утверждение
            Assert.AreEqual(res1, 2);
            Assert.AreEqual(res2, 2);
            Assert.AreEqual(res3, 1);
            Assert.AreEqual(resAll, 5);
        }
Exemple #2
0
        public void Can_Send_Pagination_View_Model()
        {
            // Организация (arrange)
            Mock <ITechRepository> mock = new Mock <ITechRepository>();

            mock.Setup(m => m.Teches).Returns(new List <Tech>
            {
                new Tech {
                    TechID = 1, Name = "Tech1"
                },
                new Tech {
                    TechID = 2, Name = "Tech2"
                },
                new Tech {
                    TechID = 3, Name = "Tech3"
                },
                new Tech {
                    TechID = 4, Name = "Tech4"
                },
                new Tech {
                    TechID = 5, Name = "Tech5"
                }
            });
            TechController controller = new TechController(mock.Object);

            controller.pageSize = 3;

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

            // Assert
            Paging_Info pageInfo = result.Paging_Info;

            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Exemple #3
0
        public void Can_in_Pages()
        {
            // Организация (arrange)
            Mock <ITechRepository> mock = new Mock <ITechRepository>();

            mock.Setup(m => m.Teches).Returns(new List <Tech>
            {
                new Tech {
                    TechID = 1, Name = "Tech1"
                },
                new Tech {
                    TechID = 2, Name = "Tech2"
                },
                new Tech {
                    TechID = 3, Name = "Tech3"
                },
                new Tech {
                    TechID = 4, Name = "Tech4"
                },
                new Tech {
                    TechID = 5, Name = "Tech5"
                }
            });
            TechController controller = new TechController(mock.Object);

            controller.pageSize = 3;

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

            // Утверждение
            List <Tech> ta = result.Teches.ToList();

            Assert.IsTrue(ta.Count == 2);
            Assert.AreEqual(ta[0].Name, "Tech4");
            Assert.AreEqual(ta[1].Name, "Tech5");
        }
Exemple #4
0
        public void Can_Filter_Games()
        {
            // Организация (arrange)
            Mock <ITechRepository> mock = new Mock <ITechRepository>();

            mock.Setup(m => m.Teches).Returns(new List <Tech>
            {
                new Tech {
                    TechID = 1, Name = "Tech1", Category = "Cat1"
                },
                new Tech {
                    TechID = 2, Name = "Tech2", Category = "Cat2"
                },
                new Tech {
                    TechID = 3, Name = "Tech3", Category = "Cat1"
                },
                new Tech {
                    TechID = 4, Name = "Tech4", Category = "Cat2"
                },
                new Tech {
                    TechID = 5, Name = "Tech5", Category = "Cat3"
                }
            });
            TechController controller = new TechController(mock.Object);

            controller.pageSize = 3;

            // Action
            List <Tech> result = ((TechListViewModel)controller.List("Cat2", 1).Model)
                                 .Teches.ToList();

            // Assert
            Assert.AreEqual(result.Count(), 2);
            Assert.IsTrue(result[0].Name == "Tech2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "Tech4" && result[1].Category == "Cat2");
        }