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

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();

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

            await app.TestData.UnstructuredData().AddAsync <PageDirectoryEntityDefinition>(directoryId, RelatedEntityCascadeAction.None);

            var dependencies = await contentRepository.ExecuteQueryAsync(new GetEntityDependencySummaryByRelatedEntityIdQuery(PageDirectoryEntityDefinition.DefinitionCode, directoryId));

            using (new AssertionScope())
            {
                // Generally entity mapping is down to the query referenced in IDependableEntityDefinition.CreateGetEntityMicroSummariesByIdRangeQuery
                // but we'll check the basic mapping for one test here
                dependencies.Should().NotBeNull();
                dependencies.Should().HaveCount(1);
                var dependency = dependencies.First();
                dependency.CanDelete.Should().BeFalse();
                dependency.Entity.Should().NotBeNull();
                dependency.Entity.RootEntityId.Should().Be(app.SeededEntities.CustomEntityForUnstructuredDataTests.CustomEntityId);
                dependency.Entity.RootEntityTitle.Should().Be(app.SeededEntities.CustomEntityForUnstructuredDataTests.Title);
                dependency.Entity.EntityDefinitionCode.Should().Be(app.SeededEntities.CustomEntityForUnstructuredDataTests.CustomEntityDefinitionCode);
                dependency.Entity.EntityDefinitionName.Should().Be(new TestCustomEntityDefinition().Name);
                dependency.Entity.IsPreviousVersion.Should().BeFalse();
            }
        }
        public async Task CompletesReset()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CompletesReset);

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();
            var authorizedTask    = await AddUserAndInitiate(uniqueData, app);

            var token = MakeToken(authorizedTask);

            await contentRepository
            .Users()
            .AccountVerification()
            .EmailFlow()
            .CompleteAsync(new CompleteUserAccountVerificationViaEmailCommand()
            {
                Token        = token,
                UserAreaCode = authorizedTask.User.UserAreaCode
            });

            var completedTask = await GetAuthorizedTask(app, authorizedTask.UserId);

            using (new AssertionScope())
            {
                completedTask.Should().NotBeNull();
                completedTask.CompletedDate.Should().NotBeNull();
                completedTask.User.AccountVerifiedDate.Should().NotBeNull();
            }
        }
Exemple #3
0
        public async Task Valid_ReturnsValid()
        {
            var uniqueData = UNIQUE_PREFIX + "Valid";

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();

            var seedDate = new DateTime(2022, 01, 20);
            var request  = await AddUserAndInitiateRequest(uniqueData, app);

            var token = MakeResetToken(request);

            app.Mocks.MockDateTime(seedDate.AddHours(10));
            var result = await contentRepository
                         .Users()
                         .AccountRecovery()
                         .Validate(new ValidateUserAccountRecoveryByEmailQuery()
            {
                UserAreaCode = request.User.UserAreaCode,
                Token        = token,
            })
                         .ExecuteAsync();

            using (new AssertionScope())
            {
                result.Should().NotBeNull();
                result.IsSuccess.Should().BeTrue();
                result.Error.Should().BeNull();
            }
        }
        public async Task RootNodeIsRootDirectory()
        {
            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();

            var treeRoot = await contentRepository
                           .PageDirectories()
                           .GetAll()
                           .AsTree()
                           .ExecuteAsync();

            using (new AssertionScope())
            {
                treeRoot.Should().NotBeNull();
                treeRoot.AuditData.Should().NotBeNull();
                treeRoot.AuditData.Creator.Should().NotBeNull();
                treeRoot.AuditData.CreateDate.Should().NotBeDefault();
                treeRoot.ChildPageDirectories.Should().NotBeNull();
                treeRoot.Depth.Should().Be(0);
                treeRoot.UrlPath.Should().BeEmpty();
                treeRoot.FullUrlPath.Should().Be("/");
                treeRoot.ParentPageDirectoryId.Should().BeNull();
                treeRoot.ParentPageDirectory.Should().BeNull();
            }
        }
        public async Task CanComplete()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CanComplete);

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            var addAuthorizedTaskCommand = await app
                                           .TestData
                                           .AuthorizedTasks()
                                           .AddWithNewUserAsync(uniqueData, null);

            await contentRepository
            .AuthorizedTasks()
            .CompleteAsync(new CompleteAuthorizedTaskCommand(addAuthorizedTaskCommand.OutputAuthorizedTaskId));

            var authorizedTask = await dbContext
                                 .AuthorizedTasks
                                 .AsNoTracking()
                                 .Where(t => t.AuthorizedTaskId == addAuthorizedTaskCommand.OutputAuthorizedTaskId)
                                 .SingleAsync();

            using (new AssertionScope())
            {
                authorizedTask.Should().NotBeNull();
                authorizedTask.CompletedDate.Should().NotBeNull();
            }
        }
