/// <summary>
        ///     Determines whether the command is supported for the given item
        /// </summary>
        /// <param name="item">the context item</param>
        /// <returns>a value indicating if the command is supported</returns>
        public bool CanExecute(Item item)
        {
            if (!_pageModeAccess.CanWebEdit() || !_pageModeAccess.CanDesignItem(item) ||
                !item.IsBaseLayoutItem())
            {
                return false;
            }

            var args = new GetBaseLayoutItemsArgs(item);
            _pipelineRunner.Run(args);

            return args.BaseLayoutItems.Count > 0;
        }
        public void Process_WithItemWithoutBaseLayoutField_DoesNotCallGetItems()
        {
            // Arrange
            var args = new GetBaseLayoutItemsArgs(MasterFakesFactory.CreateFakeItem(null, null, null, null, null, false));
            var processor = Substitute.ForPartsOf<GetLookupSourceItems>();
            processor.When(p => p.GetItems(Arg.Any<Item>(), Arg.Any<string>())).DoNotCallBase();

            // Act
            processor.Process(args);

            // Assert
            processor.DidNotReceive().GetItems(Arg.Any<Item>(), Arg.Any<string>());
        }
Пример #3
0
        /// <summary>
        ///     Get base layout items from the soure of the base layout field
        /// </summary>
        /// <param name="args">The getBaseLayoutItems pipeline args</param>
        public void Process(GetBaseLayoutItemsArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.IsNotNull(args.Item, "Item cannot be null.");

            if (!args.Item.IsBaseLayoutItem())
            {
                return;
            }

            var field = args.Item.Fields[BaseLayoutItem.BaseLayoutFieldId];

            args.BaseLayoutItems.AddRange(GetItems(args.Item, field.Source));
        }
        /// <summary>
        ///     Gets the select base layout dialog URL with parameters for the given item
        /// </summary>
        /// <param name="item">the item</param>
        /// <returns>the dialog url</returns>
        public string GetDialogUrl(Item item)
        {
            var args = new GetBaseLayoutItemsArgs(item);
            _pipelineRunner.Run(args);

            if (args.BaseLayoutItems.Count == 0) return null;

            BaseLayoutItem baseLayoutItem = item;
            var options = new SelectBaseLayoutOptions {Items = args.BaseLayoutItems};
            if (baseLayoutItem.BaseLayout != null)
            {
                options.CurrentBaseLayoutId = baseLayoutItem.BaseLayout.ID;
            }

            return GetUrl(options, item.Database);
        }
        public void Process_WhenGetItemsReturnsItems_AddsItemsToArgs()
        {
            // Arrange
            var item1 = MasterFakesFactory.CreateFakeItem();
            var item2 = MasterFakesFactory.CreateFakeItem();
            var args = new GetBaseLayoutItemsArgs(MasterFakesFactory.CreateFakeItem());
            var processor = Substitute.ForPartsOf<GetLookupSourceItems>();
            processor.When(p => p.GetItems(Arg.Any<Item>(), Arg.Any<string>())).DoNotCallBase();
            processor.GetItems(Arg.Any<Item>(), Arg.Any<string>()).Returns(new[] {item1, item2});

            // Act
            processor.Process(args);

            // Assert
            Assert.Equal(2, args.BaseLayoutItems.Count);
        }