Exemplo n.º 1
0
        public void ShouldCreateWebPartCategory()
        {
            IWebPartCategory passedCategory = null;

            var name        = "Category";
            var path        = "/Category";
            var displayName = "Display Name";
            var imagePath   = "/image/path";

            var webPartCategoryMock1 = new Mock <IWebPartCategory>();

            webPartCategoryMock1
            .Setup(x => x.CategoryPath)
            .Returns(path);
            webPartCategoryMock1
            .Setup(x => x.CategoryDisplayName)
            .Returns(displayName);
            webPartCategoryMock1
            .Setup(x => x.CategoryImagePath)
            .Returns(imagePath);
            var webPartCategoryMock2 = new Mock <IWebPartCategory>();

            webPartCategoryMock2
            .Setup(x => x.CategoryID)
            .Returns(20);
            webPartCategoryMock2
            .Setup(x => x.CategoryPath)
            .Returns("/");

            var webPartServiceMock = new Mock <IWebPartService>();

            webPartServiceMock
            .Setup(x => x.WebPartCategories)
            .Returns(new IWebPartCategory[] { webPartCategoryMock1.Object, webPartCategoryMock2.Object });
            webPartServiceMock
            .Setup(x => x.Create(It.IsAny <IWebPartCategory>()))
            .Callback <IWebPartCategory>(x => passedCategory = x)
            .Returns(webPartCategoryMock1.Object);

            var businessLayer = new NewCMSWebPartCategoryBusiness
            {
                WebPartService = webPartServiceMock.Object,
                WriteDebug     = Assert.NotNull,
                WriteVerbose   = Assert.NotNull,
            };

            var results = businessLayer.CreateWebPartCategory(path, displayName, imagePath);

            results
            .Should()
            .NotBeNull();
            results
            .Should().BeEquivalentTo(webPartCategoryMock1.Object);

            passedCategory.CategoryName.Should().Be(name);
            passedCategory.CategoryPath.Should().Be(path);
            passedCategory.CategoryDisplayName.Should().Be(displayName);
            passedCategory.CategoryImagePath.Should().Be(imagePath);
            passedCategory.CategoryParentID.Should().Be(20);
        }
        /// <inheritdoc />
        protected override void ProcessRecord()
        {
            IEnumerable <IWebPartCategory> categories = null;

            switch (this.ParameterSetName)
            {
            case CATEGORYNAME:
                categories = this.BusinessLayer.GetWebPartCategories(this.CategoryName, this.RegularExpression.ToBool(), this.Recurse.ToBool());
                break;

            case IDSETNAME:
                categories = this.BusinessLayer.GetWebPartCategories(this.ID, this.Recurse.ToBool());
                break;

            case PATH:
                categories = this.BusinessLayer.GetWebPartCategories(this.CategoryPath, this.Recurse.ToBool());
                break;

            case WEBPART:
                categories = new IWebPartCategory[]
                {
                    this.BusinessLayer.GetWebPartCategory(this.WebPart.ActLike <IWebPart>()),
                };
                break;

            case NONE:
                categories = this.BusinessLayer.GetWebPartCategories();
                break;
            }

            foreach (var category in categories)
            {
                this.ActOnObject(category);
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override void ActOnObject(IWebPartCategory webPartCategory)
        {
            if (webPartCategory == null)
            {
                return;
            }

            this.RemoveBusinessLayer.RemoveWebPartCategory(webPartCategory, this.Recurse.ToBool());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a list of the <see cref="IWebPartCategory"/> which are children of the <paramref name="parentWebPartCategory"/>.
        /// </summary>
        /// <param name="parentWebPartCategory">The <see cref="IWebPartCategory"/> which is parent to the categories to find.</param>
        /// <param name="recurse">Indicates whether webpart categories should be returned recursively.</param>
        /// <returns>A list of the <see cref="IWebPartCategory"/> which are children to the supplied <paramref name="parentWebPartCategory"/>.</returns>
        public IEnumerable <IWebPartCategory> GetWebPartCategories(IWebPartCategory parentWebPartCategory, bool recurse)
        {
            var categories = this.WebPartService.GetWebPartCategories(parentWebPartCategory);

            if (recurse)
            {
                return(this.GetRecurseWebPartCategories(categories));
            }
            else
            {
                return(categories);
            }
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public IWebPartCategory Create(IWebPartCategory webPartCategory)
        {
            var category = new WebPartCategoryInfo
            {
                CategoryDisplayName = webPartCategory.CategoryDisplayName,
                CategoryName        = webPartCategory.CategoryName,
                CategoryImagePath   = webPartCategory.CategoryImagePath,
                CategoryParentID    = webPartCategory.CategoryParentID,
            };

            WebPartCategoryInfoProvider.SetWebPartCategoryInfo(category);

            return(category.ActLike <IWebPartCategory>());
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public void Update(IWebPartCategory webPartCategory)
        {
            var category = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(webPartCategory.CategoryID);

            if (category == null)
            {
                return;
            }

            category.CategoryDisplayName = webPartCategory.CategoryDisplayName;
            category.CategoryName        = webPartCategory.CategoryName;
            category.CategoryImagePath   = webPartCategory.CategoryImagePath;
            category.CategoryParentID    = webPartCategory.CategoryParentID;

            WebPartCategoryInfoProvider.SetWebPartCategoryInfo(category);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deletes the specified <see cref="IWebPartCategory"/>.  Throws exceptions if there are children.
        /// </summary>
        /// <param name="webPartCategory">The webpart category to delete.</param>
        /// <param name="recurse">Indicates whether webpart categories and web parts should be removed recursively.</param>
        public void RemoveWebPartCategory(IWebPartCategory webPartCategory, bool recurse)
        {
            var webParts = this.WebPartService.GetWebParts(webPartCategory);

            if (webParts.Any())
            {
                if (recurse)
                {
                    foreach (var webpart in webParts)
                    {
                        if (this.ShouldProcess(webpart.WebPartDisplayName, "Remove the web part from Kentico."))
                        {
                            this.WebPartService.Delete(webpart);
                        }
                    }
                }
                else
                {
                    throw new Exception($"Web Part Category {webPartCategory.CategoryDisplayName} has Web Parts associated.  Failed to delete.");
                }
            }

            var webPartCategories = this.WebPartService.GetWebPartCategories(webPartCategory);

            if (webPartCategories.Any())
            {
                if (recurse)
                {
                    foreach (var category in webPartCategories)
                    {
                        this.RemoveWebPartCategory(category, recurse);
                    }
                }
                else
                {
                    throw new Exception($"Web Part Category {webPartCategory.CategoryDisplayName} has Web Parts Categories associated.  Failed to delete.");
                }
            }

            if (this.ShouldProcess(webPartCategory.CategoryDisplayName, "Remove the web part category from Kentico."))
            {
                this.WebPartService.Delete(webPartCategory);
            }
        }
 /// <summary>
 /// When overridden in a child class, operates on the specified web part category.
 /// </summary>
 /// <param name="webPartCategory">The web part category to operate on.</param>
 protected virtual void ActOnObject(IWebPartCategory webPartCategory)
 {
     this.WriteObject(webPartCategory?.UndoActLike());
 }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a <see cref="IWebPart"/> with the specified name under the specified <see cref="IWebPartCategory"/>.
        /// </summary>
        /// <param name="name">The name for the <see cref="IWebPart"/>.</param>
        /// <param name="fileName">The file name for the underlying class file.</param>
        /// <param name="displayName">The display name for the <see cref="IWebPart"/>.</param>
        /// <param name="webPartCategory">The <see cref="IWebPartCategory"/> to create the <see cref="IWebPart"/> under.</param>
        /// <returns>The newly created <see cref="IWebPart"/>.</returns>
        public virtual IWebPart CreateWebPart(string name, string fileName, string displayName, IWebPartCategory webPartCategory)
        {
            if (string.IsNullOrEmpty(displayName))
            {
                displayName = name;
            }

            var data = new WebPart
            {
                WebPartDisplayName = displayName,
                WebPartFileName    = fileName,
                WebPartName        = name,

                WebPartCategoryID = webPartCategory.CategoryID,
            };

            return(this.WebPartService.Create(data));
        }
Exemplo n.º 10
0
 /// <summary>
 /// Gets a list of <see cref="IWebPart"/> that are within the <paramref name="webPartCategory"/>.
 /// </summary>
 /// <param name="webPartCategory">The <see cref="IWebPartCategory"/> that contains the desired <see cref="IWebPart"/>.</param>
 /// <returns>A list of <see cref="IWebPart"/> that are within the <paramref name="webPartCategory"/>.</returns>
 public IEnumerable <IWebPart> GetWebPartsByCategory(IWebPartCategory webPartCategory) => this.WebPartService.GetWebParts(webPartCategory);
Exemplo n.º 11
0
 /// <inheritdoc />
 public IEnumerable <IWebPart> GetWebParts(IWebPartCategory webPartCategory) =>
 (from wp in this.WebParts
      where wp.WebPartCategoryID == webPartCategory.CategoryID
  select wp).ToArray();
Exemplo n.º 12
0
 /// <inheritdoc />
 public IEnumerable <IWebPartCategory> GetWebPartCategories(IWebPartCategory parentWebPartCategory) =>
 (from c in this.WebPartCategories
      where c.CategoryParentID == parentWebPartCategory.CategoryID
  select c).ToArray();
Exemplo n.º 13
0
 /// <inheritdoc />
 public void Delete(IWebPartCategory webPartCategory) =>
 WebPartCategoryInfoProvider.DeleteCategoryInfo(webPartCategory.CategoryID);
Exemplo n.º 14
0
 /// <summary>
 /// Sets the <see cref="IWebPartCategory"/> within Kentico.
 /// </summary>
 /// <param name="webPartCategory">The <see cref="IWebPartCategory"/> to set.</param>
 public void Set(IWebPartCategory webPartCategory)
 {
     this.WebPartService.Update(webPartCategory);
 }