Exemple #6
0
        public async Task WhenEnabled_Runs()
        {
            CleanupUsersCommand executedCommand = null;

            using var app = _appFactory.Create(s =>
            {
                s.Configure <UsersSettings>(c =>
                {
                    c.Cleanup.DefaultRetentionPeriodInDays               = 11;
                    c.Cleanup.AuthenticationLogRetentionPeriodInDays     = 12;
                    c.Cleanup.AuthenticationFailLogRetentionPeriodInDays = 13;
                });
                s.MockHandler <CleanupUsersCommand>(c => executedCommand = c);
            });

            var backgroundTask = app.Services.GetRequiredService <UserCleanupBackgroundTask>();
            await backgroundTask.ExecuteAsync();

            using (new AssertionScope())
            {
                executedCommand.Should().NotBeNull();
                executedCommand.DefaultRetentionPeriod.Should().Be(TimeSpan.FromDays(11));
                executedCommand.AuthenticationLogRetentionPeriod.Should().Be(TimeSpan.FromDays(12));
                executedCommand.AuthenticationFailLogRetentionPeriod.Should().Be(TimeSpan.FromDays(13));
            }
        }
        public async Task ResetsPassword()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(ResetsPassword);

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();
            var userId            = await app.TestData.Users().AddAsync(uniqueData);

            var originalUserState = await dbContext
                                    .Users
                                    .AsNoTracking()
                                    .FilterById(userId)
                                    .SingleAsync();

            await contentRepository
            .Users()
            .ResetPasswordAsync(userId);

            var user = await dbContext
                       .Users
                       .AsNoTracking()
                       .FilterById(userId)
                       .SingleOrDefaultAsync();

            using (new AssertionScope())
            {
                user.Should().NotBeNull();
                originalUserState.Password.Should().NotBeNull();
                user.Password.Should().NotBe(originalUserState.Password);
                user.LastPasswordChangeDate.Should().BeAfter(originalUserState.LastPasswordChangeDate);
                user.SecurityStamp.Should().NotBeNull().And.NotBe(originalUserState.SecurityStamp);
            }
        }
Exemple #8
0
        public async Task CompletesReset()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CompletesReset);

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();
            var resetRequest      = await AddUserAndInitiateRequest(uniqueData, app);

            var token = MakeResetToken(resetRequest);

            await contentRepository
            .Users()
            .AccountRecovery()
            .CompleteAsync(new CompleteUserAccountRecoveryViaEmailCommand()
            {
                NewPassword  = "******",
                Token        = token,
                UserAreaCode = resetRequest.User.UserAreaCode,
            });

            var completedResetRequest = await GetResetRequest(app, resetRequest.UserId);

            using (new AssertionScope())
            {
                completedResetRequest.Should().NotBeNull();
                completedResetRequest.CompletedDate.Should().NotBeNull();
                completedResetRequest.User.RequirePasswordChange.Should().BeFalse();
                completedResetRequest.User.Password.Should().NotBe(resetRequest.User.Password);
                completedResetRequest.User.LastPasswordChangeDate.Should().NotBe(resetRequest.User.LastPasswordChangeDate);
                completedResetRequest.User.SecurityStamp.Should().NotBeNull().And.NotBe(resetRequest.User.SecurityStamp);
            }
        }
        public async Task ReturnsRequestedPage()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(ReturnsRequestedPage);

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

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

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var accessDetails     = await contentRepository
                                    .Pages()
                                    .AccessRules()
                                    .GetByPageId(pageId)
                                    .AsDetails()
                                    .ExecuteAsync();

            using (new AssertionScope())
            {
                accessDetails.Should().NotBeNull();
                accessDetails.PageId.Should().Be(pageId);
                accessDetails.AccessRules.Should().NotBeNull().And.BeEmpty();
                accessDetails.InheritedAccessRules.Should().NotBeNull().And.BeEmpty();
                accessDetails.UserAreaForSignInRedirect.Should().BeNull();
                accessDetails.ViolationAction.Should().Be(AccessRuleViolationAction.Error);
            }
        }
