コード例 #1
0
        public void BackOfficeRouting_Ensure_Default_Editor_Url_Structures()
        {
            //Arrange

            var context = new FakeHttpContextFactory("~/empty", new RouteData());

            var contentEditor         = new ContentEditorController(new FakeBackOfficeRequestContext());
            var contentControllerName = RebelController.GetControllerName(contentEditor.GetType());
            var contentControllerId   = RebelController.GetControllerId <EditorAttribute>(contentEditor.GetType());

            var dataTypeEditor         = new DataTypeEditorController(new FakeBackOfficeRequestContext());
            var dataTypeControllerName = RebelController.GetControllerName(dataTypeEditor.GetType());
            var dataTypeControllerId   = RebelController.GetControllerId <EditorAttribute>(dataTypeEditor.GetType());

            var docTypeEditor         = new DocumentTypeEditorController(new FakeBackOfficeRequestContext());
            var docTypeControllerName = RebelController.GetControllerName(docTypeEditor.GetType());
            var docTypeControllerId   = RebelController.GetControllerId <EditorAttribute>(docTypeEditor.GetType());

            const string customAction  = "Index";
            const string defaultAction = "Dashboard";
            const int    id            = -1;
            const string area          = "Rebel";

            //Act

            //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work

            var contentEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, contentControllerName,
                                                                new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = contentControllerId.ToString("N") }),
                                                                RouteTable.Routes, context.RequestContext, true);

            var dataTypeEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, dataTypeControllerName,
                                                                 new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = dataTypeControllerId.ToString("N") }),
                                                                 RouteTable.Routes, context.RequestContext, true);

            var docTypeEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, docTypeControllerName,
                                                                new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = docTypeControllerId.ToString("N") }),
                                                                RouteTable.Routes, context.RequestContext, true);

            var contentEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, contentControllerName,
                                                               new RouteValueDictionary(new { area, id, editorId = contentControllerId.ToString("N") }),
                                                               RouteTable.Routes, context.RequestContext, true);

            var dataTypeEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, dataTypeControllerName,
                                                                new RouteValueDictionary(new { area, id, editorId = dataTypeControllerId.ToString("N") }),
                                                                RouteTable.Routes, context.RequestContext, true);

            var docTypeEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, docTypeControllerName,
                                                               new RouteValueDictionary(new { area, id, editorId = docTypeControllerId.ToString("N") }),
                                                               RouteTable.Routes, context.RequestContext, true);

            //Assert

            Assert.AreEqual(string.Format("/Rebel/Editors/{0}", contentControllerName), contentEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}", dataTypeControllerName), dataTypeEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}", docTypeControllerName), docTypeEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", dataTypeControllerName, customAction, id), dataTypeEditorCustomUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", docTypeControllerName, customAction, id), docTypeEditorCustomUrl);
        }
コード例 #2
0
        public void DataTypeEditorControllerTests_PreValueModel_Data_Will_Be_Updated_With_Posted_Values()
        {
            //Arrange

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

            dataTypeEntity.RenderTypeProvider = propEditor.Id.ToString();
            UmbracoApplicationContext.AddPersistenceData(dataTypeEntity);

            var controller = new DataTypeEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "PreValueEditorModel.Value", "hello" }
            }, GetBackOfficeRequestContext());

            //Act
            var result = controller.EditForm(dataTypeEntity.Id) as ViewResult;

            //Assert
            Assert.IsTrue(controller.ModelState.IsValidField("PreValueEditorModel.Value"));
            Assert.AreEqual("hello", controller.ModelState["PreValueEditorModel.Value"].Value.AttemptedValue);
        }
コード例 #3
0
        public void DataTypeEditorControllerTests_DataType_Saved()
        {
            //Arrange

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

            dataTypeEntity.RenderTypeProvider = propEditor.Id.ToString();
            UmbracoApplicationContext.AddPersistenceData(dataTypeEntity);

            var controller = new DataTypeEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "Name", "Hello World" },
                { "PropertyEditorId", "5A379AF0-0256-4BE9-9D01-F149603DB257" },
                { "submit.Save", "Save" }                                   //set save flag
            }, GetBackOfficeRequestContext(), false);

            //Act

            var result = controller.EditForm(dataTypeEntity.Id);

            //Assert

            Assert.IsTrue(result is RedirectToRouteResult);

            using (var uow = UmbracoApplicationContext.Hive.OpenReader <IContentStore>())
            {
                var latestEntity = uow.Repositories.Schemas.Get <AttributeType>(dataTypeEntity.Id);
                Assert.IsTrue(dataTypeEntity.UtcModified < latestEntity.UtcModified);
            }
        }
コード例 #4
0
        public void DataTypeEditorControllerTests_All_Standard_Values_Bound()
        {
            //Arrange

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

            dataTypeEntity.RenderTypeProvider = propEditor.Id.ToString();
            UmbracoApplicationContext.AddPersistenceData(dataTypeEntity);

            var controller = new DataTypeEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "Name", "Hello World" },
                { "PropertyEditorId", "5A379AF0-0256-4BE9-9D01-F149603DB257" }
            }, GetBackOfficeRequestContext());

            //Act
            var result     = controller.EditForm(dataTypeEntity.Id) as ViewResult;
            var modelState = controller.ModelState;

            //Assert

            Assert.AreEqual("Hello World", controller.ModelState["Name"].Value.AttemptedValue);
            Assert.IsTrue(controller.ModelState.IsValidField("Name"));
            Assert.AreEqual("5A379AF0-0256-4BE9-9D01-F149603DB257", controller.ModelState["PropertyEditorId"].Value.AttemptedValue);
            Assert.IsTrue(controller.ModelState.IsValidField("PropertyEditorId"));
        }
コード例 #5
0
        public void DataTypeEditorControllerTests_Invalid_Model_State_When_Missing_Required_Values()
        {
            //Arrange

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

            dataTypeEntity.RenderTypeProvider = propEditor.Id.ToString();
            UmbracoApplicationContext.AddPersistenceData(dataTypeEntity);

            var controller = new DataTypeEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "Name", "" },
                { "PropertyEditorId", "" }
            }, GetBackOfficeRequestContext());

            //Act

            var result = controller.EditForm(dataTypeEntity.Id) as ViewResult;

            //Assert

            Assert.IsFalse(controller.ModelState.IsValidField("Name"));
            Assert.IsFalse(controller.ModelState.IsValidField("PropertyEditorId"));
        }
コード例 #6
0
        public void DataTypeEditorControllerTests_Create_New_Wizard_Step_Bound_And_Validated()
        {
            //Arrange

            var propEditor  = new MandatoryPropertyEditor();
            var createModel = new CreateDataTypeModel {
                Name = "test", PropertyEditorId = propEditor.Id
            };

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

            dataTypeEntity.RenderTypeProvider = propEditor.Id.ToString();
            UmbracoApplicationContext.AddPersistenceData(dataTypeEntity);

            var controller = new DataTypeEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(GetBackOfficeRequestContext());

            //Act

            var result = (ViewResult)controller.CreateNewForm(createModel);
            var model  = (CreateDataTypeModel)result.Model;

            //Assert

            Assert.IsTrue(controller.ModelState.IsValidField("Name"));
            Assert.IsTrue(controller.ModelState.IsValidField("PropertyEditorId"));

            Assert.AreEqual("test", model.Name);
            Assert.AreEqual(propEditor.Id, model.PropertyEditorId);
        }
コード例 #7
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));
            }
        }
コード例 #8
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"));
        }