public void Run()
        {
            var data = new BangaloreUniversityData();
            User user = null;
            while (true)
            {
                string inputLine = Console.ReadLine();
                if (inputLine == null)
                {
                    break;
                }

                var route = new Route(inputLine);
                var controllerType =
                    Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(type => type.Name == route.ControllerName);
                var controller = Activator.CreateInstance(controllerType, data, user) as Controller;
                var action = controllerType.GetMethod(route.ActionName);
                object[] @params = MapParameters(route, action);
                try
                {
                    var view = action.Invoke(controller, @params) as IView;
                    Console.WriteLine(view.Display());
                    user = controller.User;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
            }
        }
        public void TestLogoutWithWrongUserRoleShouldReturnAppropriateMessage()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Guest);
            UsersController controller = new UsersController(data, user);

            controller.Logout().Display();
        }
        public void TestLogoutIfNoUserIsLoggedInShouldReturnAppropriateMessage()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Lecturer);
            UsersController controller = new UsersController(data, null);

            controller.Logout().Display();
        }
        public void TestSuccessfullLogoutShouldReturnAppropriateMessage()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Lecturer);
            UsersController controller = new UsersController(data, user);

            string message = controller.Logout().Display();

            Assert.AreEqual("User firstLecturer logged out successfully.", message);
        }
Beispiel #5
0
        public void TestWithNoCourses()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Guest);
            CoursesController controller = new CoursesController(data, user);

            string message = controller.All().Display();

            Assert.AreEqual("No courses.", message);
        }
        public void TestLogout_InitializeNullUser_ShouldThrow()
        {
            // Arrange
            User user = null;
            var database = new BangaloreUniversityData();
            var controller = new UsersController(database, user);

            // Act
            controller.Logout();

            // Assert
        }
        public void TestLogout_InitializeGuestUser_ShouldThrow()
        {
            // Arrange
            User user = new User("gosho", "123456", Role.Guest);
            var database = new BangaloreUniversityData();
            var controller = new UsersController(database, user);

            // Act
            controller.Logout();

            // Assert
        }
        public void TestLogout_LogoutValidUser_CurrentUserShouldBeNull()
        {
            // Arrange
            User user = new User("gosho", "123456", Role.Lecturer);
            var database = new BangaloreUniversityData();
            var controller = new UsersController(database, user);

            // Act
            controller.Logout();

            // Assert
            Assert.IsNull(controller.User, "User should be null.");
        }
        public void Run()
        {
            var database = new BangaloreUniversityData();
            User currentUser = null;

            while (true)
            {
                string routeUrl = Console.ReadLine();
                if (routeUrl == null)
                {
                    break;
                }

                var route = new Route(routeUrl);
                var expectedController = route.ControllerName;
                var controllerType = Assembly.GetExecutingAssembly()
                    .GetTypes()
                    .FirstOrDefault(type => type.Name == expectedController);

                var controller = Activator.CreateInstance(controllerType, database, currentUser) as Controller;

                var action = controllerType.GetMethod(route.ActionName);
                var argumentsToPass = MapParameters(route, action);
                try
                {
                    var view = action.Invoke(controller, argumentsToPass) as IView;

                    var output = view.Display();
                    Console.WriteLine(output);

                    currentUser = controller.CurrentUser;
                }
                catch (Exception ex)
                {
                    if (ex.InnerException is ArgumentException || ex.InnerException is AuthorizationFailedException)
                    {
                        Console.WriteLine(ex.InnerException.Message);
                    }
                    else
                    {
                        throw ex.InnerException;
                    }
                }
            }
        }
Beispiel #10
0
        public void TestWithOneCourseAndNoStudents()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Lecturer);
            CoursesController controller = new CoursesController(data, user);

            controller.Create("Object-Oriented+Programming");
            string message = controller.All().Display();

            var courses = new StringBuilder();
            courses.AppendLine("All courses:");
            foreach (var course in data.Courses.Items)
            {
                courses.AppendFormat("{0} ({1} students)", course.CourseName, course.Students.Count);
            }

            Assert.AreEqual(courses.ToString(), message);
        }
Beispiel #11
0
        public void TestWithSeveralCoursesAndDifferentStudents()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Lecturer);
            CoursesController controller = new CoursesController(data, user);

            controller.Create("Object-Oriented+Programming");
            controller.Create("High-Quality+Code");
            controller.Create("Java+Basics");
            controller.Enroll(1);
            controller.Enroll(3);
            string message = controller.All().Display();

            var courses = new StringBuilder();
            courses.AppendLine("All courses:");
            foreach (var course in data.Courses.Items.OrderBy(c => c.CourseName).ThenByDescending(c => c.Students.Count))
            {
                courses.AppendFormat("{0} ({1} students)", course.CourseName, course.Students.Count).AppendLine();
            }

            Assert.AreEqual(courses.ToString().Trim(), message);
        }
 public void InitializeUsersController()
 {
     var data = new BangaloreUniversityData();
     this.controller = new UsersController(data, null);       
 }
 public void InitializeCoursesController()
 {
     var data = new BangaloreUniversityData();
     var user = new User("pesho", "32432we", Role.Lecturer);
     this.controller = new CoursesController(data, user);
 }