예제 #1
0
        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 ContentEditorControllerTest_All_Standard_Values_Bound()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());

            var controller = new ContentEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "Name", "Demo" },
                { "SelectedTemplateId", "1042" },                                   //i know that 1042 is in our mocked template resolver
                { "UtcPublishScheduled", "2013-01-01" },
                { "UtcUnpublishScheduled", "2014-01-01" }
            }, GetBackOfficeRequestContext());

            //Act
            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model  = (ContentEditorModel)result.Model;

            //Assert
            Assert.AreEqual("Demo", model.Name);
            //Assert.AreEqual(new HiveId(1042), model.SelectedTemplateId);
            Assert.AreEqual(new DateTime(2013, 1, 1, 0, 0, 0), model.UtcPublishScheduled);
            Assert.AreEqual(new DateTime(2014, 1, 1, 0, 0, 0), model.UtcUnpublishScheduled);
        }
예제 #3
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);
        }
        public void ContentEditorControllerTest_Actions_Secured_By_Permissions()
        {
            //Arrange
            var backOfficeRequestContext = GetBackOfficeRequestContext();
            var controller = new ContentEditorController(backOfficeRequestContext);

            controller.InjectDependencies(GetBackOfficeRequestContext());

            //TODO: There may be a better way of automatically getting a single controller variable using the controller extenders,
            //but likely that's just testing the action invoker, so for now here's the individual controllers

            var copyController = new MoveCopyController(backOfficeRequestContext);

            copyController.InjectDependencies(GetBackOfficeRequestContext());

            var sortController = new SortController(backOfficeRequestContext);

            sortController.InjectDependencies(GetBackOfficeRequestContext());

            var publishController = new PublishController(backOfficeRequestContext);

            publishController.InjectDependencies(GetBackOfficeRequestContext());

            var hos = new HostnameController(backOfficeRequestContext);

            hos.InjectDependencies(GetBackOfficeRequestContext());

            var rollback = new RollbackController(backOfficeRequestContext);

            rollback.InjectDependencies(GetBackOfficeRequestContext());

            var permissions = new PermissionsController(backOfficeRequestContext);

            permissions.InjectDependencies(GetBackOfficeRequestContext());

            //Assert
            Assert.IsTrue(ActionIsSecuredByPermission(controller, "CreateNew", FixedPermissionIds.Create));
            Assert.IsTrue(ActionIsSecuredByPermission(controller, "Edit", FixedPermissionIds.Update));
            Assert.IsTrue(ActionIsSecuredByPermission(controller, "Delete", FixedPermissionIds.Delete));
            Assert.IsTrue(ActionIsSecuredByPermission(copyController, "Copy", FixedPermissionIds.Copy));
            Assert.IsTrue(ActionIsSecuredByPermission(copyController, "Move", FixedPermissionIds.Move));
            Assert.IsTrue(ActionIsSecuredByPermission(sortController, "Sort", FixedPermissionIds.Sort));
            Assert.IsTrue(ActionIsSecuredByPermission(publishController, "Publish", FixedPermissionIds.Publish));
            Assert.IsTrue(ActionIsSecuredByPermission(permissions, "Permissions", FixedPermissionIds.Permissions));
            Assert.IsTrue(ActionIsSecuredByPermission(rollback, "Rollback", FixedPermissionIds.Rollback));

            // TODO: (APN @ Matt) the assertion for action name doesn't take into account two methods with the same name
            // but differing parameter counts, so this one fails
            // NOTE: (MPB) Have renamed post action to HostnameForm to get test passing for now, not sure if that is enough
            // or whether assertion method should allow you to query for a specific method signature?
            Assert.IsTrue(ActionIsSecuredByPermission(hos, "Hostname", FixedPermissionIds.Hostnames));
        }
        public void ContentEditorControllerTests_Create_New_Wizard_Step_Bound_And_Validated()
        {
            //Arrange

            var selectedDocTypeId = new HiveId("content", "", new HiveIdValue(Guid.NewGuid()));
            var createModel       = new CreateContentModel {
                Name = "test", SelectedDocumentTypeId = selectedDocTypeId
            };

            // Get the parent content schema
            using (var writer = RebelApplicationContext.Hive.OpenWriter <IContentStore>())
            {
                var contentSchemaRoot = writer.Repositories.Schemas.Get <EntitySchema>(FixedHiveIds.ContentRootSchema);
                //create doc type in persistence layer
                var schema = HiveModelCreationHelper.CreateEntitySchema("test", "Test", new AttributeDefinition[] { });
                schema.Id = selectedDocTypeId;
                schema.RelationProxies.EnlistParent(contentSchemaRoot, FixedRelationTypes.DefaultRelationType);
                writer.Repositories.Schemas.AddOrUpdate(schema);
                writer.Complete();
            }

            var controller = new ContentEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "Name", "test" },
                { "SelectedDocumentTypeId", selectedDocTypeId.ToString() }
            }, GetBackOfficeRequestContext());

            //Act

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

            //Assert

            Assert.IsTrue(controller.ModelState.IsValidField("Name"),
                          string.Join("; ", controller.ModelState["Name"].Errors.Select(x => x.ErrorMessage)));
            Assert.IsTrue(controller.ModelState.IsValidField("SelectedDocumentTypeId"),
                          string.Join("; ", controller.ModelState["SelectedDocumentTypeId"].Errors.Select(x => x.ErrorMessage)));

            Assert.AreEqual("test", model.Name);
            Assert.AreEqual((Guid)selectedDocTypeId.Value, (Guid)model.SelectedDocumentTypeId.Value);
        }
        public void ContentEditorControllerTests_Invalid_Model_State_When_Missing_Required_Values()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());

            var controller = new ContentEditorController(GetBackOfficeRequestContext());

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

            //Act
            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model  = (ContentEditorModel)result.Model;

            //Assert
            Assert.IsFalse(controller.ModelState.IsValidField("Name"));
        }
        public void ContentEditorControllerTests_Content_Unpublished()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor(),
                                                     c =>
            {
                c.MetaData.UtcStatusChanged = DateTime.Now;
                c.MetaData.StatusType       = FixedStatusTypes.Published;
            });

            var controller = new ContentEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "Name", "hello" },
                { "submit.Unpublish", "Unpublish" }                                  //set unpublish flag
            }, GetBackOfficeRequestContext(), false);

            //Act

            var result = controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);

            //Assert

            Assert.IsTrue(result is RedirectToRouteResult);

            using (var uow = RebelApplicationContext.Hive.OpenReader <IContentStore>())
            {
                var snapshot = uow.Repositories.Revisions.GetLatestSnapshot <TypedEntity>(contentEntity.Item.Id);
                if (snapshot == null)
                {
                    Assert.Fail("no snapshot found");
                }

                var contentViewModel = RebelApplicationContext.FrameworkContext.TypeMappers.Map <EntitySnapshot <TypedEntity>, ContentEditorModel>(snapshot);
                Assert.AreEqual(null, contentViewModel.UtcPublishedDate);
                var lastUnpublished = snapshot.GetLatestDate(FixedStatusTypes.Unpublished);
                Assert.IsTrue(DateTimeOffset.UtcNow.Subtract(lastUnpublished) < new TimeSpan(0, 1, 0));
            }
        }
        public void ContentEditorControllerTests_Create_New_Wizard_Step_Bound_And_Validated()
        {
            //Arrange

            var selectedDocTypeId = new HiveId("content", "", new HiveIdValue(Guid.NewGuid()));
            var createModel = new CreateContentModel { Name = "test", SelectedDocumentTypeId = selectedDocTypeId };
            // Get the parent content schema
            using (var writer = UmbracoApplicationContext.Hive.OpenWriter<IContentStore>())
            {
                var contentSchemaRoot = writer.Repositories.Schemas.Get<EntitySchema>(FixedHiveIds.ContentRootSchema);
                //create doc type in persistence layer
                var schema = HiveModelCreationHelper.CreateEntitySchema("test", "Test", new AttributeDefinition[] { });
                schema.Id = selectedDocTypeId;
                schema.RelationProxies.EnlistParent(contentSchemaRoot, FixedRelationTypes.DefaultRelationType);
                writer.Repositories.Schemas.AddOrUpdate(schema);
                writer.Complete();
            }
            
            var controller = new ContentEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  { "Name", "test" },
                                                  { "SelectedDocumentTypeId", selectedDocTypeId.ToString() }
                                              }, GetBackOfficeRequestContext());

            //Act

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

            //Assert

            Assert.IsTrue(controller.ModelState.IsValidField("Name"),
                string.Join("; ", controller.ModelState["Name"].Errors.Select(x => x.ErrorMessage)));
            Assert.IsTrue(controller.ModelState.IsValidField("SelectedDocumentTypeId"), 
                string.Join("; ", controller.ModelState["SelectedDocumentTypeId"].Errors.Select(x => x.ErrorMessage)));

            Assert.AreEqual("test", model.Name);
            Assert.AreEqual((Guid)selectedDocTypeId.Value, (Guid)model.SelectedDocumentTypeId.Value);
        }
        public void ContentEditorControllerTests_Content_Saved()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());

            var controller = new ContentEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { "Name", "Demo" },
                { contentEntity.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Id.GetHtmlId() + ".Name", "test" },
                { contentEntity.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Id.GetHtmlId() + ".UrlName", "test" },
                { contentEntity.Item.Attributes["bodyText"].Id.GetHtmlId() + ".Value", "1234" },
                { contentEntity.Item.Attributes["siteName"].Id.GetHtmlId() + ".Value", "4321" },
                { "submit.Save", "Save" }                                  //set save flag
            }, GetBackOfficeRequestContext(), false);

            //Act

            var result = controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);

            //Assert

            Assert.IsTrue(result is RedirectToRouteResult);

            using (var uow = RebelApplicationContext.Hive.OpenReader <IContentStore>())
            {
                var snapshot = uow.Repositories.Revisions.GetLatestSnapshot <TypedEntity>(contentEntity.Item.Id);
                if (snapshot == null)
                {
                    Assert.Fail("no snapshot found");
                }

                Assert.AreNotEqual(contentEntity.MetaData.Id, snapshot.Revision.MetaData.Id);
                Assert.IsTrue(contentEntity.MetaData.UtcCreated < snapshot.Revision.MetaData.UtcCreated);
                var contentViewModel = RebelApplicationContext.FrameworkContext.TypeMappers.Map <EntitySnapshot <TypedEntity>, ContentEditorModel>(snapshot);
                Assert.AreEqual(null, contentViewModel.UtcPublishedDate);
            }
        }
        public void ContentEditorControllerTests_Regex_Property_Bound_And_Invalidated()
        {
            //Arrange

            var contentEntity   = CreateEntityRevision(new RegexPropertyEditor());
            var customAttribute = contentEntity.Item.Attributes.Last();
            var controller      = new ContentEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                //there will be 2 attributes, one for node name and a custom one
                { customAttribute.Id.GetHtmlId() + ".Value", "asd" }
            }, GetBackOfficeRequestContext());

            //Act

            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model  = (ContentEditorModel)result.Model;

            //Assert

            Assert.IsFalse(controller.ModelState.IsValidField(customAttribute.Id.GetHtmlId() + ".Value"));
        }
        public void ContentEditorControllerTests_Regex_Property_Bound_And_Validated()
        {
            //Arrange

            var contentEntity   = CreateEntityRevision(new RegexPropertyEditor());
            var customAttribute = contentEntity.Item.Attributes.Last();
            var controller      = new ContentEditorController(GetBackOfficeRequestContext());

            controller.InjectDependencies(new Dictionary <string, string>(), new Dictionary <string, string>
            {
                { customAttribute.Id.GetHtmlId() + ".Value", "123" }
            }, GetBackOfficeRequestContext());

            //Act

            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model  = (ContentEditorModel)result.Model;

            //Assert

            Assert.IsTrue(controller.ModelState.IsValidField(customAttribute.Id.GetHtmlId() + ".Value"));
            Assert.AreEqual("123", model.Properties.Single(x => x.Alias == customAttribute.AttributeDefinition.Alias).PropertyEditorModel.Value);
        }
        public void ContentEditorControllerTests_Create_New_Wizard_Step_Bound_And_Invalidated()
        {
            //Arrange

            var selectedDocTypeId = Guid.NewGuid();
            var createModel = new CreateContentModel { Name = "", SelectedDocumentTypeId = new HiveId(selectedDocTypeId) };

            var controller = new ContentEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  { "Name", "" },
                                                  { "SelectedDocumentTypeId", selectedDocTypeId.ToString("N") }
                                              }, GetBackOfficeRequestContext());

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

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

        }
        public void ContentEditorControllerTests_Regex_Property_Bound_And_Validated()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());
            var customAttribute = contentEntity.Item.Attributes.Last();
            var controller = new ContentEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  { customAttribute.Id.GetHtmlId() + ".Value", "123"}
                                              }, GetBackOfficeRequestContext());

            //Act

            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model = (ContentEditorModel)result.Model;

            //Assert

            Assert.IsTrue(controller.ModelState.IsValidField(customAttribute.Id.GetHtmlId() + ".Value"));
            Assert.AreEqual("123", model.Properties.Single(x => x.Alias == customAttribute.AttributeDefinition.Alias).PropertyEditorModel.Value);
        }
        public void ContentEditorControllerTest_Actions_Secured_By_Permissions()
        {
            //Arrange
            var backOfficeRequestContext = GetBackOfficeRequestContext();
            var controller = new ContentEditorController(backOfficeRequestContext);
            controller.InjectDependencies(GetBackOfficeRequestContext());

            //TODO: There may be a better way of automatically getting a single controller variable using the controller extenders,
            //but likely that's just testing the action invoker, so for now here's the individual controllers

            var copyController = new MoveCopyController(backOfficeRequestContext);
            copyController.InjectDependencies(GetBackOfficeRequestContext());

            var sortController = new SortController(backOfficeRequestContext);
            sortController.InjectDependencies(GetBackOfficeRequestContext());

            var publishController = new PublishController(backOfficeRequestContext);
            publishController.InjectDependencies(GetBackOfficeRequestContext());

            var hos = new HostnameController(backOfficeRequestContext);
            hos.InjectDependencies(GetBackOfficeRequestContext());

            var rollback = new RollbackController(backOfficeRequestContext);
            rollback.InjectDependencies(GetBackOfficeRequestContext());

            var permissions = new PermissionsController(backOfficeRequestContext);
            permissions.InjectDependencies(GetBackOfficeRequestContext());

            //Assert
            Assert.IsTrue(ActionIsSecuredByPermission(controller, "CreateNew", FixedPermissionIds.Create));
            Assert.IsTrue(ActionIsSecuredByPermission(controller, "Edit", FixedPermissionIds.Update));
            Assert.IsTrue(ActionIsSecuredByPermission(controller, "Delete", FixedPermissionIds.Delete));
            Assert.IsTrue(ActionIsSecuredByPermission(copyController, "Copy", FixedPermissionIds.Copy));
            Assert.IsTrue(ActionIsSecuredByPermission(copyController, "Move", FixedPermissionIds.Move));
            Assert.IsTrue(ActionIsSecuredByPermission(sortController, "Sort", FixedPermissionIds.Sort));
            Assert.IsTrue(ActionIsSecuredByPermission(publishController, "Publish", FixedPermissionIds.Publish));
            Assert.IsTrue(ActionIsSecuredByPermission(permissions, "Permissions", FixedPermissionIds.Permissions));
            Assert.IsTrue(ActionIsSecuredByPermission(rollback, "Rollback", FixedPermissionIds.Rollback));

            // TODO: (APN @ Matt) the assertion for action name doesn't take into account two methods with the same name
            // but differing parameter counts, so this one fails
            // NOTE: (MPB) Have renamed post action to HostnameForm to get test passing for now, not sure if that is enough
            // or whether assertion method should allow you to query for a specific method signature?
            Assert.IsTrue(ActionIsSecuredByPermission(hos, "Hostname", FixedPermissionIds.Hostnames));
        }
