public void TestAddressInfo_ReturningExceptionViewForNotNullSessionId()
        {
            Mock <HttpSessionStateBase> session = new Mock <HttpSessionStateBase>();

            session.Setup(s => s["studentAddressId"]).Returns(2);

            Mock <HttpContextBase> httpContext = new Mock <HttpContextBase>();

            httpContext.SetupGet(c => c.Session).Returns(session.Object);

            ControllerContext ctx = new ControllerContext();

            ctx.HttpContext = httpContext.Object;

            Mock <IStudentAddressBusinessAccess> mock = new Mock <IStudentAddressBusinessAccess>();
            Exception exception = new Exception();

            mock.Setup(x => x.DisplayStudentAddressInfoByIdFromDatabase(2)).Throws(exception);

            AddressController addressController = new AddressController(mock.Object);

            addressController.ControllerContext = ctx;

            ViewResult result = addressController.AddressInfo() as ViewResult;

            Assert.That(result.ViewName, Is.EqualTo("Error"));
        }
        public void TestPostAddressInfo_ReturningCorrectView_ForNotNullStudentId()
        {
            Mock <HttpSessionStateBase> session = new Mock <HttpSessionStateBase>();

            session.Setup(s => s["studentAddressId"]).Returns(1);

            Mock <HttpContextBase> httpContext = new Mock <HttpContextBase>();

            httpContext.SetupGet(c => c.Session).Returns(session.Object);

            ControllerContext ctx = new ControllerContext();

            ctx.HttpContext = httpContext.Object;

            Mock <IStudentAddressBusinessAccess> mock = new Mock <IStudentAddressBusinessAccess>();

            mock.Setup(x => x.UpdateStudentAddressInfoIntoDatabase(student));

            AddressController addressController = new AddressController(mock.Object);

            addressController.ControllerContext = ctx;

            RedirectToRouteResult result = addressController.AddressInfo(student) as RedirectToRouteResult;

            Assert.That(result.RouteValues["action"], Is.EqualTo("QualificationInfo"));
        }
        public void TestPostAddressInfo_WhenModelStateIsInvalid()
        {
            AddressController addressController = new AddressController();

            addressController.ModelState.AddModelError("xyz", "Error has occured");

            ViewResult result = addressController.AddressInfo(student2) as ViewResult;

            Assert.That(result.ViewName, Is.EqualTo("AddressInfo"));
        }
        public void TestAddressInfo_ReturningCorrectViewForNullSessionId()
        {
            Mock <HttpSessionStateBase> session = new Mock <HttpSessionStateBase>();

            session.Setup(s => s["studentAddressId"]).Returns(null);

            Mock <HttpContextBase> httpContext = new Mock <HttpContextBase>();

            httpContext.SetupGet(c => c.Session).Returns(session.Object);

            ControllerContext ctx = new ControllerContext();

            ctx.HttpContext = httpContext.Object;

            AddressController addressController = new AddressController();

            addressController.ControllerContext = ctx;

            ViewResult result = addressController.AddressInfo() as ViewResult;

            Assert.That(result.ViewName, Is.EqualTo("AddressInfo"));
        }