Esempio n. 1
0
        public void ShouldNotEditRoleIfRequiredFieldsEmpty()
        {
            var updateModel       = new EditUserRoleModel();
            var validator         = new EditUserRoleModelValidator(GetMockUserContext());
            var validationResults = validator.Validate(updateModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldBe(new List <string>
            {
                "'User Id' must not be empty.",
                "The user you are trying to edit does not exist in the database.",
                "'Role Id' must not be empty.",
                "The role you are trying to assign does not exist in the database.",
                "'Email' must not be empty."
            }, false);
        }
Esempio n. 2
0
        public void ShouldNotEditRoleIfUserIsCurrentlyLoggedIn()
        {
            var existingUser = SetupUsers(1).Single();

            var updateModel = new EditUserRoleModel
            {
                UserId = existingUser.Id,
                RoleId = Role.Admin.Value.ToString(),
                Email  = existingUser.Email
            };

            var validator         = new EditUserRoleModelValidator(GetMockUserContext(existingUser, Role.Admin));
            var validationResults = validator.Validate(updateModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("The user is not allowed to assign/remove roles as they are logged in as a Super Administrator or have an Administrator role.");
        }
Esempio n. 3
0
        public void ShouldNotEditRoleIfRoleDoesNotExist()
        {
            var existingUser = SetupUsers(1).Single();

            var notExistingRoleId = "3";

            var updateModel = new EditUserRoleModel
            {
                UserId = existingUser.Id,
                RoleId = notExistingRoleId,
                Email  = existingUser.Email
            };

            var validator         = new EditUserRoleModelValidator(GetMockUserContext(existingUser));
            var validationResults = validator.Validate(updateModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("The role you are trying to assign does not exist in the database.");
        }
Esempio n. 4
0
        public void ShouldNotEditRoleIfUserDoesNotExists()
        {
            var testUserNotInSystem = new AdminAppUser
            {
                Email    = $"testuser{Guid.NewGuid():N}@test.com",
                UserName = $"testuser{Guid.NewGuid():N}@test.com"
            };

            var updateModel = new EditUserRoleModel
            {
                UserId = testUserNotInSystem.Id,
                RoleId = Role.Admin.Value.ToString(),
                Email  = testUserNotInSystem.Email
            };

            var validator         = new EditUserRoleModelValidator(GetMockUserContext(testUserNotInSystem, Role.Admin));
            var validationResults = validator.Validate(updateModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("The user you are trying to edit does not exist in the database.");
        }