80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
|
|
using System.Linq.Expressions;
|
||
|
|
using System.Net;
|
||
|
|
using NUnit.Framework;
|
||
|
|
using Umbraco.Cms.Api.Management.Controllers.Document;
|
||
|
|
using Umbraco.Cms.Core;
|
||
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
||
|
|
using Umbraco.Cms.Core.Services;
|
||
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
||
|
|
|
||
|
|
namespace Umbraco.Cms.Tests.Integration.ManagementApi.Document;
|
||
|
|
|
||
|
|
public class ByKeyDocumentControllerTests : ManagementApiUserGroupTestBase<ByKeyDocumentController>
|
||
|
|
{
|
||
|
|
private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
|
||
|
|
|
||
|
|
private ITemplateService TemplateService => GetRequiredService<ITemplateService>();
|
||
|
|
|
||
|
|
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||
|
|
|
||
|
|
private Guid _documentKey;
|
||
|
|
|
||
|
|
[SetUp]
|
||
|
|
public async Task Setup()
|
||
|
|
{
|
||
|
|
// Template
|
||
|
|
var template = TemplateBuilder.CreateTextPageTemplate(Guid.NewGuid().ToString());
|
||
|
|
await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey);
|
||
|
|
|
||
|
|
// Content Type
|
||
|
|
var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id,
|
||
|
|
name: Guid.NewGuid().ToString(), alias: Guid.NewGuid().ToString());
|
||
|
|
contentType.AllowedAsRoot = true;
|
||
|
|
await ContentTypeService.CreateAsync(contentType, Constants.Security.SuperUserKey);
|
||
|
|
|
||
|
|
// Content
|
||
|
|
var createModel = new ContentCreateModel
|
||
|
|
{
|
||
|
|
ContentTypeKey = contentType.Key,
|
||
|
|
TemplateKey = template.Key,
|
||
|
|
ParentKey = Constants.System.RootKey,
|
||
|
|
Variants = new List<VariantModel> { new() { Name = Guid.NewGuid().ToString() } },
|
||
|
|
};
|
||
|
|
var response = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||
|
|
_documentKey = response.Result.Content.Key;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override Expression<Func<ByKeyDocumentController, object>> MethodSelector =>
|
||
|
|
x => x.ByKey(CancellationToken.None, _documentKey);
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.OK
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel EditorUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.OK
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel SensitiveDataUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.Forbidden
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel TranslatorUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.Forbidden
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel WriterUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.OK
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel UnauthorizedUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.Unauthorized
|
||
|
|
};
|
||
|
|
}
|