public void DocumentTypeEditorControllerTests_Create_New_Wizard_Step_Bound_And_Invalidated() { //Arrange var parentDocTypeId = Guid.NewGuid(); var selectedDocTypeId = Guid.NewGuid(); var createModel = new CreateDocumentTypeModel { Name = "", //CreateTemplate = true, //ParentId = parentDocTypeId, SelectedDocumentTypeId = new HiveId(selectedDocTypeId) }; var controller = new ContentEditorController(GetBackOfficeRequestContext()); controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string> { //{ "ParentId", parentDocTypeId.ToString("N") }, { "Name", "" }, { "SelectedDocumentTypeId", selectedDocTypeId.ToString("N") }, { "CreateTemplate", true.ToString() } }, GetBackOfficeRequestContext()); //Act var result = (ViewResult)controller.CreateNewForm(createModel); //Assert Assert.IsFalse(controller.ModelState.IsValidField("Name")); }
public void Should_require_name() { var model = new CreateDocumentTypeModel(); var validator = new CreateDocumentTypeValidator(); var results = validator.Validate(model); Assert.Contains(results.Errors, e => e.PropertyName == "Name"); }
public void Should_validate_successfully_with_valid_data() { var model = new CreateDocumentTypeModel { Name = "Author" }; var validator = new CreateDocumentTypeValidator(); var results = validator.Validate(model); Assert.True(results.IsValid); }
public DocumentTypeControllerTests() { _commandSender = new Mock <ICommandSender>(); _controller = new DocumentTypeController(_commandSender.Object); _goodPayload = new CreateDocumentTypeModel { Name = "test" }; }
public async Task <IActionResult> Post([FromBody] CreateDocumentTypeModel model) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var command = new Core.WriteModel.Commands.CreateDocumentType(Guid.NewGuid(), model.Name); await _commandSender.Send(command); return(new OkResult()); }
public void DocumentTypeEditorControllerTests_DocumentType_Create() { //Arrange var controller = new DocumentTypeEditorController(GetBackOfficeRequestContext()); controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>(), GetBackOfficeRequestContext(), false); //Act var model = new CreateDocumentTypeModel { Name = "Hello", SelectedDocumentTypeId = FixedHiveIds.ContentRootSchema, CreateTemplate = false }; var result = controller.CreateNewForm(model); //Assert Assert.IsTrue(result is RedirectToRouteResult); //get the new id from the route values var newId = ((RedirectToRouteResult)result).RouteValues["id"]; Assert.AreEqual(typeof(HiveId), newId.GetType()); using (var uow = UmbracoApplicationContext.Hive.OpenReader <IContentStore>()) { var entity = uow.Repositories.Schemas.Get <EntitySchema>((HiveId)newId); if (entity == null) { Assert.Fail("no entity found"); } Assert.AreEqual("hello", entity.Alias); Assert.AreEqual("Hello", entity.Name.Value); Assert.IsTrue(DateTimeOffset.UtcNow.Subtract(entity.UtcCreated) < new TimeSpan(0, 1, 0)); Assert.IsTrue(DateTimeOffset.UtcNow.Subtract(entity.UtcModified) < new TimeSpan(0, 1, 0)); Assert.IsTrue(entity.AttributeGroups.Any(x => x.Alias == FixedGroupDefinitions.GeneralGroupAlias)); } }
public void DocumentTypeEditorControllerTests_DocumentType_Create() { //Arrange var controller = new DocumentTypeEditorController(GetBackOfficeRequestContext()); controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>(), GetBackOfficeRequestContext(), false); //Act var model = new CreateDocumentTypeModel { Name = "Hello", SelectedDocumentTypeId = FixedHiveIds.ContentRootSchema, CreateTemplate = false }; var result = controller.CreateNewForm(model); //Assert Assert.IsTrue(result is RedirectToRouteResult); //get the new id from the route values var newId = ((RedirectToRouteResult)result).RouteValues["id"]; Assert.AreEqual(typeof(HiveId), newId.GetType()); using (var uow = RebelApplicationContext.Hive.OpenReader<IContentStore>()) { var entity = uow.Repositories.Schemas.Get<EntitySchema>((HiveId)newId); if (entity == null) Assert.Fail("no entity found"); Assert.AreEqual("hello", entity.Alias); Assert.AreEqual("Hello", entity.Name.Value); Assert.IsTrue(DateTimeOffset.UtcNow.Subtract(entity.UtcCreated) < new TimeSpan(0, 1, 0)); Assert.IsTrue(DateTimeOffset.UtcNow.Subtract(entity.UtcModified) < new TimeSpan(0, 1, 0)); Assert.IsTrue(entity.AttributeGroups.Any(x => x.Alias == FixedGroupDefinitions.GeneralGroupAlias)); } }
public void DocumentTypeEditorControllerTests_Create_New_Wizard_Step_Bound_And_Invalidated() { //Arrange var parentDocTypeId = Guid.NewGuid(); var selectedDocTypeId = Guid.NewGuid(); var createModel = new CreateDocumentTypeModel { Name = "", //CreateTemplate = true, //ParentId = parentDocTypeId, SelectedDocumentTypeId = new HiveId(selectedDocTypeId) }; var controller = new ContentEditorController(GetBackOfficeRequestContext()); controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string> { //{ "ParentId", parentDocTypeId.ToString("N") }, { "Name", "" }, { "SelectedDocumentTypeId", selectedDocTypeId.ToString("N") }, { "CreateTemplate", true.ToString() } }, GetBackOfficeRequestContext()); //Act var result = (ViewResult)controller.CreateNewForm(createModel); //Assert Assert.IsFalse(controller.ModelState.IsValidField("Name")); }