예제 #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);
        }
예제 #2
0
        public void ResponseOk()
        {
            var mockApproveUser = University.GetUser("e101");

            //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);

            PaymentResponseSuccess pr = new PaymentResponseSuccess()
            {
                amount    = application.Quota.StickerFee,
                TransId   = "TEST-Transaction-001",
                ReturnOid = application.ID.ToString() + "-TestOrder",
                mdStatus  = 4,
                Response  = "success"
            };

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

            Assert.IsNotNull(result);
            Assert.AreEqual("Sticker", result.RouteValues["controller"]);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.IsNotNull(result.RouteValues["paymentok"]);

            //get updated list to be sure application status is not updated
            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.WaitingForDelivery, applicationR.Status);
        }
예제 #3
0
        public void ApplyPost()
        {
            var mockUser    = University.GetUser("a101");
            var stickerType = University.GetStickerTypes(mockUser.Category).FirstOrDefault();
            var mockData    = new StickerApplication
            {
                SelectedType = stickerType.ID.ToString(),
                Vehicle      = new Vehicle {
                    OwnerName = "Test Owner", PlateNumber = "06ZZ1234", RegistrationNumber = "ZZ123456"
                }
            };

            StickerController controller = new StickerController();

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

            RedirectToRouteResult result = controller.Apply(mockData) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("1", result.RouteValues["ok"]);
            Assert.AreEqual("Index", result.RouteValues["action"]);

            ViewResult indexResult = controller.Index() as ViewResult;

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

            List <StickerApplication> model = indexResult.Model as List <StickerApplication>;

            Assert.AreNotEqual(0, model.Count);
            Assert.AreEqual("06ZZ1234", model.FirstOrDefault().Vehicle.PlateNumber);
        }
예제 #4
0
        public void IndexFilteredThenApprove()
        {
            var mockApproveUser = University.GetUser("o101");

            ApproveController controller = new ApproveController();

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

            //get list
            ViewResult result = controller.Index("", "", "Test Student11", 1) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(PagedList <StickerApplication>));

            PagedList <StickerApplication> model = result.Model as PagedList <StickerApplication>;

            Assert.AreEqual(0, model.Where(a => a.Status != StickerApplicationStatus.WaitingForApproval).Count());
            Assert.AreEqual(1, model.Count);

            //approve
            StickerApplication       stickerApplication = model.FirstOrDefault();
            List <ApprovementOption> approvementOptions = stickerApplication.GetApprovementOptions();

            Assert.AreEqual(2, approvementOptions.Count);
            ApprovementOption otherOption = approvementOptions.Where(a => a.QuotaID != stickerApplication.Quota.ID).FirstOrDefault();

            controller.Approve(stickerApplication.ID, otherOption.QuotaID);

            //get list
            result = controller.Index("", "", "Test Student11", 1) as ViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(PagedList <StickerApplication>));
            model = result.Model as PagedList <StickerApplication>;
            Assert.AreEqual(0, model.Count);

            //applications index page for user
            StickerController scontroller = new StickerController
            {
                ControllerContext = new ControllerContext(MockAuthContext(University.GetUser(stickerApplication.User.UID)).Object, new RouteData(), controller)
            };
            ViewResult sresult = scontroller.Index() as ViewResult;

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

            List <StickerApplication> smodel = sresult.Model as List <StickerApplication>;

            Assert.AreNotEqual(0, smodel.Count);
            Assert.AreEqual(StickerApplicationStatus.WaitingForPayment, smodel.FirstOrDefault().Status);
        }
예제 #5
0
        public void ApplyRenew()
        {
            var mockUser    = University.GetUser("e103");
            var stickerType = University.GetStickerTypes(mockUser.Category).FirstOrDefault();

            StickerController controller = new StickerController();

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

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(List <StickerApplication>));
            StickerApplication oldApplication = ((List <StickerApplication>)result.Model).FirstOrDefault();

            Assert.IsNotNull(oldApplication);
            Assert.IsTrue(oldApplication.Term.IsExpired);

            RedirectToRouteResult renewResult = controller.Renew(oldApplication.ID) as RedirectToRouteResult;

            Assert.AreEqual("1", renewResult.RouteValues["ok"]);
            Assert.AreEqual("Index", renewResult.RouteValues["action"]);

            result = controller.Index() as ViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(List <StickerApplication>));
            List <StickerApplication> applications = result.Model as List <StickerApplication>;

            Assert.AreEqual(2, applications.Count);

            StickerApplication newApplication = applications.FirstOrDefault(a => a.ID != oldApplication.ID);

            oldApplication = applications.FirstOrDefault(a => a.ID == oldApplication.ID);
            Assert.IsFalse(newApplication.Term.IsExpired);
            Assert.AreEqual(StickerApplicationStatus.Expired, oldApplication.Status);
            Assert.AreEqual(StickerApplicationStatus.WaitingForApproval, newApplication.Status);
        }
