public ActionResult Create(TimeZoneCreateOrUpdate value) { if (value == null) { throw new ArgumentNullException("value"); } var timeZone = this.TimeZoneService.Create(); var privilege = new TimeZonePrivilege(); if (!privilege.CanCreate(timeZone)) { return NotAuthorized(); } value.Validate(); if (value.IsValid) { value.ValueToModel(timeZone); this.TimeZoneService.InsertOrUpdate(timeZone); value = new TimeZoneCreateOrUpdate(timeZone); value.SuccessMessage(Messages.TimeZoneCreated.FormatInvariant(timeZone.Title)); } else { value.CopyToModel(ModelState); } return base.View(Views.Update, value); }
public void Test_TimeZoneCreateOrUpdate_Validate() { var value = new TimeZoneCreateOrUpdate(); value.Validate(); Assert.AreEqual(2, value.Errors.Count, "Errors"); }
public void Test_TimeZoneCreateOrUpdate_ValueToModel() { var value = new TimeZoneCreateOrUpdate { Title = "test", Display = "test2", Offset = 2 }; var country = new TimeZone(); value.ValueToModel(country); Assert.AreEqual("test", value.Title, "Title"); Assert.AreEqual("test2", value.Display, "Display"); Assert.AreEqual(2, value.Offset, "Offset"); }
public void Test_TimeZoneCreateOrUpdate() { var value = new TimeZoneCreateOrUpdate( new TimeZone { Id = 1, Title = "test", Display = "test2", Offset = 2 } ); Assert.AreEqual(1, value.Id, "Id"); Assert.AreEqual("test", value.Title, "Title"); Assert.AreEqual("test2", value.Display, "Display"); Assert.AreEqual(2, value.Offset, "Offset"); }
public void Test_TimeZoneController_Create_Post() { PrincipalHelper.Create(); var value = new TimeZoneCreateOrUpdate { Title = "test", Display = "test", Offset = 0 }; var viewResult = this.TimeZoneController.Create(value) as ViewResult; Assert.IsNotNull(viewResult, "ViewResult"); Assert.AreEqual(Views.Update, viewResult.ViewName, "ViewName"); var model = viewResult.Model as TimeZoneCreateOrUpdate; Assert.IsNotNull(model, "Model"); Assert.AreEqual(Messages.TimeZoneCreated.FormatInvariant(model.Title), model.Message.Message); value = new TimeZoneCreateOrUpdate(); var errorResult = this.TimeZoneController.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.TimeZoneController.Create(value) as NotAuthorizedResult; Assert.IsNotNull(notAuthorizedResult, "NotAuthorizedResult"); }