Example #1
0
        public void fromuser_shouldfillcorrectproperties()
        {
            // Arrange
            User user = new User();

            user.Id            = Guid.NewGuid();
            user.ActivationKey = "key";
            user.Email         = "email";
            user.Firstname     = "firstname";
            user.Id            = Guid.NewGuid();
            user.IsActivated   = true;
            user.IsAdmin       = true;
            user.IsEditor      = true;
            user.Lastname      = "lastname";
            user.SetPassword("pwd");
            user.PasswordResetKey = "resetkey";
            user.Salt             = "salt";

            UserEntity entity = new UserEntity();

            // Act
            ToEntity.FromUser(user, entity);

            // Assert
            Assert.That(entity.Id, Is.Not.EqualTo(user.Id));              // the id isn't copied from the page
            Assert.That(entity.ActivationKey, Is.EqualTo(user.ActivationKey));
            Assert.That(entity.Email, Is.EqualTo(user.Email));
            Assert.That(entity.Firstname, Is.EqualTo(user.Firstname));
            Assert.That(entity.IsActivated, Is.EqualTo(user.IsActivated));
            Assert.That(entity.IsAdmin, Is.EqualTo(user.IsAdmin));
            Assert.That(entity.IsEditor, Is.EqualTo(user.IsEditor));
            Assert.That(entity.Lastname, Is.EqualTo(user.Lastname));
            Assert.That(entity.Password, Is.EqualTo(user.Password));
            Assert.That(entity.Salt, Is.EqualTo(user.Salt));
        }
Example #2
0
        public void AddAdminUser(string email, string username, string password)
        {
            try
            {
                using (IUnitOfWork unitOfWork = _context.CreateUnitOfWork())
                {
                    var user = new User();
                    user.Email    = email;
                    user.Username = username;
                    user.SetPassword(password);
                    user.IsAdmin     = true;
                    user.IsEditor    = true;
                    user.IsActivated = true;

                    var entity = new UserEntity();
                    ToEntity.FromUser(user, entity);

                    unitOfWork.Add(entity);
                    unitOfWork.SaveChanges();
                }
            }
            catch (Exception e)
            {
                throw new DatabaseException(e, "Install failed: unable to create the admin user using '{0}' - {1}", ConnectionString, e.Message);
            }
        }