* Introduce new AuditEntryService - Moved logic related to the IAuditEntryRepository from the AuditService to the new service - Introduced new Async methods - Using ids (for easier transition from the previous Write method) - Using keys - Moved and updated integration tests related to the audit entries to a new test class `AuditEntryServiceTests` - Added unit tests class `AuditEntryServiceTests` and added a few unit tests - Added migration to add columns for `performingUserKey` and `affectedUserKey` and convert existing user ids - Adjusted usages of the old AuditService.Write method to use the new one (mostly notification handlers) * Audit service rework - Added new async and paged methods - Marked (now) redundant methods as obsolete - Updated all of the usages to use the non-obsolete methods - Added unit tests class `AuditServiceTests` and some unit tests - Updated existing integration test * Apply suggestions from code review * Small improvement * Update src/Umbraco.Core/Services/AuditService.cs * Some minor adjustments following the merge * Delete unnecessary file * Small cleanup on the tests
72 lines
2.7 KiB
C#
72 lines
2.7 KiB
C#
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Events;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|
using Umbraco.Cms.Core.Notifications;
|
|
using Umbraco.Cms.Core.Serialization;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
|
|
|
public partial class ContentEditingServiceTests : ContentEditingServiceTestsBase
|
|
{
|
|
[SetUp]
|
|
public void Setup() => ContentRepositoryBase.ThrowOnWarning = true;
|
|
|
|
public void Relate(IContent parent, IContent child)
|
|
{
|
|
var relatedContentRelType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedDocumentAlias);
|
|
|
|
var relation = RelationService.Relate(parent.Id, child.Id, relatedContentRelType);
|
|
RelationService.Save(relation);
|
|
}
|
|
|
|
protected override void CustomTestSetup(IUmbracoBuilder builder)
|
|
=> builder.AddNotificationAsyncHandler<ContentCopiedNotification, RelateOnCopyNotificationHandler>();
|
|
|
|
private ITemplateService TemplateService => GetRequiredService<ITemplateService>();
|
|
|
|
private IJsonSerializer JsonSerializer => GetRequiredService<IJsonSerializer>();
|
|
|
|
private async Task<IContentType> CreateTextPageContentTypeAsync()
|
|
{
|
|
var template = TemplateBuilder.CreateTextPageTemplate();
|
|
await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey);
|
|
|
|
var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id);
|
|
contentType.AllowedAsRoot = true;
|
|
ContentTypeService.Save(contentType);
|
|
|
|
return contentType;
|
|
}
|
|
|
|
private async Task<(IContent root, IContent child)> CreateRootAndChildAsync(IContentType contentType, string rootName = "The Root", string childName = "The Child")
|
|
{
|
|
var createModel = new ContentCreateModel
|
|
{
|
|
ContentTypeKey = contentType.Key,
|
|
ParentKey = Constants.System.RootKey,
|
|
Variants = [new () { Name = rootName }]
|
|
};
|
|
|
|
var root = (await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result.Content!;
|
|
|
|
contentType.AllowedContentTypes = new List<ContentTypeSort>
|
|
{
|
|
new (contentType.Key, 1, contentType.Alias)
|
|
};
|
|
ContentTypeService.Save(contentType);
|
|
|
|
createModel.ParentKey = root.Key;
|
|
createModel.Variants = [new() { Name = childName }];
|
|
|
|
var child = (await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result.Content!;
|
|
Assert.AreEqual(root.Id, child.ParentId);
|
|
|
|
return (root, child);
|
|
}
|
|
}
|