Exemple #10
0
        public async Task WhenValid_ChangesPassword()
        {
            var uniqueData  = UNIQUE_PREFIX + "Valid_ChangesPW";
            var newPassword = uniqueData + "New";

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            var addUserCommand = app.TestData.Users().CreateAddCommand(uniqueData);
            await contentRepository.Users().AddAsync(addUserCommand);

            var command = new UpdateUserPasswordByCredentialsCommand()
            {
                Username     = addUserCommand.Email,
                NewPassword  = newPassword,
                OldPassword  = addUserCommand.Password,
                UserAreaCode = addUserCommand.UserAreaCode
            };
            await contentRepository.Users().UpdatePasswordByCredentialsAsync(command);

            // Use the auth query to verify the password has been changed
            var authResult = await contentRepository.ExecuteQueryAsync(new AuthenticateUserCredentialsQuery()
            {
                UserAreaCode = command.UserAreaCode,
                Username     = command.Username,
                Password     = newPassword
            });

            using (new AssertionScope())
            {
                authResult.Should().NotBeNull();
                authResult.IsSuccess.Should().BeTrue();
            }
        }
        public async Task WhenSignedInDefaultUserArea_CanSignOut()
        {
            var uniqueData = UNIQUE_PREFIX + "SIDef_SO";

            using var app = _appFactory.Create();
            var contentRepository  = app.Services.GetContentRepository();
            var dbContext          = app.Services.GetRequiredService <CofoundryDbContext>();
            var userSessionService = app.Services.GetRequiredService <IUserSessionService>();

            var userId = await app.TestData.Users().AddAsync(uniqueData);

            await userSessionService.SignInAsync(TestUserArea1.Code, userId, true);

            var userIdBeforeSignOut = userSessionService.GetCurrentUserId();

            await contentRepository
            .Users()
            .Authentication()
            .SignOutAsync();

            var userIdAfterSignOut = userSessionService.GetCurrentUserId();

            using (new AssertionScope())
            {
                userIdBeforeSignOut.Should().Be(userId);
                userIdAfterSignOut.Should().BeNull();
            }
        }
        public async Task CanSetVerified()
        {
            var uniqueData = UNIQUE_PREFIX + "CSetVer";

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            var userId = await app.TestData.Users().AddAsync(uniqueData);

            await contentRepository
            .Users()
            .AccountVerification()
            .UpdateStatusAsync(new UpdateUserAccountVerificationStatusCommand()
            {
                IsAccountVerified = true,
                UserId            = userId
            });

            var user = await dbContext
                       .Users
                       .AsNoTracking()
                       .FilterById(userId)
                       .SingleAsync();

            using (new AssertionScope())
            {
                user.AccountVerifiedDate.Should().NotBeNull().And.NotBeDefault();

                app.Mocks
                .CountMessagesPublished <UserAccountVerificationStatusUpdatedMessage>(m => m.UserId == userId && m.UserAreaCode == user.UserAreaCode && m.IsVerified)
                .Should().Be(1);
            }
        }
