public void Test_UserAdminCreate_ValueToModel()
        {
            var value = new UserAdminCreate
            {
                CountryId = 1,
                TimeZoneId = 2,
                Name = "test",
                Title = "test2",
                EmailAddress = "*****@*****.**",
                Password = "******",
                Signature = "test5",
                IsProtected = true,
                Status = UserStatus.Activated,
                Dst = UserPreferenceDaylightSavingTime.On,
                StartOfWeek = UserPreferenceStartOfWeek.Monday,
                TimeFormat = UserPreferenceTimeFormat.Extended
            };

            var user = new User();

            value.ValueToModel(user);

            Assert.AreEqual("test", user.Name, "Name");
            Assert.AreEqual("test2", user.Title, "Title");
            Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress");
            Assert.AreEqual("testing", user.Password, "Password");
            Assert.AreEqual("test5", user.Signature, "Signature");
            Assert.IsTrue(user.IsProtected, "IsProtected");
            Assert.AreEqual(UserStatus.Activated, user.Status, "Status");
            Assert.AreEqual(UserPreferenceDaylightSavingTime.On, value.Preference.Dst, "Dst");
            Assert.AreEqual(UserPreferenceStartOfWeek.Monday, value.Preference.StartOfWeek, "StartOfWeek");
            Assert.AreEqual(UserPreferenceTimeFormat.Extended, value.Preference.TimeFormat, "TimeFormat");
        }
Beispiel #2
0
        public ActionResult Create(UserAdminCreate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var user = this.UserService.Create();
            var privilege = new UserPrivilege();

            if (!privilege.CanCreate(user))
            {
                return NotAuthorized();
            }

            value.Validate();

            if (value.IsValid)
            {
                value.ValueToModel(user);

                this.UserService.Insert(user, value.Preference);

                var model = new UserAdminUpdate(user);

                model.SuccessMessage(Messages.UserCreated.FormatInvariant(user.Name));

                return base.View(Views.Update, model);
            }

            value.CopyToModel(ModelState);

            return base.View(Views.Create, value);
        }
        public void Test_UserAdminCreate_Validate()
        {
            var value = new UserAdminCreate();

            value.Validate();

            Assert.AreEqual(6, value.Errors.Count, "Errors");
        }
        public void Test_HomeController_Create_Post()
        {
            PrincipalHelper.Create();

            var value = new UserAdminCreate
            {
                Name = "fake",
                EmailAddress = "*****@*****.**",
                VerifyEmailAddress = "*****@*****.**",
                Password = "******",
                VerifyPassword = "******"
            };

            var viewResult = this.HomeController.Create(value) as ViewResult;

            Assert.IsNotNull(viewResult, "ViewResult");
            Assert.AreEqual(Views.Update, viewResult.ViewName, "ViewName");

            var model = viewResult.Model as UserAdminUpdate;

            Assert.IsNotNull(model, "Model");
            Assert.AreEqual(Messages.UserCreated.FormatInvariant(model.Name), model.Message.Message);

            value = new UserAdminCreate();

            var errorResult = this.HomeController.Create(value) as ViewResult;

            Assert.IsNotNull(errorResult, "ErrorResult");
            Assert.AreEqual(Views.Create, errorResult.ViewName, "ErrorViewName");
            Assert.AreEqual(6, value.Errors.Count, "Errors");

            PrincipalHelper.Clear();

            var notAuthorizedResult = this.HomeController.Create(value) as NotAuthorizedResult;

            Assert.IsNotNull(notAuthorizedResult, "NotAuthorizedResult");
        }