public static void ValidateNotEnrolledStudent(User user, Course course) { if (!user.Courses.Contains(course)) { throw new ArgumentException("You are not enrolled in this course."); } }
public static void ValidateEnrollingStudent(User user, Course course) { if (user.Courses.Contains(course)) { throw new ArgumentException("You are already enrolled in this course."); } }
public static void ValidateRoles(User user) { if (!user.IsInRole(Role.Student) && !user.IsInRole(Role.Lecturer)) { throw new AuthorizationFailedException("The current user is not authorized to perform this operation."); } }
public static void ValidateLectureRole(User user) { if (!user.IsInRole(Role.Lecturer)) { // TODO: AuthorizationFailedException throw new ArgumentException("The current user is not authorized to perform this operation."); } }
public void Display62() { User user; Login login; string s; user = new User("�\0\0\0\0", "�\0\0\0\0\0", Role.Student); login = new Login(user); s = this.Display((View)login); Assert.AreEqual<string>("User �\0\0\0\0 logged in successfully.", s); }
public void BuildViewResult884() { User user; Logout logout; StringBuilder stringBuilder; user = new User("�\0\0\0\0\0", "�\0\0\0\0\0", Role.Student); logout = new Logout(user); stringBuilder = new StringBuilder(); this.BuildViewResult(logout, stringBuilder); Assert.IsNotNull((object)logout); Assert.IsNotNull(((View)logout).Model); }
/// <summary> /// The controller actions which performs user registration. /// </summary> /// <param name="username">The user name of the person to be registered.</param> /// <param name="password">The password.</param> /// <param name="confirmPassword">The confirmation password. Should be identical with the password.</param> /// <param name="role">The role of the person- can be lecture or student.</param> /// <returns>In case of sucess retunrs sucess message. If passwords do not mathch, /// there is logged user, or user is not registered returns error message.</returns> /// <exception cref="ArgumentException">Appropriate error message.</exception> public IView Register(string username, string password, string confirmPassword, string role) { Validations.CheckPasswordsMatch(password, confirmPassword); Validations.EnsureNoLoggedInUser(this.HasCurrentUser); Validations.EnsureUserIsNotRgistered(this.Data.Users, username); var userRole = (Role)Enum.Parse(typeof(Role), role, true); var user = new User(username, password, userRole); this.Data.Users.Add(user); this.Data.Users.UserName_User[username] = user; return this.View(user); }
public void All_WithValidData_ShouldCallDatabaseGetAll() { var user = new User("Pesho", "1234567", Role.Lecturer); var database = new Mock<IBangaloreUniversityData>(); database.Setup(data => data.Courses.GetAll()).Returns(new List<Course>()); var controller = new CoursesController(database.Object, user); controller.All(); database.Verify(data => data.Courses.GetAll(), Times.Exactly(1)); }
public void All_ReturnsIView() { var user = new User("Pesho", "1234567", Role.Lecturer); var database = new Mock<IBangaloreUniversityData>(); database.Setup(data => data.Courses.GetAll()).Returns(new List<Course>()); var controller = new CoursesController(database.Object, user); var result = controller.All(); Assert.IsInstanceOfType(result, typeof(IView)); }
public UsersController(IBangaloreUniversityDate data, User user) : base(data, user) { }
public CoursesController(IBangaloreUniversityData data, User currentUser) : base(data, currentUser) { }
public Register(User user) : base(user) { }
public Logout Constructor(User user) { Logout target = new Logout(user); return target; // TODO: add assertions to method LogoutTest.Constructor(User) }
public Login(User user) : base(user) { }
protected Controller(IBangaloreUniversityDate data, User user) { this.Data = data; this.User = user; }
protected Controller(IBangaloreUniversityData data, User currentUser) { this.Data = data; this.CurrentUser = currentUser; }
public Logout(User user) : base(user) { }