Exemple #13
0
        public async Task ReturnsMappedData()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(ReturnsMappedData);

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

            var addDirectoryCommand = app.TestData.PageDirectories().CreateAddCommand(uniqueData, parentDirectoryId);

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();

            await contentRepository
            .PageDirectories()
            .AddAsync(addDirectoryCommand);

            var query   = new GetPatchableCommandByIdQuery <UpdatePageDirectoryCommand>(addDirectoryCommand.OutputPageDirectoryId);
            var command = await contentRepository.ExecuteQueryAsync(query);

            using (new AssertionScope())
            {
                command.Should().NotBeNull();
                command.Name.Should().Be(addDirectoryCommand.Name);
                command.PageDirectoryId.Should().Be(addDirectoryCommand.OutputPageDirectoryId);
            }
        }
Exemple #14
0
        public async Task MapsBasicData()
        {
            var uniqueData        = UNIQUE_PREFIX + nameof(MapsBasicData);
            var sluggedUniqueData = SlugFormatter.ToSlug(uniqueData);

            using var app = _appFactory.Create();
            var rootDirectoryId = await app.TestData.PageDirectories().GetRootDirectoryIdAsync();

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

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

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

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var page2             = await contentRepository
                                    .Pages()
                                    .GetById(page2Id)
                                    .AsRoute()
                                    .ExecuteAsync();

            using (new AssertionScope())
            {
                page2.Should().NotBeNull();
                page2.PageId.Should().Be(page2Id);

                page2.FullUrlPath.Should().Be($"/{sluggedUniqueData}/{sluggedUniqueData}2");
                page2.HasDraftVersion.Should().BeTrue();
                page2.HasPublishedVersion.Should().BeFalse();
                page2.Locale.Should().BeNull();
                page2.PageId.Should().Be(page2Id);
                page2.PageType.Should().Be(PageType.Generic);
                page2.PublishStatus.Should().Be(PublishStatus.Unpublished);
                page2.PublishDate.Should().BeNull();
                page2.LastPublishDate.Should().BeNull();
                page2.Title.Should().Be(uniqueData + "2");
                page2.UrlPath.Should().Be(sluggedUniqueData + "2");
                page2.Versions.Should().HaveCount(1);

                page2.PageDirectory.Should().NotBeNull();
                page2.PageDirectory.PageDirectoryId.Should().Be(directoryId);
                page2.PageDirectory.FullUrlPath.Should().Be($"/{sluggedUniqueData}");
                page2.PageDirectory.LocaleVariations.Should().BeEmpty();
                page2.PageDirectory.Name.Should().Be(uniqueData);
                page2.PageDirectory.ParentPageDirectoryId.Should().Be(rootDirectoryId);
                page2.PageDirectory.UrlPath.Should().Be(sluggedUniqueData);

                var version = page2.Versions.FirstOrDefault();
                version.CreateDate.Should().NotBeDefault();
                version.HasCustomEntityRegions.Should().BeFalse();
                version.HasPageRegions.Should().BeTrue();
                version.IsLatestPublishedVersion.Should().BeFalse();
                version.PageTemplateId.Should().Be(app.SeededEntities.TestPageTemplate.PageTemplateId);
                version.Title.Should().Be(uniqueData + "2");
                version.VersionId.Should().BePositive();
                version.WorkFlowStatus.Should().Be(WorkFlowStatus.Draft);
            }
        }
        public async Task WhenDraftOnlyQueriedWithPublishStatus_ReturnsVersionWithWorkflowStatus(PublishStatusQuery publishStatus, WorkFlowStatus?workFlowStatus)
        {
            var uniqueData = UNIQUE_PREFIX + "DraftOnlyQPubStatus_" + publishStatus;

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

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

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var page = await contentRepository
                       .Pages()
                       .GetById(pageId)
                       .AsRenderDetails(publishStatus)
                       .ExecuteAsync();

            if (!workFlowStatus.HasValue)
            {
                page.Should().BeNull();
            }
            else
            {
                using (new AssertionScope())
                {
                    page.Should().NotBeNull();
                    page.PageId.Should().Be(pageId);
                    page.WorkFlowStatus.Should().Be(workFlowStatus);
                }
            }
        }
