Exemplo n.º 1
0
        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 = UmbracoApplicationContext.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));
            }
        }
Exemplo n.º 2
0
        public void DataTypeEditorControllerTests_Create_New_Wizard_Step_Bound_And_Invalidated()
        {
            //Arrange

            var createModel = new CreateDataTypeModel {
                Name = "", PropertyEditorId = Guid.Empty
            };

            //create data type in persistence layer
            var dataTypeEntity = HiveModelCreationHelper.CreateAttributeType("test", "Test", "");

            UmbracoApplicationContext.AddPersistenceData(dataTypeEntity);

            var controller = new DataTypeEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(GetBackOfficeRequestContext());

            //Act
            var result = (ViewResult)controller.CreateNewForm(createModel);

            //Assert
            Assert.IsFalse(controller.ModelState.IsValidField("Name"));
        }