Inheritance: DefaultMenuAction, MenuAction
示例#1
0
 public IActionResult UpdateItem(Guid id, [FromBody] UpdateMenuItem model)
 {
     model.SiteId = SiteId;
     model.MenuId = id;
     _commandSender.Send <UpdateMenuItem, Menu>(model);
     return(new NoContentResult());
 }
示例#2
0
 public IActionResult UpdateItem(Guid id, [FromBody] UpdateMenuItem model)
 {
     model.SiteId = SiteId;
     model.MenuId = id;
     _dispatcher.SendAndPublish <UpdateMenuItem, Menu>(model);
     return(new NoContentResult());
 }
示例#3
0
        public async Task <IActionResult> UpdateItem(Guid id, [FromBody] UpdateMenuItem model)
        {
            model.SiteId = SiteId;
            model.MenuId = id;
            await Task.Run(() => _commandSender.Send <UpdateMenuItem, Menu>(model));

            return(new NoContentResult());
        }
 public void Should_throw_exception_if_menu_item_does_not_exist()
 {
     _command = new UpdateMenuItem
     {
         MenuItemId = Guid.NewGuid(),
     };
     Assert.Throws <Exception>(() => _menu.UpdateMenuItem(_command, _validatorMock.Object));
 }
示例#5
0
        public void Update(UpdateMenuItem cmd)
        {
            Type   = cmd.Type;
            PageId = cmd.PageId;
            Link   = cmd.Link;
            Text   = cmd.Text;
            Title  = cmd.Title;

            SetLocalisations(cmd.MenuItemLocalisations);
            SetPermisisons(cmd.MenuItemPermissions);
        }
示例#6
0
        public void Update(UpdateMenuItem cmd)
        {
            MenuItemType = cmd.MenuItemType;
            PageId       = cmd.PageId;
            Link         = cmd.Link;
            Text         = cmd.Text;
            Title        = cmd.Title;

            MenuItemLocalisations.Clear();

            foreach (var item in cmd.MenuItemLocalisations)
            {
                AddLocalisation(item.LanguageId, item.Text, item.Title);
            }
        }
        public void Should_throw_exception_if_menu_not_found()
        {
            var command = new UpdateMenuItem
            {
                MenuId = Guid.NewGuid()
            };

            var menuRepositoryMock = new Mock <IMenuRepository>();

            menuRepositoryMock.Setup(x => x.GetById(command.MenuId)).Returns((Menu)null);

            var validatorMock = new Mock <IValidator <UpdateMenuItem> >();

            var handler = new UpdateMenuItemHandler(menuRepositoryMock.Object, validatorMock.Object);

            Assert.Throws <Exception>(() => handler.Handle(command));
        }
示例#8
0
        public void UpdateMenuItem(UpdateMenuItem cmd, IValidator <UpdateMenuItem> validator)
        {
            var menuItem = MenuItems.FirstOrDefault(x => x.Id == cmd.MenuItemId);

            if (menuItem == null || menuItem.Status == MenuItemStatus.Deleted)
            {
                throw new Exception("Menu item not found");
            }

            validator.ValidateCommand(cmd);

            AddEvent(new MenuItemUpdated
            {
                SiteId          = SiteId,
                AggregateRootId = Id,
                MenuName        = Name,
                MenuItem        = new MenuItem(cmd, menuItem.SortOrder)
            });
        }
        public void Should_throw_exception_when_validation_fails()
        {
            var command = new UpdateMenuItem
            {
                SiteId                = Guid.NewGuid(),
                MenuId                = Guid.NewGuid(),
                MenuItemId            = Guid.NewGuid(),
                MenuItemLocalisations = new List <MenuItemDetails.MenuItemLocalisation>()
            };

            var menuRepositoryMock = new Mock <IMenuRepository>();

            menuRepositoryMock.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(new Menu());

            var validatorMock = new Mock <IValidator <UpdateMenuItem> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult(new List <ValidationFailure> {
                new ValidationFailure("Id", "Id Error")
            }));

            var createMenuHandler = new UpdateMenuItemHandler(menuRepositoryMock.Object, validatorMock.Object);

            Assert.Throws <Exception>(() => createMenuHandler.Handle(command));
        }