예제 #6
0
        public void IndexFilteredThenApprove()
        {
            var mockDeliverUser = University.GetUser("o102");

            DeliverController controller = new DeliverController();

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

            //get list
            ViewResult result = controller.Index("", "", "Test Student13", 1) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(PagedList <StickerApplication>));

            PagedList <StickerApplication> model = result.Model as PagedList <StickerApplication>;

            Assert.AreEqual(0, model.Where(a => a.Status != StickerApplicationStatus.WaitingForDelivery).Count());
            Assert.AreEqual(1, model.Count);

            //deliver
            StickerApplication stickerApplication = model.FirstOrDefault();

            controller.Deliver(stickerApplication.ID, new Sticker {
                SerialNumber = 1
            });

            //get list
            result = controller.Index("", "", "Test Student13", 1) as ViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(PagedList <StickerApplication>));
            model = result.Model as PagedList <StickerApplication>;
            Assert.AreEqual(0, model.Count);

            //applications index page for user
            StickerController scontroller = new StickerController
            {
                ControllerContext = new ControllerContext(MockAuthContext(University.GetUser(stickerApplication.User.UID)).Object, new RouteData(), controller)
            };
            ViewResult sresult = scontroller.Index() as ViewResult;

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

            List <StickerApplication> smodel = sresult.Model as List <StickerApplication>;

            Assert.AreNotEqual(0, smodel.Count);
            Assert.AreEqual(StickerApplicationStatus.Active, smodel.FirstOrDefault().Status);
            Assert.AreEqual(1, smodel.FirstOrDefault().Sticker.SerialNumber);
        }
예제 #7
0
        public void InvalidateSticker()
        {
            var mockUser = University.GetUser("o103");

            InvalidateController controller = new InvalidateController();

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

            ViewResult result = controller.Index("", "", "", 1) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(PagedList <StickerApplication>));
            PagedList <StickerApplication> applications = result.Model as PagedList <StickerApplication>;

            Assert.IsTrue(applications.Count > 0, "No active stickers found");
            StickerApplication application = applications.FirstOrDefault();

            Assert.IsNotNull(application);
            Assert.AreEqual(StickerApplicationStatus.Active, application.Status);
            StickerApplication invalidatedApplication = application;

            RedirectToRouteResult invalidateResult = controller.Invalidate(application.ID) as RedirectToRouteResult;

            Assert.AreEqual(1, invalidateResult.RouteValues["success"]);
            Assert.AreEqual("Index", invalidateResult.RouteValues["action"]);

            result = controller.Index("", "", "", 1) as ViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(PagedList <StickerApplication>));
            applications = result.Model as PagedList <StickerApplication>;
            StickerApplication testApplication = applications.FirstOrDefault(a => a.ID == invalidatedApplication.ID);

            Assert.IsNull(testApplication, "Invalidated sticker still listed as Active");

            //applications index page for user
            StickerController scontroller = new StickerController
            {
                ControllerContext = new ControllerContext(MockAuthContext(University.GetUser(invalidatedApplication.User.UID)).Object, new RouteData(), controller)
            };
            ViewResult sresult = scontroller.Index() as ViewResult;

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

            List <StickerApplication> smodel = sresult.Model as List <StickerApplication>;

            Assert.AreNotEqual(0, smodel.Count);
            Assert.AreEqual(StickerApplicationStatus.Invalidated, smodel.FirstOrDefault().Status);
        }
예제 #8
0
        public void IndexWithDataTest()
        {
            var mockUser = University.GetUser("e100");

            StickerController controller = new StickerController();

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

            ViewResult result = controller.Index() as ViewResult;

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

            List <StickerApplication> model = result.Model as List <StickerApplication>;

            Assert.AreNotEqual(0, model.Count);
            Assert.AreEqual(1, model.FirstOrDefault().ID);
        }
예제 #9
0
        public void IndexWithoutData()
        {
            var mockUser = new User()
            {
                UID = "e100"
            };
            var mockData  = new List <StickerApplication>();
            var mockDbSet = new Mock <DbSet <StickerApplication> >().SetupData(mockData);
            var dbctx     = new Mock <DatabaseContext>();

            dbctx.Setup(c => c.StickerApplications).Returns(mockDbSet.Object);

            StickerController controller = new StickerController(dbctx.Object);

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

            RedirectToRouteResult result = controller.Index() as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("action", result.RouteValues.Keys.FirstOrDefault());
            Assert.AreEqual("Apply", result.RouteValues.Values.FirstOrDefault());
        }
예제 #10
0
        public void Index()
        {
            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);

            PayController controller = new PayController();

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

            ViewResult result = controller.Index(application.ID) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(PaymentRequest));

            PaymentRequest model = result.Model as PaymentRequest;

            Assert.IsNotNull(model.Application);
            Assert.IsNotNull(model.Application.Quota);
            Assert.IsNotNull(model.Application.Quota.StickerFee);
            Assert.AreEqual(model.Application.Quota.StickerFee, application.Quota.StickerFee);
        }