예제 #15
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 = UmbracoController.GetControllerName(contentEditor.GetType());
            var contentControllerId = UmbracoController.GetControllerId<EditorAttribute>(contentEditor.GetType());

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

            var docTypeEditor = new DocumentTypeEditorController(new FakeBackOfficeRequestContext());
            var docTypeControllerName = UmbracoController.GetControllerName(docTypeEditor.GetType());
            var docTypeControllerId = UmbracoController.GetControllerId<EditorAttribute>(docTypeEditor.GetType());
            
            const string customAction = "Index";
            const string defaultAction = "Dashboard";
            const int id = -1;
            const string area = "Umbraco";

            //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("/Umbraco/Editors/{0}", contentControllerName), contentEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Umbraco/Editors/{0}", dataTypeControllerName), dataTypeEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Umbraco/Editors/{0}", docTypeControllerName), docTypeEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Umbraco/Editors/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl);
            Assert.AreEqual(string.Format("/Umbraco/Editors/{0}/{1}/{2}", dataTypeControllerName, customAction, id), dataTypeEditorCustomUrl);
            Assert.AreEqual(string.Format("/Umbraco/Editors/{0}/{1}/{2}", docTypeControllerName, customAction, id), docTypeEditorCustomUrl);
        }
        public void ContentEditorControllerTest_All_Standard_Values_Bound()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());

            var controller = new ContentEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  { "Name", "Demo"},
                                                  { "SelectedTemplateId", "1042" }, //i know that 1042 is in our mocked template resolver
                                                  { "UtcPublishScheduled", "2013-01-01" },
                                                  { "UtcUnpublishScheduled", "2014-01-01" }
                                              }, GetBackOfficeRequestContext());

            //Act
            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model = (ContentEditorModel)result.Model;

            //Assert
            Assert.AreEqual("Demo", model.Name);
            //Assert.AreEqual(new HiveId(1042), model.SelectedTemplateId);
            Assert.AreEqual(new DateTime(2013, 1, 1, 0, 0, 0), model.UtcPublishScheduled);
            Assert.AreEqual(new DateTime(2014, 1, 1, 0, 0, 0), model.UtcUnpublishScheduled);
        }
        public void ContentEditorControllerTests_Invalid_Model_State_When_Missing_Required_Values()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());

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

            //Act
            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model = (ContentEditorModel)result.Model;

            //Assert
            Assert.IsFalse(controller.ModelState.IsValidField("Name"));
        }
        public void ContentEditorControllerTests_Content_Published()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor(),
                c =>
                {
                    c.MetaData.UtcStatusChanged = DateTime.Now;
                    c.MetaData.StatusType = FixedStatusTypes.Draft;
                });

            var controller = new ContentEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  { "Name", "hello"},
                                                  { "submit.Publish", "Publish"} //set Publish flag
                                              }, GetBackOfficeRequestContext(), false);

            //Act

            var result = controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);

            //Assert

            Assert.IsTrue(result is RedirectToRouteResult);

            using (var uow = UmbracoApplicationContext.Hive.OpenReader<IContentStore>())
            {
                var snapshot = uow.Repositories.Revisions.GetLatestSnapshot<TypedEntity>(contentEntity.Item.Id);
                if (snapshot == null)
                    Assert.Fail("no snapshot found");

                var contentViewModel = UmbracoApplicationContext.FrameworkContext.TypeMappers.Map<EntitySnapshot<TypedEntity>, ContentEditorModel>(snapshot);
                Assert.IsNotNull(contentViewModel.UtcPublishedDate);
                Assert.IsTrue(DateTimeOffset.UtcNow.Subtract(contentViewModel.UtcPublishedDate.Value) < new TimeSpan(0, 1, 0));
            }
        }
        public void ContentEditorControllerTests_Content_Saved()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());

            var controller = new ContentEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  { "Name", "Demo"},
                                                  { contentEntity.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Id.GetHtmlId() + ".Name", "test"},
                                                  { contentEntity.Item.Attributes[NodeNameAttributeDefinition.AliasValue].Id.GetHtmlId() + ".UrlName", "test"},
                                                  { contentEntity.Item.Attributes["bodyText"].Id.GetHtmlId() + ".Value", "1234"},
                                                  { contentEntity.Item.Attributes["siteName"].Id.GetHtmlId() + ".Value", "4321"},                                                  
                                                  { "submit.Save", "Save"} //set save flag
                                              }, GetBackOfficeRequestContext(), false);

            //Act

            var result = controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);

            //Assert

            Assert.IsTrue(result is RedirectToRouteResult);

            using (var uow = UmbracoApplicationContext.Hive.OpenReader<IContentStore>())
            {
                var snapshot = uow.Repositories.Revisions.GetLatestSnapshot<TypedEntity>(contentEntity.Item.Id);
                if (snapshot == null)
                    Assert.Fail("no snapshot found");

                Assert.AreNotEqual(contentEntity.MetaData.Id, snapshot.Revision.MetaData.Id);
                Assert.IsTrue(contentEntity.MetaData.UtcCreated < snapshot.Revision.MetaData.UtcCreated);
                var contentViewModel = UmbracoApplicationContext.FrameworkContext.TypeMappers.Map<EntitySnapshot<TypedEntity>, ContentEditorModel>(snapshot);
                Assert.AreEqual(null, contentViewModel.UtcPublishedDate);
            }
        }
        public void ContentEditorControllerTests_Regex_Property_Bound_And_Invalidated()
        {
            //Arrange

            var contentEntity = CreateEntityRevision(new RegexPropertyEditor());
            var customAttribute = contentEntity.Item.Attributes.Last();
            var controller = new ContentEditorController(GetBackOfficeRequestContext());
            controller.InjectDependencies(new Dictionary<string, string>(), new Dictionary<string, string>
                                              {
                                                  //there will be 2 attributes, one for node name and a custom one
                                                  { customAttribute.Id.GetHtmlId() + ".Value", "asd"}
                                              }, GetBackOfficeRequestContext());

            //Act

            var result = (ViewResult)controller.EditForm(contentEntity.Item.Id, contentEntity.MetaData.Id);
            var model = (ContentEditorModel)result.Model;

            //Assert

            Assert.IsFalse(controller.ModelState.IsValidField(customAttribute.Id.GetHtmlId() + ".Value"));
        }