示例#10
0
        public void Setup()
        {
            _menu = new Menu();

            var menuItemId = Guid.NewGuid();

            var addMenuItemCommand = new AddMenuItem
            {
                SiteId                = _menu.SiteId,
                MenuId                = Guid.NewGuid(),
                MenuItemId            = menuItemId,
                MenuItemType          = MenuItemType.Link,
                PageId                = Guid.NewGuid(),
                Link                  = "link",
                Text                  = "Text",
                Title                 = "Title",
                MenuItemLocalisations = new List <MenuItemDetails.MenuItemLocalisation>
                {
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 1",
                        Title      = "Title 1"
                    },
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 2",
                        Title      = "Title 2"
                    }
                }
            };

            var addMenuItemValidatorMock = new Mock <IValidator <AddMenuItem> >();

            addMenuItemValidatorMock.Setup(x => x.Validate(addMenuItemCommand)).Returns(new ValidationResult());

            _menu.AddMenuItem(addMenuItemCommand, addMenuItemValidatorMock.Object);

            _command = new UpdateMenuItem
            {
                SiteId                = _menu.SiteId,
                MenuId                = _menu.Id,
                MenuItemId            = menuItemId,
                MenuItemLocalisations = new List <MenuItemDetails.MenuItemLocalisation>
                {
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 1",
                        Title      = "Title 1"
                    },
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 2",
                        Title      = "Title 2"
                    }
                }
            };

            _validatorMock = new Mock <IValidator <UpdateMenuItem> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _menu.UpdateMenuItem(_command, _validatorMock.Object);

            _menuItem = _menu.MenuItems.FirstOrDefault(c => c.Id == _command.MenuItemId);

            _firstMenuItemLocalisation = _menuItem.MenuItemLocalisations.FirstOrDefault();

            _event = _menu.Events.OfType <MenuItemUpdated>().SingleOrDefault();
        }
        public void Should_update_menu_when_add_menu_item()
        {
            var menu = new Menu();

            var menuItemId = Guid.NewGuid();

            var addMenuItemCommand = new AddMenuItem
            {
                SiteId                = Guid.NewGuid(),
                MenuId                = Guid.NewGuid(),
                MenuItemId            = menuItemId,
                MenuItemType          = MenuItemType.Link,
                PageId                = Guid.NewGuid(),
                Link                  = "link",
                Text                  = "Text",
                Title                 = "Title",
                MenuItemLocalisations = new List <MenuItemDetails.MenuItemLocalisation>
                {
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 1",
                        Title      = "Title 1"
                    },
                    new MenuItemDetails.MenuItemLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Text       = "Text 2",
                        Title      = "Title 2"
                    }
                }
            };

            var addMenuItemValidatorMock = new Mock <IValidator <AddMenuItem> >();

            addMenuItemValidatorMock.Setup(x => x.Validate(addMenuItemCommand)).Returns(new ValidationResult());

            menu.AddMenuItem(addMenuItemCommand, addMenuItemValidatorMock.Object);

            var command = new UpdateMenuItem
            {
                SiteId                = Guid.NewGuid(),
                MenuId                = Guid.NewGuid(),
                MenuItemId            = menuItemId,
                MenuItemLocalisations = new List <MenuItemDetails.MenuItemLocalisation>()
            };

            var menuRepositoryMock = new Mock <IMenuRepository>();

            menuRepositoryMock.Setup(x => x.GetById(command.SiteId, command.MenuId)).Returns(menu);
            menuRepositoryMock.Setup(x => x.Update(menu));

            var validatorMock = new Mock <IValidator <UpdateMenuItem> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var createMenuHandler = new UpdateMenuItemHandler(menuRepositoryMock.Object, validatorMock.Object);

            createMenuHandler.Handle(command);

            menuRepositoryMock.Verify(x => x.Update(menu));
        }