Example #1
0
        public void ResponseFail()
        {
            var mockApproveUser = University.GetUser("e201");

            //get Applications
            StickerController sc = new StickerController();

            sc.ControllerContext = new ControllerContext(MockAuthContext(mockApproveUser).Object, new RouteData(), sc);
            ViewResult indexResult = sc.Index() as ViewResult;

            Assert.IsNotNull(indexResult);
            Assert.IsInstanceOfType(indexResult.Model, typeof(List <StickerApplication>));

            //find application waiting for payment
            List <StickerApplication> listModel = indexResult.Model as List <StickerApplication>;

            Assert.AreNotEqual(0, listModel.Count);
            StickerApplication application = listModel.Find(m => m.Status == StickerApplicationStatus.WaitingForPayment);

            Assert.IsNotNull(application);
            Assert.AreEqual(StickerApplicationStatus.WaitingForPayment, application.Status);

            //pay
            PayController controller = new PayController();

            controller.ControllerContext = new ControllerContext(MockAuthContext(mockApproveUser).Object, new RouteData(), controller);

            PaymentResponseFail pr = new PaymentResponseFail()
            {
                TransId   = "TEST-Transaction-002",
                ReturnOid = application.ID.ToString() + "-TestOrder",
                mdStatus  = 4,
                Response  = "error",
                ErrMsg    = "Test Error Message"
            };

            RedirectToRouteResult result = controller.Fail(pr) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Pay", result.RouteValues["controller"]);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual(application.ID.ToString(), result.RouteValues["Id"]);
            Assert.IsNotNull(result.RouteValues["hasError"]);

            //get updated list
            ViewResult indexResultR = sc.Index() as ViewResult;

            Assert.IsNotNull(indexResultR);
            Assert.IsInstanceOfType(indexResultR.Model, typeof(List <StickerApplication>));
            List <StickerApplication> listModelR = indexResultR.Model as List <StickerApplication>;

            Assert.AreNotEqual(0, listModelR.Count);
            StickerApplication applicationR = listModelR.Find(m => m.ID == application.ID);

            Assert.IsNotNull(applicationR);
            Assert.AreEqual(StickerApplicationStatus.WaitingForPayment, applicationR.Status);
        }
Example #2
0
 public ActionResult Fail(PaymentResponseFail resp)
 {
     Trace.WriteLine("POST /Pay/Fail");
     if (resp != null && resp.ProcReturnCode == "51")
     {
         return(RedirectToAction("Index", "Pay", new { Id = resp.ApplicationId, insufficientFunds = "1" }));
     }
     else if (resp != null)
     {
         return(RedirectToAction("Index", "Pay", new { Id = resp.ApplicationId, hasError = "1" }));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }