示例#1
0
        public void TestCreateG()
        {
            var controller = new SanPhamsController();

            var result = controller.Create() as ViewResult;

            Assert.IsNotNull(result);
        }
示例#2
0
        public void TestIndex2()
        {
            var controller = new SanPhamsController();

            var result = controller.Index2() as ViewResult;

            Assert.IsNotNull(result);

            var model = result.Model as List <SanPham>;

            Assert.IsNotNull(model);

            var db = new CT25Team19Entities();

            Assert.AreEqual(db.SanPhams.Count(), model.Count);
        }
示例#3
0
        public void TestEditP()
        {
            var rand    = new Random();
            var product = new SanPham
            {
                TenSP   = rand.NextDouble().ToString(),
                SoLuong = -rand.Next(),
                DonGia  = -rand.Next()
            };

            var controller = new SanPhamsController();
            var result0    = controller.Edit(product) as ViewResult;

            Assert.IsNotNull(result0);
            Assert.AreEqual("Đơn giá phải lớn hơn 0", controller.ModelState["DonGia"].Errors[0].ErrorMessage);
            Assert.AreEqual("Số lượng phải lớn hơn 0", controller.ModelState["SoLuong"].Errors[0].ErrorMessage);
        }
示例#4
0
        public void TestSearch()
        {
            var db       = new CT25Team19Entities();
            var products = db.SanPhams.ToList();
            var keyword  = products.First().TenSP.Split().First();

            products = products.Where(p => p.TenSP.ToLower().Contains(keyword.ToLower())).ToList();

            var controller = new SanPhamsController();
            var result     = controller.Search(keyword) as ViewResult;

            Assert.IsNotNull(result);

            var model = result.Model as List <SanPham>;

            Assert.IsNotNull(model);

            Assert.AreEqual("Index2", result.ViewName);
            Assert.AreEqual(products.Count(), model.Count);
            Assert.AreEqual(keyword, result.ViewData["keyword"]);
        }
示例#5
0
        public void TestEditG()
        {
            var controller = new SanPhamsController();
            var result0    = controller.Edit(ToString()) as HttpNotFoundResult;

            Assert.IsNotNull(result0);

            var db      = new CT25Team19Entities();
            var product = db.SanPhams.First();
            var result  = controller.Edit(product.MaSP) as ViewResult;

            Assert.IsNotNull(result);

            var model = result.Model as SanPham;

            Assert.IsNotNull(model);
            Assert.AreEqual(product.MaSP, model.MaSP);
            Assert.AreEqual(product.TenSP, model.TenSP);
            Assert.AreEqual(product.SoLuong, model.SoLuong);
            Assert.AreEqual(product.MaLoaiSP, model.MaLoaiSP);
            Assert.AreEqual(product.Mau, model.Mau);
            Assert.AreEqual(product.HinhAnh, model.HinhAnh);
            Assert.AreEqual(product.Size, model.Size);
        }