コード例 #1
0
        public void ApplyWithAuth()
        {
            var visitor = new Visitor
            {
                Description = "For testing purpose",
                Email       = "*****@*****.**",
                Name        = "Test Person",
                VisitDate   = DateTime.Today,
                User        = null,
                Vehicle     = new Vehicle {
                    OwnerName = "Test Owner", PlateNumber = "06AB123", RegistrationNumber = "AB12313", Type = VehicleType.Car
                }
            };

            var mockUser         = University.GetUser("e101");
            VisitorController vc = new VisitorController();

            vc.ControllerContext = new ControllerContext(MockAuthContext(mockUser).Object, new RouteData(), vc);
            RedirectToRouteResult actionResult = vc.Apply(visitor) as RedirectToRouteResult;

            Assert.IsNotNull(actionResult);
            Assert.AreEqual("List", actionResult.RouteValues["action"]);
            Assert.AreEqual("Visitor", actionResult.RouteValues["controller"]);
            Assert.AreEqual(1, actionResult.RouteValues["success"]);
        }
コード例 #2
0
        public void ApplyIndex()
        {
            VisitorController vc           = new VisitorController();
            ViewResult        actionResult = vc.Apply() as ViewResult;

            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(actionResult.Model);
            Assert.IsInstanceOfType(actionResult.Model, typeof(Visitor));
        }
コード例 #3
0
        public void ApplyWithInvalidModel()
        {
            VisitorController vc = new VisitorController();

            vc.ModelState.AddModelError("test", "error");
            EmptyResult actionResult = vc.Apply(new Visitor()) as EmptyResult;

            Assert.IsNotNull(actionResult);
        }
コード例 #4
0
        public void ApplyThenDetail()
        {
            var visitor = new Visitor
            {
                Description = "For testing purpose",
                Email       = "*****@*****.**",
                Name        = "Test Person",
                VisitDate   = DateTime.Today,
                User        = new User()
                {
                    UID = "e101"
                },
                Vehicle = new Vehicle {
                    OwnerName = "Test Owner", PlateNumber = "06AB123", RegistrationNumber = "AB12313", Type = VehicleType.Car
                }
            };

            VisitorController     vc           = new VisitorController();
            RedirectToRouteResult actionResult = vc.Apply(visitor) as RedirectToRouteResult;

            Assert.IsNotNull(actionResult);
            Assert.AreEqual("Detail", actionResult.RouteValues["action"]);
            Assert.AreEqual("Visitor", actionResult.RouteValues["controller"]);
            Assert.IsNotNull(actionResult.RouteValues["UID"]);
            Assert.AreEqual(1, actionResult.RouteValues["success"]);

            ViewResult viewResult = vc.Detail(actionResult.RouteValues["UID"].ToString()) as ViewResult;

            Assert.IsNotNull(viewResult);
            Assert.IsInstanceOfType(viewResult.Model, typeof(Visitor));
            Visitor model = viewResult.Model as Visitor;

            Assert.AreEqual(visitor.Name, model.Name);
            Assert.AreEqual(visitor.Email, model.Email);
            Assert.AreEqual(VisitorStatus.WaitingForApproval, model.Status);
        }
コード例 #5
0
        public void ApplyWithAlreadyRequestedVehicle()
        {
            var visitor = new Visitor
            {
                Description = "For testing purpose",
                Email       = "*****@*****.**",
                Name        = "Test Person",
                VisitDate   = DateTime.Today,
                User        = new User()
                {
                    UID = "e101"
                },
                Vehicle = new Vehicle {
                    OwnerName = "Test Owner", PlateNumber = "06BB100", RegistrationNumber = "AB12313", Type = VehicleType.Car
                }
            };

            VisitorController vc           = new VisitorController();
            ViewResult        actionResult = vc.Apply(visitor) as ViewResult;

            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(actionResult.ViewBag.ErrorMessage);
            Console.Out.WriteLine(actionResult.ViewBag.ErrorMessage);
        }