示例#1
0
        public ActionResult Create(UserBanCreateOrUpdate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var ban = this.UserBanService.Create();
            var privilege = new UserBanPrivilege();

            if (!privilege.CanUpdate(ban))
            {
                return NotAuthorized();
            }

            value.Validate();

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

                this.UserBanService.InsertOrUpdate(ban, value.Name);

                value = new UserBanCreateOrUpdate(ban);
                value.SuccessMessage(Messages.UserBanCreated.FormatInvariant(ban.User.Name));
            }
            else
            {
                value.CopyToModel(ModelState);
            }

            return base.View(Views.Update, value);
        }
        public void Test_UserBanCreateOrUpdate_Validate()
        {
            var value = new UserBanCreateOrUpdate();

            value.Validate();

            Assert.AreEqual(3, value.Errors.Count, "Errors");
        }
        public void Test_UserBanCreateOrUpdate_Initialize()
        {
            var value = new UserBanCreateOrUpdate();

            value.Initialize(new User());

            Assert.IsNotNull(value.User, "User");
        }
        public void Test_UserBanCreateOrUpdate_ValueToModel()
        {
            var date = DateTime.Now;

            var value = new UserBanCreateOrUpdate
            {
                Reason = "test",
                Expire = date.ToString("M/d/yyyy", CultureInfo.InvariantCulture),
            };

            var ban = new UserBan();

            value.ValueToModel(ban);

            Assert.AreEqual("test", ban.Reason, "Reason");
            Assert.IsNotNull(ban.Expire, "Expire NotNull");
            Assert.AreEqual(new DateTime(date.Year, date.Month, date.Day, 0, 0, 0), ban.Expire.Value, "Expire");
        }
        public void Test_UserBanCreateOrUpdate()
        {
            var date = DateTime.Now;

            var value = new UserBanCreateOrUpdate(
                new UserBan
                {
                    Id = 1,
                    Reason = "test",
                    IsPermanent = true,
                    Expire = DateTime.Now,
                    User = new User()
                }
            );

            Assert.AreEqual(1, value.Id, "Id");
            Assert.AreEqual("test", value.Reason, "Reason");
            Assert.IsTrue(value.IsPermanent, "IsPermanent");
            Assert.AreEqual(date.ToString("M/d/yyyy", CultureInfo.InvariantCulture), value.Expire, "Expire");
            Assert.IsNotNull(value.User, "User");
        }
示例#6
0
        public void Test_BanController_Create_Post()
        {
            PrincipalHelper.Create();

            var value = new UserBanCreateOrUpdate
            {
                Name = "test",
                Reason = "test",
                IsPermanent = true
            };

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

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

            var model = viewResult.Model as UserBanCreateOrUpdate;

            Assert.IsNotNull(model, "Model");
            Assert.AreEqual(Messages.UserBanCreated.FormatInvariant(string.Empty), model.Message.Message);

            value.Name = null;

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

            Assert.IsNotNull(errorResult, "ErrorResult");
            Assert.AreEqual(Views.Update, viewResult.ViewName, "ErrorViewName");
            Assert.AreEqual(2, value.Errors.Count, "Errors");

            PrincipalHelper.Clear();

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

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