コード例 #1
0
ファイル: Validations.cs プロジェクト: EBojilova/CSharpHQC
 public static void ValidateNotEnrolledStudent(User user, Course course)
 {
     if (!user.Courses.Contains(course))
     {
         throw new ArgumentException("You are not enrolled in this course.");
     }
 }
コード例 #2
0
ファイル: Validations.cs プロジェクト: EBojilova/CSharpHQC
 public static void ValidateEnrollingStudent(User user, Course course)
 {
     if (user.Courses.Contains(course))
     {
         throw new ArgumentException("You are already enrolled in this course.");
     }
 }
コード例 #3
0
ファイル: Validations.cs プロジェクト: EBojilova/CSharpHQC
 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.");
     }
 }
コード例 #4
0
ファイル: Validations.cs プロジェクト: EBojilova/CSharpHQC
 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.");
     }
 }
コード例 #5
0
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);
}
コード例 #6
0
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);
}
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
 public UsersController(IBangaloreUniversityDate data, User user)
     : base(data, user)
 {
 }
コード例 #11
0
 public CoursesController(IBangaloreUniversityData data, User currentUser)
     : base(data, currentUser)
 {
 }
コード例 #12
0
ファイル: Register.cs プロジェクト: EBojilova/CSharpHQC
 public Register(User user)
     : base(user)
 {
 }
コード例 #13
0
ファイル: LogoutTest.cs プロジェクト: EBojilova/CSharpHQC
 public Logout Constructor(User user)
 {
     Logout target = new Logout(user);
     return target;
     // TODO: add assertions to method LogoutTest.Constructor(User)
 }
コード例 #14
0
ファイル: Login.cs プロジェクト: EBojilova/CSharpHQC
 public Login(User user)
     : base(user)
 {
 }
コード例 #15
0
ファイル: Controller.cs プロジェクト: EBojilova/CSharpHQC
 protected Controller(IBangaloreUniversityDate data, User user)
 {
     this.Data = data;
     this.User = user;
 }
コード例 #16
0
ファイル: Controller.cs プロジェクト: EBojilova/CSharpHQC
 protected Controller(IBangaloreUniversityData data, User currentUser)
 {
     this.Data = data;
     this.CurrentUser = currentUser;
 }
コード例 #17
0
ファイル: Logout.cs プロジェクト: EBojilova/CSharpHQC
 public Logout(User user)
     : base(user)
 {
 }