Exemple #16
0
        public async Task WhenPageIsPublished_CopiesBasicData()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(WhenPageIsPublished_CopiesBasicData);

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

            var pageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId, c =>
            {
                c.MetaDescription      = uniqueData + " Meta";
                c.OpenGraphDescription = uniqueData + "OG Desc";
                c.OpenGraphImageId     = app.SeededEntities.TestImageId;
                c.OpenGraphTitle       = uniqueData + "OG Title";
                c.Publish = true;
            });

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var draftVersionId    = await contentRepository
                                    .Pages()
                                    .Versions()
                                    .AddDraftAsync(new AddPageDraftVersionCommand()
            {
                PageId = pageId
            });

            var dbContext = app.Services.GetRequiredService <CofoundryDbContext>();
            var versions  = await dbContext
                            .PageVersions
                            .AsNoTracking()
                            .Include(v => v.PageVersionBlocks)
                            .FilterByPageId(pageId)
                            .ToListAsync();

            var publishedVersion = versions.FirstOrDefault(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Published);
            var draftVersion     = versions.SingleOrDefault(v => v.PageVersionId == draftVersionId);

            using (new AssertionScope())
            {
                versions.Should().HaveCount(2);
                publishedVersion.Should().NotBeNull();
                draftVersion.Should().NotBeNull();
                draftVersion.CreateDate.Should().BeAfter(publishedVersion.CreateDate);
                draftVersion.DisplayVersion.Should().Be(2);
                draftVersion.ExcludeFromSitemap.Should().BeTrue();
                draftVersion.MetaDescription.Should().Be(publishedVersion.MetaDescription);
                draftVersion.OpenGraphDescription.Should().Be(publishedVersion.OpenGraphDescription);
                draftVersion.OpenGraphImageId.Should().Be(publishedVersion.OpenGraphImageId);
                draftVersion.OpenGraphTitle.Should().Be(publishedVersion.OpenGraphTitle);
                draftVersion.PageTemplateId.Should().Be(publishedVersion.PageTemplateId);
                draftVersion.PageVersionBlocks.Should().BeEmpty();
                draftVersion.Title.Should().Be(publishedVersion.Title);
                draftVersion.WorkFlowStatusId.Should().Be((int)WorkFlowStatus.Draft);
            }
        }
        public async Task WhenNotExists_ReturnsNull()
        {
            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();

            var area = await contentRepository
                       .UserAreas()
                       .GetByCode("ZZZ")
                       .AsMicroSummary()
                       .ExecuteAsync();

            area.Should().BeNull();
        }
        public async Task CanDelete()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CanDelete);

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            var userId = await app.TestData.Users().AddAsync(uniqueData, c => c.DisplayName = "Test");

            var originalUser = await GetUserAsync(dbContext, userId);

            await contentRepository
            .Users()
            .DeleteAsync(userId);

            var deletedUser = await GetUserAsync(dbContext, userId);

            using (new AssertionScope())
            {
                deletedUser.Should().NotBeNull();
                deletedUser.Email.Should().BeNull();
                deletedUser.UniqueEmail.Should().BeNull();
                deletedUser.FirstName.Should().BeNull();
                deletedUser.LastName.Should().BeNull();
                deletedUser.DisplayName.Should().BeNull();
                deletedUser.EmailDomainId.Should().BeNull();
                deletedUser.Password.Should().NotBeNull().And.NotBe(originalUser.Username);
                deletedUser.Username.Should().NotBeNull().And.NotBe(originalUser.Username);
                deletedUser.UniqueUsername.Should().NotBeNull().And.NotBe(originalUser.UniqueUsername);
                deletedUser.DeactivatedDate.Should().NotBeNull();
                deletedUser.DeletedDate.Should().NotBeNull();
            }
        }
