Exemplo n.º 1
0
 public IdCustomEntityRoutingRuleTests()
 {
     _rule      = new IdCustomEntityRoutingRule();
     _pageRoute = new PageRoute()
     {
         FullUrlPath = PATH + _rule.RouteFormat,
         CustomEntityDefinitionCode = "TSTCDE",
         Locale = new ActiveLocale()
         {
             LocaleId = 8
         }
     };
 }
        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);
            }
        }