public async Task CanAddViolationAction(AccessRuleViolationAction action) { var uniqueData = UNIQUE_PREFIX + nameof(CanAddViolationAction) + action.ToString().Substring(0, 2); using var app = _appFactory.Create(); var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions(); var dbContext = app.Services.GetRequiredService <CofoundryDbContext>(); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var command = new UpdatePageDirectoryAccessRuleSetCommand() { PageDirectoryId = directoryId, ViolationAction = action }; command.AccessRules.AddNew(app.SeededEntities.TestUserArea2.UserAreaCode, app.SeededEntities.TestUserArea2.RoleA.RoleId); await contentRepository .PageDirectories() .AccessRules() .UpdateAsync(command); var directory = await dbContext .PageDirectories .AsNoTracking() .FilterById(directoryId) .SingleOrDefaultAsync(); using (new AssertionScope()) { directory.Should().NotBeNull(); directory.AccessRuleViolationActionId.Should().Be((int)action); } }
public async Task WhenPageAccessRuleForUserAreaAndUserInvalid_ReturnsCorrectAction(AccessRuleViolationAction routeAccessRuleViolationAction) { var uniqueData = UNIQUE_PREFIX + "PAR4UserAreaAndUserInv" + routeAccessRuleViolationAction.ToString().Substring(0, 2); var sluggedUniqueData = SlugFormatter.ToSlug(uniqueData); using var app = _webApplicationFactory.CreateApp(); var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData); var pageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId, c => c.Publish = true); await app.TestData.Pages().AddAccessRuleAsync(pageId, app.SeededEntities.TestUserArea1.UserAreaCode, null, c => c.ViolationAction = routeAccessRuleViolationAction); using var client = _webApplicationFactory.CreateClientWithServices(s => s.TurnOnDeveloperExceptionPage()); await client.ImpersonateUserAsync(app.SeededEntities.TestUserArea2.RoleA.User); var result = await client.GetAsync($"/{sluggedUniqueData}/{sluggedUniqueData}"); await AssertAccessRuleResponseAsync(result, routeAccessRuleViolationAction); }