public void Does_not_send_CreatePageCommand_command_when_ModelState_is_not_valid()
        {
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
                                                        {
                                                            ParentTreeNodeId = "2",
                                                        };

            var contentTreeNodeController = mocker.Resolve<ContentTreeNodeController>();
            contentTreeNodeController.ModelState.AddModelError("key", "error");
            contentTreeNodeController.Create(contentTreeNodeInputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.IsAny<CreatePageCommand>()), Times.Never());
        }
        public void Does_not_call_Create_method_of_IContentTreeNodeContext_when_ModelState_is_invalid()
        {
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
            {
                ParentTreeNodeId = "2",
                Type = typeof(string).AssemblyQualifiedName
            };
            var contentTreeNodeController = mocker.Resolve<ContentTreeNodeController>();
            contentTreeNodeController.ModelState.AddModelError("key", "error");
            contentTreeNodeController.Create(contentTreeNodeInputModel);

            mocker.GetMock<IContentTree>().Verify(a => a.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never());
        }
        public void Calls_Create_method_of_IContentTreeNodeContext_when_ModelState_is_valid()
        {
            mocker.GetMock<IContentTree>().Setup(a => a.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(new Guid().ToString());
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
                                            {
                                                ParentTreeNodeId = "2",
                                                Type = typeof(string).AssemblyQualifiedName
                                            };

            mocker.Resolve<ContentTreeNodeController>().Create(contentTreeNodeInputModel);

            mocker.GetMock<IContentTree>().Verify(a =>a.Create(contentTreeNodeInputModel.ParentTreeNodeId, contentTreeNodeInputModel.Type, contentTreeNodeInputModel.ControllerName), Times.Once());
        }
        public void Sets_input_model_ContentItemId_to_value_passed_in_when_the_content_tree_node_is_not_returned_from_the_repository()
        {
            var expectedInputModel = new ContentTreeNodeInputModel()
            {
                Name = "some name",
                Action = "contentItemId"
            };

            var landingPageController = mocker.Resolve<ContentTreeNodeController>();
            var result = landingPageController.Modify("1", "contentItemId");

            Assert.AreEqual("contentItemId", ((ModifyViewModel)((ViewResult)result).ViewData.Model).ContentTreeNodeInputModel.Action);
        }
        public override ActionResult Modify(ContentTreeNodeInputModel contentTreeNodeInputModel)
        {
            var result = base.Modify(contentTreeNodeInputModel);
            if ((result as RedirectToRouteResult) == null) return result;

            return new RedirectToRouteResult(new RouteValueDictionary()
                                             	{
                                             		{"controller", "HomepageContentTreeNode"},
                                                    {"action", "Modify"},
                                                    { "treeNodeId", contentTreeNodeInputModel == null ? "0" : contentTreeNodeInputModel.TreeNodeId },
                                                    { "contentItemId", contentTreeNodeInputModel == null ? "Index" : contentTreeNodeInputModel.Action },
                                             	});
        }
        public void Sets_input_model_ContentItemId_to_Index_when_content_tree_node_pulled_from_repository_is_null()
        {
            var expectedInputModel = new ContentTreeNodeInputModel()
            {
                Name = "some name",
            };
            mocker.GetMock<IContentTreeNodeToContentTreeNodeInputModelMapper>().Setup(a => a.CreateInstance(It.Is<ContentTreePageNode>(b => b.Id == "1" && b.Action == "Index")))
                .Returns(expectedInputModel);

            var landingPageController = mocker.Resolve<ContentTreeNodeController>();
            var result = landingPageController.Modify("1", null);

            var viewModel = (ModifyViewModel)((ViewResult)result).ViewData.Model;
            Assert.AreEqual("Index", viewModel.ContentTreeNodeInputModel.Action);
        }
        public void Does_not_send_ModifyPage_command_when_ModelState_is_not_valid()
        {
            var inputModel = new ContentTreeNodeInputModel()
                                        {
                                            Name = "name",
                                            TreeNodeId = "treeNodeId",
                                            Action = "Index"
                                        };

            var controller = mocker.Resolve<ContentTreeNodeController>();
            controller.ModelState.AddModelError("key", "error");
            controller.Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.IsAny<ModifyPageCommand>()), Times.Never());
        }
        public void Calls_SafeFileByTreeNodeIdAndAction_method_of_IContentTreeNodeFileUploadPersister()
        {
            var guid = new Guid().ToString();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.CreateTreeNodeAndReturnTreeNodeId(It.IsAny<ContentTreeNodeInputModel>())).Returns(guid);
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
            {
                ParentTreeNodeId = "2",
                Type = typeof(string).AssemblyQualifiedName,
                HeaderImage = "test",
                Action = "Index",

            };

            mocker.Resolve<ContentTreeNodeController>().Create(contentTreeNodeInputModel);

            mocker.GetMock<IContentTreeNodeFileUploadPersister>()
                .Verify(a => a.SaveFilesByTreeNodeIdAndAction(guid, contentTreeNodeInputModel.Action), Times.Once());
        }
        public void Does_not_send_ModifyPage_command_when_attempting_to_modify_a_page_that_does_not_exist()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
                                    {
                                        TreeNodeId = treeNodeId.ToString(),
                                        Action = "Confirmation"
                                    };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.IsAny<ModifyPageCommand>()), Times.Never());
        }
        public void Calls_SaveFileByTreeNodeIdAndAction_method_of_IContentTreeNodeFileUploadPersister()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
            {
                TreeNodeId = treeNodeId.ToString(),
                Action = "Confirmation",
                HeaderImage = "test"
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<IContentTreeNodeFileUploadPersister>()
                .Verify(a => a.SaveFilesByTreeNodeIdAndAction(treeNodeId.ToString(), inputModel.Action), Times.Once());
        }
        public void Sends_CreatePageCommand_with_PageId_from_IGuidGetter_when_attempting_to_modify_a_page_that_does_not_exist()
        {
            var pageId = Guid.NewGuid();
            mocker.GetMock<IGuidGetter>().Setup(a => a.GetGuid()).Returns(pageId);
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
            {
                TreeNodeId = treeNodeId.ToString(),
                Action = "Confirmation"
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<CreatePageCommand>(b => b.PageId == pageId)), Times.Once());
        }
        public void Sends_CreatePageCommand_with_correct_Hidden_property_value_when_attempting_to_modify_a_page_that_does_not_exist()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
            {
                TreeNodeId = treeNodeId.ToString(),
                Action = "Confirmation",
                Hidden = true,
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<CreatePageCommand>(b => b.Hidden == inputModel.Hidden)), Times.Once());
        }
        public void Sends_CreatePageCommand_with_LastModifyBy_set_when_attempting_to_modify_a_page_that_does_not_exist()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreePageNodeContext>().Setup(a => a.GetAllContentTreePageNodes())
                .Returns(new ContentTreePageNode[]
                         	{
                         		new ContentTreePageNode()
                         			{
                         				Id = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            }.AsQueryable());
            var inputModel = new ContentTreeNodeInputModel()
            {
                TreeNodeId = treeNodeId.ToString(),
                Action = "Confirmation",
                Name = "name"
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<CreatePageCommand>(b => b.LastModifyBy == "test")), Times.Once());
        }
        public void Sends_ModifyPage_command_with_HeaderImage_property_set_to_null_when_RemoveHeaderImage_checkbox_is_checked_and_ModelState_is_valid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
            {
                Name = "name",
                PageId = Guid.NewGuid().ToString(),
                TreeNodeId = treeNodeId.ToString(),
                Action = "Index",
                RemoveHeaderImage = true,
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>()
                .Verify(a => a.Send(It.Is<ModifyPageCommand>(b => b.HeaderImage == null)), Times.Once());
        }
        public void Sends_PagePublishedCommand_with_correct_PageId_set_when_input_model_FormAction_property_begins_with_Publish()
        {
            var treeNodeId = Guid.NewGuid();
            var pageId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
            {
                PageId = pageId.ToString(),
                TreeNodeId = treeNodeId.ToString(),
                Action = "Index",
                FormAction = "Publish and Exit"
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<PublishPageCommand>(b => b.PageId == pageId)), Times.Once());
        }
        public void Returns_RedirectResult_when_ModelState_is_valid()
        {
            var guid = Guid.NewGuid().ToString();
            mocker.GetMock<IContentTree>()
                .Setup(a => a.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns(guid);
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
                                                    {
                                                        ParentTreeNodeId = "2",
                                                        Type = typeof(string).AssemblyQualifiedName
                                                    };

            var result = mocker.Resolve<ContentTreeNodeController>().Create(contentTreeNodeInputModel);

            Assert.AreEqual(guid, (result as RedirectToRouteResult).RouteValues["TreeNodeId"].ToString());
            Assert.AreEqual(typeof(ContentTreeNodeController).Name.Replace("Controller", string.Empty), (result as RedirectToRouteResult).RouteValues["controller"].ToString());
            Assert.AreEqual("Modify", (result as RedirectToRouteResult).RouteValues["action"].ToString());
        }
        public void Only_sends_a_single_ModifyPage_command()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
                                    {
                                        PageId = Guid.NewGuid().ToString(),
                                        TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index"
                                    };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.IsAny<ModifyPageCommand>()), Times.Once());
        }
        public void Sends_ModifyPage_command_with_correct_UrlSegment_when_ModelState_is_valid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreePageNodeContext>().Setup(a => a.GetAllContentTreePageNodes())
                .Returns(new ContentTreePageNode[]
                         	{
                         		new ContentTreePageNode()
                         			{
                         				Id = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            }.AsQueryable());
            var inputModel = new ContentTreeNodeInputModel()
                                    {
                                        PageId = Guid.NewGuid().ToString(),
                                        TreeNodeId = treeNodeId.ToString(),
                                        UrlSegment = "test",
                                        Action = "Index",
                                    };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<ModifyPageCommand>(b => b.UrlSegment == inputModel.UrlSegment)), Times.Once());
        }
        public void Sends_ModifyPage_command_with_HeaderImage_property_set_from_input_model_when_RemoveHeaderImage_is_false_and_ModelState_is_valid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreePageNodeContext>().Setup(a => a.GetAllContentTreePageNodes())
                .Returns(new ContentTreePageNode[]
                         	{
                         		new ContentTreePageNode()
                         			{
                         				Id = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            }.AsQueryable());
            var inputModel = new ContentTreeNodeInputModel()
            {
                Name = "name",
                PageId = Guid.NewGuid().ToString(),
                TreeNodeId = treeNodeId.ToString(),
                Action = "Index",
                HeaderImage = new FileUploadInputModel()
                                  {
                                      Id = "test"
                                  },
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>()
                .Verify(a => a.Send(It.Is<ModifyPageCommand>(b => b.HeaderImage == "test")), Times.Once());
        }
        public void Does_not_send_PagePublishedCommand_with_correct_PageId_set_when_input_model_FormAction_property_does_not_begin_with_Publish()
        {
            var pageId = Guid.NewGuid();
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreePageNodeContext>().Setup(a => a.GetAllContentTreePageNodes())
                .Returns(new ContentTreePageNode[]
                         	{
                         		new ContentTreePageNode()
                         			{
                         				Id = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            }.AsQueryable());
            var inputModel = new ContentTreeNodeInputModel()
            {
                PageId = pageId.ToString(),
                TreeNodeId = treeNodeId.ToString(),
                Action = "Index",
                FormAction = "Exit"
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<PublishPageCommand>(b => b.PageId == pageId)), Times.Never());
        }
        public virtual ActionResult Create(ContentTreeNodeInputModel contentTreeNodeInputModel)
        {
            if (string.IsNullOrEmpty(contentTreeNodeInputModel.Action)) contentTreeNodeInputModel.Action = "Index";
            if (ModelState.IsValid == false)
                return View("Modify", new ModifyViewModel()
                                      	{
                                      		ContentTreeNodeInputModel = contentTreeNodeInputModel,
                                            Action = "Create",
                                      	});

            var treeNodeId = contentTree.Create(contentTreeNodeInputModel.ParentTreeNodeId, contentTreeNodeInputModel.Type, contentTreeNodeInputModel.ControllerName);

            commandBus.Send(new CreatePageCommand()
                                {
                                    PageId = guidGetter.GetGuid(),
                                    TreeNodeId = new Guid(treeNodeId),
                                    Body = contentTreeNodeInputModel.Body,
                                    HeaderText = contentTreeNodeInputModel.HeaderText,
                                    HeaderImage = contentTreeNodeInputModel.HeaderImage == null ? null : contentTreeNodeInputModel.HeaderImage.Id,
                                    Name = contentTreeNodeInputModel.Name,
                                    Sequence = contentTreeNodeInputModel.Sequence,
                                    UrlSegment = contentTreeNodeInputModel.UrlSegment,
                                    Type = Type.GetType(contentTreeNodeInputModel.Type),
                                    Inactive = contentTreeNodeInputModel.Inactive,
                                    Hidden = contentTreeNodeInputModel.Hidden,
                                    LastModifyBy = currentUserContext.GetCurrentPrincipal().Identity.Name,
                                    WorkflowStatus = contentTreeNodeInputModel.WorkflowStatus,
                                    IsNew = contentTreeNodeInputModel.IsNew
                                });

            if (!string.IsNullOrEmpty(contentTreeNodeInputModel.FormAction))
            {
                if (contentTreeNodeInputModel.FormAction.ToLower() == "save and exit")
                    return new RedirectToRouteResult(new RouteValueDictionary()
                                             	{
                                             		{"controller", "TreeManager"},
                                                    {"action", "Index"},
                                             	});
            }
            return new RedirectToRouteResult(new RouteValueDictionary()
                                                 {
                                                     {"controller", GetType().Name.Replace("Controller", string.Empty)},
                                                     {"action", "Modify"},
                                                     {"TreeNodeId", treeNodeId}
                                                 });
        }
        public void Sends_ModifyPage_command_when_ModelState_is_valid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreePageNodeContext>().Setup(a => a.GetAllContentTreePageNodes())
                .Returns(new ContentTreePageNode[]
                         	{
                         		new ContentTreePageNode()
                         			{
                         				Id = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            }.AsQueryable());
            var inputModel = new ContentTreeNodeInputModel()
                                        {
                                            Name = "name",
                                            PageId = Guid.NewGuid().ToString(),
                                            TreeNodeId = treeNodeId.ToString(),
                                            Action = "Index"
                                        };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.IsAny<ModifyPageCommand>()), Times.Once());
        }
        public void Sends_ModifyPage_command_with_correct_ParentId_when_ModelState_is_valid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
                                    {
                                        PageId = Guid.NewGuid().ToString(),
                                        TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                                        ParentTreeNodeId = "123"
                                    };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<ModifyPageCommand>(b => b.ParentId.ToString() == inputModel.ParentTreeNodeId)), Times.Once());
        }
        public void Returns_redirect_result_to_content_tree_index_when_ModelState_is_valid_and_input_model_action_is_saveandexit()
        {
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
                                            {
                                                TreeNodeId = Guid.NewGuid().ToString(),
                                                PageId = Guid.NewGuid().ToString(),
                                                Name = "name",
                                                Action = "Index",
                                                FormAction = "Save and Exit"
                                            };
            mocker.GetMock<IContentTreeNodeInputModelToContentTreeNodeMapper>()
                .Setup(a => a.CreateInstance(contentTreeNodeInputModel)).Returns(new ContentTreeNode()
                                                                                    {
                                                                                        Name = "name",
                                                                                    });

            var contentTreeNodeController = mocker.Resolve<ContentTreeNodeController>();
            var result = contentTreeNodeController.Modify(contentTreeNodeInputModel);

            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }
        public void Sends_ModifyPage_command_with_HeaderImage_property_set_from_draft_header_image_when_RemoveHeaderImage_is_false_and_the_input_model_HeaderImage_property_is_empty_and_ModelState_is_valid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                                        HeaderImage = "headerImage.jpg"
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
            {
                Name = "name",
                PageId = Guid.NewGuid().ToString(),
                TreeNodeId = treeNodeId.ToString(),
                Action = "Index",
                HeaderImage = string.Empty
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>()
                .Verify(a => a.Send(It.Is<ModifyPageCommand>(b => b.HeaderImage == "headerImage.jpg")), Times.Once());
        }
        public void Returns_redirect_result_when_ModelState_is_valid()
        {
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
                                                        {
                                                            PageId = Guid.NewGuid().ToString(),
                                                            TreeNodeId = Guid.NewGuid().ToString(),
                                                            Name = "name",
                                                        };
            mocker.GetMock<IContentTreeNodeInputModelToContentTreeNodeMapper>()
                .Setup(a => a.CreateInstance(contentTreeNodeInputModel)).Returns(new ContentTreeNode()
                                                                                    {
                                                                                        Name = "name",
                                                                                    });

            var contentTreeNodeController = mocker.Resolve<ContentTreeNodeController>();
            var result = contentTreeNodeController.Modify(contentTreeNodeInputModel);

            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }
        public void Sends_ModifyPage_command_with_LastModifyBy_set_when_ModelState_is_valid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var inputModel = new ContentTreeNodeInputModel()
            {
                PageId = Guid.NewGuid().ToString(),
                TreeNodeId = treeNodeId.ToString(),
                UrlSegment = "test",
                Action = "Index",
            };

            mocker.Resolve<ContentTreeNodeController>().Modify(inputModel);

            mocker.GetMock<ICommandBus>().Verify(a => a.Send(It.Is<ModifyPageCommand>(b => b.LastModifyBy == "test")), Times.Once());
        }
        public void Returns_view_model_with_input_model_set_to_the_same_as_was_passed_in_when_ModelState_is_invalid()
        {
            var treeNodeId = Guid.NewGuid();
            mocker.GetMock<IContentTreeNodeContext>().Setup(a => a.GetContentTreeNodesByTreeId(treeNodeId.ToString()))
                .Returns(new ContentTreeNode[]
                         	{
                         		new ContentTreeNode()
                         			{
                         				TreeNodeId = treeNodeId.ToString(),
                                        Action = "Index",
                         			},
                            });
            var contentTreeNodeInputModel = new ContentTreeNodeInputModel()
                                                    {
                                                        TreeNodeId = treeNodeId.ToString(),
                                                        Name = "name",
                                                        Action = "Index",
                                                    };
            mocker.GetMock<IContentTreeNodeInputModelToContentTreeNodeMapper>()
                .Setup(a => a.CreateInstance(contentTreeNodeInputModel)).Returns(new ContentTreeNode()
                                                                                    {
                                                                                        Name = "name",
                                                                                    });

            var contentTreeNodeController = mocker.Resolve<ContentTreeNodeController>();
            contentTreeNodeController.ModelState.AddModelError("key", "error");
            var result = contentTreeNodeController.Modify(contentTreeNodeInputModel);

            var contentTreeNodeViewModel = (ModifyViewModel)((ViewResult) result).ViewData.Model;
            Assert.AreEqual(contentTreeNodeInputModel, contentTreeNodeViewModel.ContentTreeNodeInputModel);
        }
 public string CreateTreeNodeAndReturnTreeNodeId(ContentTreeNodeInputModel contentTreeNodeInputModel)
 {
     var newTreeNodeId = treeNodeSummaryContext.Create(contentTreeNodeInputModel.ParentTreeNodeId, contentTreeNodeInputModel.Type);
     contentTreeNodeInputModel.TreeNodeId = newTreeNodeId;
     return contentTreeNodeInputModel.TreeNodeId;
 }
        public virtual ActionResult Modify(ContentTreeNodeInputModel contentTreeNodeInputModel)
        {
            contentTreeNodeFileUploadPersister.SaveFilesByTreeNodeIdAndAction(contentTreeNodeInputModel.TreeNodeId, contentTreeNodeInputModel.Action);
            if (ModelState.IsValid == false)
                return View("Modify", new ModifyViewModel() { Action = "Modify", ContentTreeNodeInputModel = contentTreeNodeInputModel });

            var contentTreeNode = contentTreePageNodeContext.GetAllContentTreePageNodes().Where(a => a.Id == contentTreeNodeInputModel.TreeNodeId && a.Action == contentTreeNodeInputModel.Action).FirstOrDefault();
            if (contentTreeNode != null)
            {
                var modifyPageComand = new ModifyPageCommand()
                {
                    AggregateRootId = new Guid(contentTreeNodeInputModel.PageId),
                    TreeNodeId = new Guid(contentTreeNodeInputModel.TreeNodeId),
                    HeaderText = contentTreeNodeInputModel.HeaderText,
                    HeaderImage = contentTreeNodeInputModel.HeaderImage == null ? null : contentTreeNodeInputModel.HeaderImage.Id,
                    Name = contentTreeNodeInputModel.Name,
                    Body = contentTreeNodeInputModel.Body,
                    ParentId = contentTreeNodeInputModel.ParentTreeNodeId,
                    Sequence = contentTreeNodeInputModel.Sequence,
                    UrlSegment = contentTreeNodeInputModel.UrlSegment,
                    ActionId = contentTreeNodeInputModel.Action,
                    Hidden = contentTreeNodeInputModel.Hidden,
                    Inactive = contentTreeNodeInputModel.Inactive,
                    LastModifyBy = currentUserContext.GetCurrentPrincipal().Identity.Name,
                    ControllerName = contentTreeNodeInputModel.ControllerName,
                    WorkflowStatus = contentTreeNodeInputModel.WorkflowStatus,
                    IsNew = contentTreeNodeInputModel.IsNew
                };
                commandBus.Send(modifyPageComand);
            } else {
                commandBus.Send(new CreatePageCommand()
                                    {
                                        TreeNodeId = new Guid(contentTreeNodeInputModel.TreeNodeId),
                                        PageId = guidGetter.GetGuid(),
                                        Body = contentTreeNodeInputModel.Body,
                                        HeaderText = contentTreeNodeInputModel.HeaderText,
                                        HeaderImage = contentTreeNodeInputModel.HeaderImage == null ? null : contentTreeNodeInputModel.HeaderImage.Id,
                                        Name = contentTreeNodeInputModel.Name,
                                        UrlSegment = contentTreeNodeInputModel.UrlSegment,
                                        Action = contentTreeNodeInputModel.Action,
                                        Hidden = contentTreeNodeInputModel.Hidden,
                                        Inactive = contentTreeNodeInputModel.Inactive,
                                        LastModifyBy = currentUserContext.GetCurrentPrincipal().Identity.Name,
                                        WorkflowStatus = contentTreeNodeInputModel.WorkflowStatus,
                                        IsNew = contentTreeNodeInputModel.IsNew
                                    });
            }

            if ((!string.IsNullOrEmpty(contentTreeNodeInputModel.FormAction)) && (contentTreeNodeInputModel.FormAction.StartsWith("Publish")))
                commandBus.Send(new PublishPageCommand()
                                        {
                                            PageId = new Guid(contentTreeNodeInputModel.PageId)
                                        });

            if ((!string.IsNullOrEmpty(contentTreeNodeInputModel.FormAction)) && (contentTreeNodeInputModel.FormAction.StartsWith("Revert")))
                commandBus.Send(new RevertPageCommand
                                    {
                                        PageId = new Guid(contentTreeNodeInputModel.PageId)
                                    });

            if (!string.IsNullOrEmpty(contentTreeNodeInputModel.FormAction))
            {
                if (contentTreeNodeInputModel.FormAction.ToLower() == "save and exit" || contentTreeNodeInputModel.FormAction.ToLower() == "publish and exit")
                    return new RedirectToRouteResult(new RouteValueDictionary()
                                             	{
                                             		{"controller", "TreeManager"},
                                                    {"action", "Index"},
                                             	});
            }

            return new RedirectToRouteResult(new RouteValueDictionary()
                                             	{
                                             		{"controller", "ContentTreeNode"},
                                                    {"action", "Modify"},
                                                    { "treeNodeId", contentTreeNodeInputModel == null ? "0" : contentTreeNodeInputModel.TreeNodeId },
                                                    { "contentItemId", contentTreeNodeInputModel == null ? "Index" : contentTreeNodeInputModel.Action },
                                             	});
        }