Exemple #19
0
        public async Task CanQueryMultiple()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CanQueryMultiple);

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();

            var customEntity1Id = await app.TestData.CustomEntities().AddAsync(uniqueData + "1");

            var customEntity2Id = await app.TestData.CustomEntities().AddAsync(uniqueData + "2");

            await app.TestData.UnstructuredData().AddAsync(
                TestCustomEntityDefinition.Code, customEntity1Id,
                TestCustomEntityDefinition.Code, customEntity2Id,
                RelatedEntityCascadeAction.None
                );

            await app.TestData.UnstructuredData().AddAsync(
                TestCustomEntityDefinition.Code, customEntity2Id,
                TestCustomEntityDefinition.Code, customEntity1Id,
                RelatedEntityCascadeAction.Cascade
                );

            var dependencies = await contentRepository.ExecuteQueryAsync(new GetEntityDependencySummaryByRelatedEntityIdRangeQuery(TestCustomEntityDefinition.Code, new int[] { customEntity1Id, customEntity2Id }));

            using (new AssertionScope())
            {
                dependencies.Should().HaveCount(2);
                dependencies.Should().ContainSingle(e => e.Entity.RootEntityId == customEntity1Id && e.Entity.EntityDefinitionCode == TestCustomEntityDefinition.Code);
                dependencies.Should().ContainSingle(e => e.Entity.RootEntityId == customEntity2Id && e.Entity.EntityDefinitionCode == TestCustomEntityDefinition.Code);
            }
        }
Exemple #20
0
        public async Task ReturnsMappedData()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(ReturnsMappedData);

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

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

            addPageCommand.Tags = new string[] { UNIQUE_PREFIX + "1", app.SeededEntities.TestTag.TagText };

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

            var query   = new GetPatchableCommandByIdQuery <UpdatePageCommand>(addPageCommand.OutputPageId);
            var command = await contentRepository.ExecuteQueryAsync(query);

            using (new AssertionScope())
            {
                command.Should().NotBeNull();
                command.PageId.Should().Be(addPageCommand.OutputPageId);
                command.Tags.Should().OnlyContain(t => addPageCommand.Tags.Contains(t));
            }
        }
Exemple #21
0
        public async Task WhenMalformedPath_ReturnsNull(string path)
        {
            using var app = _appFactory.Create();

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var result            = await contentRepository
                                    .Pages()
                                    .GetByPath()
                                    .AsRoutingInfo(new GetPageRoutingInfoByPathQuery()
            {
                Path = path
            })
                                    .ExecuteAsync();

            result.Should().BeNull();
        }
        public async Task CanLog()
        {
            var uniqueData = UNIQUE_PREFIX + "CanLog";

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            app.Mocks.MockIPAddress(uniqueData);

            await contentRepository.ExecuteCommandAsync(new LogFailedAuthenticationAttemptCommand(TestUserArea1.Code, uniqueData));

            var log = await dbContext
                      .UserAuthenticationFailLogs
                      .AsNoTracking()
                      .Include(i => i.IPAddress)
                      .SingleOrDefaultAsync(l => l.Username == uniqueData);

            using (new AssertionScope())
            {
                log.Should().NotBeNull();
                log.IPAddress.Address.Should().Be(uniqueData);

                app.Mocks
                .CountMessagesPublished <UserAuthenticationFailedMessage>(m =>
                {
                    return(m.UserAreaCode == TestUserArea1.Code && m.Username == uniqueData);
                })
                .Should().Be(1);
            }
        }
Exemple #23
0
        public async Task ReturnsAllRoutes()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(ReturnsAllRoutes);

            using var app = _appFactory.Create();
            var testPages = new Dictionary <int, string>();

            for (int i = 1; i < 3; i++)
            {
                var parentDirectoryId = await app.TestData.PageDirectories().AddAsync(uniqueData + i);

                for (int j = 1; j < 4; j++)
                {
                    var pageTitle = uniqueData + j;
                    var pageId    = await app.TestData.Pages().AddAsync(pageTitle, parentDirectoryId);

                    testPages.Add(pageId, pageTitle);
                }
            }

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var results           = await contentRepository
                                    .Pages()
                                    .GetAll()
                                    .AsRoutes()
                                    .ExecuteAsync();

            using (new AssertionScope())
            {
                foreach (var testPage in testPages)
                {
                    results.Should().Contain(p => p.PageId == testPage.Key && p.Title == testPage.Value);
                }
            }
        }
