예제 #1
0
        public void CreateTest()
        {
            var controller = new ProductAdminController();
            var db         = new DmQT06Entities1();
            var result     = controller.Create() as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.ViewData["product.ID"], typeof(SelectList));
        }
예제 #2
0
        public void TestIndex()
        {
            var controller = new ProductAdminController();
            var context    = new Mock <HttpContextBase>();
            var session    = new Mock <HttpSessionStateBase>();

            context.Setup(c => c.Session).Returns(session.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);
            session.Setup(s => s["Username"]).Returns("abc");

            var result = controller.Index() as ViewResult;
            var db     = new DmQT06Entities1();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(List <Product>));
            Assert.AreEqual(db.Product.Count(), ((List <Product>)result.Model).Count);
            session.Setup(s => s["Username"]).Returns("null");
        }
        public ActionResult Login(Account acc)
        {
            if (ModelState.IsValid)
            {
                using (DmQT06Entities1 db = new DmQT06Entities1())
                {
                    var obj = db.Account.Where(a => a.UserName.Equals(acc.UserName) && a.PassWord.Equals(acc.PassWord)).FirstOrDefault();

                    if (obj != null)
                    {
                        Session["Username"] = obj.UserName.ToString();
                        Session["FullName"] = obj.FullName.ToString();
                        return(RedirectToAction("Index"));
                    }
                }
            }
            return(View(acc));
        }
예제 #4
0
        public void TestIndexCashBill()
        {
            var controller = new CashbillAdminController();
            var context    = new Mock <HttpContextBase>();
            var session    = new Mock <HttpSessionStateBase>();

            context.Setup(c => c.Session).Returns(session.Object);
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);
            session.Setup(s => s["Username"]).Returns("abc");

            var result = controller.Index() as ViewResult;
            var db     = new DmQT06Entities1();


            //Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(List <CashBill>));
            Assert.AreEqual(db.CashBill.Count(), ((List <CashBill>)result.Model).Count);

            session.Setup(s => s["Username"]).Returns(null);
            var redirect = controller.Index() as RedirectToRouteResult;

            //Assert.AreEqual("Login", redirect.RouteValues["controller"]);
            Assert.AreEqual("Login", redirect.RouteValues["action"]);
        }