103 lines
4.0 KiB
C#
103 lines
4.0 KiB
C#
|
|
using System.Linq.Expressions;
|
||
|
|
using System.Net;
|
||
|
|
using System.Net.Http.Json;
|
||
|
|
using NUnit.Framework;
|
||
|
|
using Umbraco.Cms.Api.Management.Controllers.Document;
|
||
|
|
using Umbraco.Cms.Api.Management.ViewModels;
|
||
|
|
using Umbraco.Cms.Api.Management.ViewModels.Document;
|
||
|
|
using Umbraco.Cms.Core;
|
||
|
|
using Umbraco.Cms.Core.Models;
|
||
|
|
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 MoveDocumentControllerTests : ManagementApiUserGroupTestBase<MoveDocumentController>
|
||
|
|
{
|
||
|
|
private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
|
||
|
|
|
||
|
|
private ITemplateService TemplateService => GetRequiredService<ITemplateService>();
|
||
|
|
|
||
|
|
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||
|
|
|
||
|
|
private Guid _targetContentKey;
|
||
|
|
private Guid _moveContentKey;
|
||
|
|
|
||
|
|
[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;
|
||
|
|
contentType.AllowedContentTypes = [new ContentTypeSort(contentType.Key, 0, contentType.Alias)];
|
||
|
|
await ContentTypeService.CreateAsync(contentType, Constants.Security.SuperUserKey);
|
||
|
|
|
||
|
|
// Target Content
|
||
|
|
var targetCreateModel = new ContentCreateModel
|
||
|
|
{
|
||
|
|
ContentTypeKey = contentType.Key,
|
||
|
|
TemplateKey = template.Key,
|
||
|
|
ParentKey = Constants.System.RootKey,
|
||
|
|
Variants = new List<VariantModel> { new() { Name = Guid.NewGuid().ToString() } },
|
||
|
|
};
|
||
|
|
var responseTarget = await ContentEditingService.CreateAsync(targetCreateModel, Constants.Security.SuperUserKey);
|
||
|
|
_targetContentKey = responseTarget.Result.Content.Key;
|
||
|
|
|
||
|
|
// Move Content
|
||
|
|
var moveCreateModel = new ContentCreateModel
|
||
|
|
{
|
||
|
|
ContentTypeKey = contentType.Key,
|
||
|
|
TemplateKey = template.Key,
|
||
|
|
ParentKey = Constants.System.RootKey,
|
||
|
|
Variants = new List<VariantModel> { new() { Name = Guid.NewGuid().ToString() } },
|
||
|
|
};
|
||
|
|
var responseMove = await ContentEditingService.CreateAsync(moveCreateModel, Constants.Security.SuperUserKey);
|
||
|
|
_moveContentKey = responseMove.Result.Content.Key;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override Expression<Func<MoveDocumentController, object>> MethodSelector =>
|
||
|
|
x => x.Move(CancellationToken.None, _moveContentKey, null);
|
||
|
|
|
||
|
|
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.Forbidden
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel UnauthorizedUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.Unauthorized
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override async Task<HttpResponseMessage> ClientRequest()
|
||
|
|
{
|
||
|
|
MoveDocumentRequestModel moveDocumentRequestModel = new() { Target = new ReferenceByIdModel(_targetContentKey), };
|
||
|
|
|
||
|
|
return await Client.PutAsync(Url, JsonContent.Create(moveDocumentRequestModel));
|
||
|
|
}
|
||
|
|
}
|