Exemple #24
0
        public async Task CanUpdateProperties()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CanUpdateProperties);

            using var app = _appFactory.Create();
            var addDirectoryCommand = await app.TestData.PageDirectories().CreateAddCommandAsync(uniqueData);

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            await contentRepository
            .PageDirectories()
            .AddAsync(addDirectoryCommand);

            var updateCommand = MapFromAddCommand(addDirectoryCommand);

            updateCommand.Name = uniqueData + "U";
            await contentRepository
            .PageDirectories()
            .UpdateAsync(updateCommand);

            var dbContext = app.Services.GetRequiredService <CofoundryDbContext>();
            var directory = await dbContext
                            .PageDirectories
                            .AsNoTracking()
                            .FilterById(addDirectoryCommand.OutputPageDirectoryId)
                            .SingleOrDefaultAsync();

            using (new AssertionScope())
            {
                directory.Should().NotBeNull();
                directory.Name.Should().Be(updateCommand.Name);
                directory.UrlPath.Should().Be(addDirectoryCommand.UrlPath);
                directory.ParentPageDirectoryId.Should().Be(addDirectoryCommand.ParentPageDirectoryId);
            }
        }
        public async Task CanLog()
        {
            var uniqueData = UNIQUE_PREFIX + "CanLog";

            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepository();
            var dbContext         = app.Services.GetRequiredService <CofoundryDbContext>();

            app.Mocks.MockIPAddress(uniqueData);

            var userId = await app.TestData.Users().AddAsync(uniqueData);

            await contentRepository.ExecuteCommandAsync(new LogSuccessfulAuthenticationCommand()
            {
                UserId = userId
            });

            var log = await dbContext
                      .UserAuthenticationLogs
                      .AsNoTracking()
                      .Include(i => i.IPAddress)
                      .SingleOrDefaultAsync(l => l.UserId == userId);

            using (new AssertionScope())
            {
                log.Should().NotBeNull();
                log.IPAddress.Address.Should().Be(uniqueData);
            }
        }
