public void EditLinkBuilder_ProjectIdBadFormat_ThrowsException()
        {
            var badFormatProjectIdOptions = new ContentManagementHelpersOptions
            {
                ProjectId = "aa-bb-cc"
            };

            Assert.Throws <ArgumentException>(() => new EditLinkBuilder(badFormatProjectIdOptions));
        }
        public void EditLinkBuilder_MissingProjectId_ThrowsException()
        {
            var noProjectIdOptions = new ContentManagementHelpersOptions
            {
                ProjectId = string.Empty
            };

            Assert.Throws <ArgumentException>(() => new EditLinkBuilder(noProjectIdOptions));
        }
        public void EditLinkBuilder_MissingEditAppEndpoint_ThrowsException()
        {
            var noEditAppEndpointOptions = new ContentManagementHelpersOptions
            {
                AdminUrl = string.Empty
            };

            Assert.Throws <ArgumentException>(() => new EditLinkBuilder(noEditAppEndpointOptions));
        }
Example #4
0
        private EditLinkHelper()
        {
            var projectId          = AppSettingProvider.ProjectId.ToString() ?? AppSettingProvider.DefaultProjectId.ToString();
            var linkBuilderOptions = new ContentManagementHelpersOptions()
            {
                ProjectId = projectId
            };

            Builder = new EditLinkBuilder(linkBuilderOptions);
        }
        public void BuildEditItemUrl_AdminUrlOtherThanDefault_ReturnsCorrectUrl()
        {
            var options = new ContentManagementHelpersOptions
            {
                AdminUrl  = "https://someOther.url/{0}",
                ProjectId = "34998683-4dd6-441c-b4cb-57493cafcaf0",
            };

            var underTest = new EditLinkBuilder(options);
            var result    = underTest.BuildEditItemUrl(_language, _itemId);

            var expected = "https://someOther.url/goto/edit-item/project/34998683-4dd6-441c-b4cb-57493cafcaf0/variant-codename/some-Language-Codename/item/1cdaa8ef-cb2b-4f82-82e9-45467b2e01b9";

            Assert.Equal(expected, result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EditLinkBuilder"/> class for retrieving edit urls.
        /// </summary>
        /// <param name="contentManagementHelpersOptions">The settings of the Kentico Cloud project.</param>
        public EditLinkBuilder(ContentManagementHelpersOptions contentManagementHelpersOptions)
        {
            if (string.IsNullOrEmpty(contentManagementHelpersOptions.AdminUrl))
            {
                throw new ArgumentException("Kentico Cloud Edit App endpoint is not specified.", nameof(contentManagementHelpersOptions.AdminUrl));
            }

            if (string.IsNullOrEmpty(contentManagementHelpersOptions.ProjectId))
            {
                throw new ArgumentException("Kentico Cloud project identifier is not specified.", nameof(contentManagementHelpersOptions.ProjectId));
            }

            if (!Guid.TryParse(contentManagementHelpersOptions.ProjectId, out Guid projectIdGuid))
            {
                throw new ArgumentException($"Provided string is not a valid project identifier ({contentManagementHelpersOptions.ProjectId}).", nameof(contentManagementHelpersOptions.ProjectId));
            }

            _options = contentManagementHelpersOptions;
        }