コード例 #1
0
        public void TestInsufficientRights()
        {
            HotelBookingSystemData data = new HotelBookingSystemData();
            RoomsController controller = new RoomsController(data, new User("hackSerA", "password", Roles.User));

            controller.Add(1, 1, 1);
        }
コード例 #2
0
        public void TestLoggedInUser()
        {
            HotelBookingSystemData data = new HotelBookingSystemData();
            UsersController controller = new UsersController(data, null);

            controller.Logout();
        }
コード例 #3
0
        public void Run()
        {
            var database = new HotelBookingSystemData();
            User currentUser = null;

            while (true)
            {
                string url = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(url))
                {
                    break;
                }

                var executionEndpoint = new Endpoint(url);

                var controllerType = Assembly
                                     .GetExecutingAssembly()
                                     .GetTypes()
                                     .FirstOrDefault(type => type.Name == executionEndpoint.ControllerName);

                var controller = Activator.CreateInstance(controllerType, database, currentUser) as Controller;
                var action = controllerType.GetMethod(executionEndpoint.ActionName);
                object[] parameters = MapParameters(executionEndpoint, action);
                string viewResult = string.Empty;

                try
                {
                    var view = action.Invoke(controller, parameters) as IView;
                    viewResult = view.Display();
                    currentUser = controller.CurrentUser;
                }
                catch (Exception ex)
                {
                    viewResult = new Error(ex.InnerException.Message).Display();
                }

                Console.WriteLine(viewResult);
            }
        }