Exemple #26
0
        public async Task ReturnsMappedData()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(ReturnsMappedData);

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

            var directory2Id = await app.TestData.PageDirectories().AddAsync(uniqueData + "-sub", directory1Id);

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var query             = new GetPageDirectoryEntityMicroSummariesByIdRangeQuery(new int[] { directory1Id, directory2Id });
            var directoryLookup   = await contentRepository.ExecuteQueryAsync(query);

            var directory1 = directoryLookup.GetOrDefault(directory1Id);
            var directory2 = directoryLookup.GetOrDefault(directory2Id);

            using (new AssertionScope())
            {
                directoryLookup.Should().NotBeNull();
                directoryLookup.Count.Should().Be(2);

                directory1.Should().NotBeNull();
                directory1.EntityDefinitionCode.Should().Be(PageDirectoryEntityDefinition.DefinitionCode);
                directory1.EntityDefinitionName.Should().Be(new PageDirectoryEntityDefinition().Name);
                directory1.IsPreviousVersion.Should().BeFalse();
                directory1.RootEntityId.Should().Be(directory1Id);
                directory1.RootEntityTitle.Should().Be(uniqueData);

                directory2.Should().NotBeNull();
            }
        }
        public async Task ReturnsAndMaps()
        {
            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var policyDescription = await contentRepository
                                    .UserAreas()
                                    .PasswordPolicies()
                                    .GetByCode(CofoundryAdminUserArea.Code)
                                    .AsDescription()
                                    .ExecuteAsync();

            using (new AssertionScope())
            {
                policyDescription.Should().NotBeNull();
                policyDescription.Description.Should()
                .NotBeNull()
                .And
                .Match("*between 10 and 300*");

                policyDescription.Attributes.Should().NotBeNullOrEmpty();
                policyDescription.Attributes.Should().Contain(PasswordPolicyAttributes.MinLength, "10");
                policyDescription.Attributes.Should().Contain(PasswordPolicyAttributes.MaxLength, "300");

                policyDescription.Criteria.Should().NotBeNullOrEmpty();
                policyDescription.Criteria.Should()
                .ContainMatch("*at least 10*")
                .And
                .ContainMatch("*not be * current password*")
                ;
            }
        }
        public async Task WhenQueriedWithPublishStatus_ReturnsCorrectWorkflowStatus(
            PublishStatusQuery publishStatus,
            WorkFlowStatus?draftOnlyWorkFlowStatus,
            WorkFlowStatus?publishOnlyWorkFlowStatus,
            WorkFlowStatus?publishAndDraftWorkFlowStatus
            )
        {
            var uniqueData = UNIQUE_PREFIX + "QPubStatus_" + publishStatus;

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

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

            var pageWithPublishedOnlyId = await app.TestData.Pages().AddAsync(uniqueData + "_P", directoryId, c => c.Publish = true);

            var pageWithPublishedandDraftId = await app.TestData.Pages().AddAsync(uniqueData + "_DP", directoryId, c => c.Publish = true);

            await app.TestData.Pages().AddDraftAsync(pageWithPublishedandDraftId);

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var pages             = await contentRepository
                                    .Pages()
                                    .GetByIdRange(new int[] { pageWithDraftOnlyId, pageWithPublishedOnlyId, pageWithPublishedandDraftId })
                                    .AsRenderSummaries(publishStatus)
                                    .ExecuteAsync();

            AssertStatus(pages, pageWithDraftOnlyId, draftOnlyWorkFlowStatus);
            AssertStatus(pages, pageWithPublishedOnlyId, publishOnlyWorkFlowStatus);
            AssertStatus(pages, pageWithPublishedandDraftId, publishAndDraftWorkFlowStatus);
Exemple #29
0
        public async Task ReturnsMappedRoute()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(ReturnsMappedRoute);

            using var app = _appFactory.Create();
            var contentRepository      = app.Services.GetContentRepositoryWithElevatedPermissions();
            var parentDirectoryCommand = await app.TestData.PageDirectories().CreateAddCommandAsync(uniqueData);

            var parentDirectoryId = await contentRepository
                                    .PageDirectories()
                                    .AddAsync(parentDirectoryCommand);

            var directoryId = await app.TestData.PageDirectories().AddAsync("Dir-1", parentDirectoryId);

            var directory = await contentRepository
                            .PageDirectories()
                            .GetById(directoryId)
                            .AsRoute()
                            .ExecuteAsync();

            var parentFullPath = "/" + parentDirectoryCommand.UrlPath;

            using (new AssertionScope())
            {
                directory.Should().NotBeNull();
                directory.IsSiteRoot().Should().BeFalse();
                directory.LocaleVariations.Should().NotBeNull().And.BeEmpty();
                directory.Name.Should().Be("Dir-1");
                directory.ParentPageDirectoryId.Should().Be(parentDirectoryId);
                directory.FullUrlPath.Should().Be(parentFullPath + "/dir-1");
                directory.UrlPath.Should().Be("dir-1");
            }
        }
Exemple #30
0
        public async Task ReturnsAndMaps()
        {
            using var app = _appFactory.Create();
            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var area1             = app.SeededEntities.TestUserArea1.Definition;
            var area2             = app.SeededEntities.TestUserArea2.Definition;

            var userAreas = await contentRepository
                            .UserAreas()
                            .GetAll()
                            .AsMicroSummaries()
                            .ExecuteAsync();

            using (new AssertionScope())
            {
                userAreas.Should().HaveCountGreaterOrEqualTo(2);
                userAreas.Should().BeInAscendingOrder(a => a.Name);

                var testArea1 = userAreas.SingleOrDefault(a => a.UserAreaCode == area1.UserAreaCode);
                testArea1.Should().NotBeNull();
                testArea1.Name.Should().Be(testArea1.Name);

                var testArea2 = userAreas.SingleOrDefault(a => a.UserAreaCode == area2.UserAreaCode);
                testArea2.Should().NotBeNull();
                testArea2.Name.Should().Be(testArea2.Name);
            }
        }