public void TestIndexInstallmentBill() { var controller = new InstallmentBillsController(); var result = controller.Index() as ViewResult; var db = new DIENMAYQUYETTIENEntities1(); Assert.IsInstanceOfType(result.Model, typeof(List <InstallmentBill>)); Assert.AreEqual(db.InstallmentBills.Count(), ((List <InstallmentBill>)result.Model).Count); }
public void TestIndexInstallmentBill() { var controller = new InstallmentBillsController(); 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 <InstallmentBill>)); Assert.AreEqual(db.InstallmentBill.Count(), ((List <InstallmentBill>)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"]); }