Rebel.Cms.Web.Editors.DataTypeEditorController.CreateForm C# (CSharp) Method

CreateForm() private method

private CreateForm ( ) : System.Web.Mvc.ActionResult
return System.Web.Mvc.ActionResult
        public virtual ActionResult CreateForm()
        {
            //get the property editor Id from the values
            var propertyEditorId = Guid.Parse(ValueProvider.GetValue("PropertyEditorId").AttemptedValue);
            //this will throw an exception if its not found
            var propertyEditor = _propertyEditors.Where(x => x.Metadata.Id == propertyEditorId).Single();
            var dataType = new DataType(string.Empty, string.Empty, propertyEditor.Value);
            var dataTypeEditorViewModel = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map<DataType, DataTypeEditorModel>(dataType);

            return ProcessSubmit(dataTypeEditorViewModel, null);
        }

Usage Example

        public void DataTypeEditorControllerTests_DataType_Create()
        {
            //Arrange

            //create data type in persistence layer
            var propEditor = new MandatoryPropertyEditor();
            var dataTypeEntity = HiveModelCreationHelper.CreateAttributeType("test", "Test", "");
            dataTypeEntity.RenderTypeProvider = propEditor.Id.ToString();

            var controller = new DataTypeEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  {"Name", "Hello World"},
                                                   {"PropertyEditorId", FixedPropertyEditors.GetPropertyEditorDefinitions().First().Metadata.Id.ToString()},
                                                   { "submit.Save", "Save"} //set save flag
                                              }, GetBackOfficeRequestContext(), false);

            //Act

            var result = controller.CreateForm();

            //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 latestEntity = uow.Repositories.Schemas.Get<AttributeType>((HiveId)newId);

                Assert.AreEqual("Hello World", latestEntity.Name.Value);
                Assert.AreEqual(FixedPropertyEditors.GetPropertyEditorDefinitions().First().Metadata.Id.ToString(), latestEntity.RenderTypeProvider);
                Assert.IsTrue(DateTimeOffset.UtcNow.Subtract(latestEntity.UtcCreated) < new TimeSpan(0, 1, 0));
            }
        }