public async Task WhenUrlNotUnique_Throws()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(WhenUrlNotUnique_Throws);

            using var app = _appFactory.Create();
            var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData);

            var page1Id = await app.TestData.Pages().AddAsync(uniqueData, directoryId);

            var page2Id = await app.TestData.Pages().AddAsync(uniqueData + "2", directoryId);

            var command = new UpdatePageUrlCommand()
            {
                PageId          = page2Id,
                PageDirectoryId = directoryId,
                UrlPath         = SlugFormatter.ToSlug(uniqueData)
            };

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            await contentRepository
            .Awaiting(r => r.Pages().UpdateUrlAsync(command))
            .Should()
            .ThrowAsync <UniqueConstraintViolationException>()
            .WithMemberNames(nameof(command.UrlPath));
        }
        public async Task WhenRoutingRuleUniquenessRequirementNotSupported_Throws()
        {
            var uniqueData = UNIQUE_PREFIX + "RuleUniquenessReqNotSupported";

            using var app = _appFactory.Create();
            var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData);

            var addPage1Command = app.TestData.Pages().CreateAddCommandWithCustomEntityDetailsPage(uniqueData, directoryId);
            var addPage2Command = app.TestData.Pages().CreateAddCommandWithCustomEntityDetailsPage(uniqueData, directoryId);

            addPage2Command.CustomEntityRoutingRule = new IdCustomEntityRoutingRule().RouteFormat;

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var page1Id           = await contentRepository
                                    .Pages()
                                    .AddAsync(addPage1Command);

            var page2Id = await contentRepository
                          .Pages()
                          .AddAsync(addPage2Command);

            var command = new UpdatePageUrlCommand()
            {
                PageId                  = page1Id,
                PageDirectoryId         = directoryId,
                CustomEntityRoutingRule = new IdCustomEntityRoutingRule().RouteFormat
            };

            await contentRepository
            .Awaiting(r => r.Pages().UpdateUrlAsync(command))
            .Should()
            .ThrowAsync <ValidationException>()
            .WithMemberNames(nameof(command.CustomEntityRoutingRule));
        }
        public async Task WhenRoutingRuleNotExists_Throws()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(WhenRoutingRuleNotExists_Throws);

            using var app = _appFactory.Create();
            var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData);

            var addPageCommand = app.TestData.Pages().CreateAddCommandWithCustomEntityDetailsPage(uniqueData, directoryId);

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var pageId            = await contentRepository
                                    .Pages()
                                    .AddAsync(addPageCommand);

            var command = new UpdatePageUrlCommand()
            {
                PageId                  = pageId,
                PageDirectoryId         = directoryId,
                CustomEntityRoutingRule = "{not-a-routing-rule}"
            };

            await contentRepository
            .Awaiting(r => r.Pages().UpdateUrlAsync(command))
            .Should()
            .ThrowAsync <ValidationException>()
            .WithMemberNames(nameof(command.CustomEntityRoutingRule));
        }
        public async Task CanChangeCustomEntityPageUrl()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CanChangeCustomEntityPageUrl);

            using var app = _appFactory.Create();
            var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData);

            var addPageCommand = app.TestData.Pages().CreateAddCommandWithCustomEntityDetailsPage(uniqueData, directoryId);

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var pageId            = await contentRepository
                                    .Pages()
                                    .AddAsync(addPageCommand);

            var routingRuleFormat = new IdCustomEntityRoutingRule().RouteFormat;
            var command           = new UpdatePageUrlCommand()
            {
                PageId                  = pageId,
                PageDirectoryId         = directoryId,
                CustomEntityRoutingRule = routingRuleFormat
            };

            await contentRepository
            .Pages()
            .UpdateUrlAsync(command);

            var dbContext = app.Services.GetRequiredService <CofoundryDbContext>();

            var page = await dbContext
                       .Pages
                       .AsNoTracking()
                       .FilterActive()
                       .FilterById(pageId)
                       .SingleOrDefaultAsync();

            using (new AssertionScope())
            {
                page.Should().NotBeNull();
                page.LocaleId.Should().Be(command.LocaleId);
                page.PageDirectoryId.Should().Be(command.PageDirectoryId);
                page.UrlPath.Should().Be(command.CustomEntityRoutingRule);
            }
        }
        public async Task CanChangeDirectory()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CanChangeDirectory);

            using var app = _appFactory.Create();
            var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData);

            var newDirectoryId = await app.TestData.PageDirectories().AddAsync(uniqueData + " Copy");

            var pageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId);

            var command = new UpdatePageUrlCommand()
            {
                PageId          = pageId,
                PageDirectoryId = newDirectoryId,
                UrlPath         = "moved-to-new-directory"
            };

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            await contentRepository
            .Pages()
            .UpdateUrlAsync(command);

            var dbContext = app.Services.GetRequiredService <CofoundryDbContext>();

            var page = await dbContext
                       .Pages
                       .AsNoTracking()
                       .FilterActive()
                       .FilterById(pageId)
                       .SingleOrDefaultAsync();

            using (new AssertionScope())
            {
                page.Should().NotBeNull();
                page.LocaleId.Should().Be(command.LocaleId);
                page.PageDirectoryId.Should().Be(command.PageDirectoryId);
                page.UrlPath.Should().Be(command.UrlPath);
            }
        }
 public Task UpdateUrlAsync(UpdatePageUrlCommand command)
 {
     return(ExtendableContentRepository.ExecuteCommandAsync(command));
 }
Beispiel #7
0
 public async Task <IActionResult> PutPageUrl(int pageId, [FromBody] UpdatePageUrlCommand command)
 {
     return(await _apiResponseHelper.RunCommandAsync(this, command));
 }
Beispiel #8
0
 public Task <JsonResult> PutPageUrl(int pageId, [FromBody] UpdatePageUrlCommand command)
 {
     return(_apiResponseHelper.RunCommandAsync(command));
 }