V14: Composition endpoints for Document and Media types (#15584)
* Adding response/request models * Adding mapping * Adding factory * Adding controllers * Moved to correct (generic domain) namespace * Renamed to reflect the correct domain + renamed IsAllowed to IsCompatible * Renaming + TODO * Removed presentation logic + TODO * Fixed controller * Attempt for generic implementation * Enable composition of media types + refactor content/media type editing tests to prove it (and a little renaming of a mis-named property) * Remove unused classes * Introducing GetAvailableCompositionsAsync to EditingServices * Implement GetAvailableCompositionsAsync * Base share implementation * Tests * Tests * Renaming * Clean up controller * Clean up test * Remove redundant check * Create and use generic models * Add shared implementation * Fix and rename doc type mapper * Fix document Type factory * Add missing response type * Create a base request model * Make key nullable when new item * Media type response models * Default isElement to false and remove isElement param from media type related things * Create mappings for media type compositions * Inject generic base service to reuse implementation amongst concrete services * Add new composition endpoints for media type * Use specific type * Add a reference comment to other test suite * Add more test cases --------- Co-authored-by: kjac <kja@umbraco.dk>
This commit is contained in:
committed by
GitHub
parent
40a28a938c
commit
547da0b191
@@ -13,7 +13,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Create_With_All_Basic_Settings(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
createModel.Description = "This is the Test description";
|
||||
createModel.Icon = "icon icon-something";
|
||||
createModel.AllowedAsRoot = true;
|
||||
@@ -41,7 +41,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true, true)]
|
||||
public async Task Can_Create_With_Variation(bool variesByCulture, bool variesBySegment)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.VariesByCulture = variesByCulture;
|
||||
createModel.VariesBySegment = variesBySegment;
|
||||
|
||||
@@ -65,7 +65,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var container = containerResult.Result?.Entity;
|
||||
Assert.IsNotNull(container);
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement, parentKey: container.Key);
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement, containerKey: container.Key);
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(result.Success);
|
||||
|
||||
@@ -80,11 +80,11 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Create_With_Properties_In_A_Container(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container = CreateContainer();
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container = ContentTypePropertyContainerModel();
|
||||
createModel.Containers = new[] { container };
|
||||
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty", containerKey: container.Key);
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", "testProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { propertyType };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -107,9 +107,9 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Create_With_Orphaned_Properties(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty");
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", "testProperty");
|
||||
createModel.Properties = new[] { propertyType };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -131,7 +131,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
public async Task Can_Specify_Key()
|
||||
{
|
||||
var key = new Guid("33C326F6-CB5E-43D6-9730-E946AA5F9C7B");
|
||||
var createModel = CreateCreateModel(key: key);
|
||||
var createModel = ContentTypeCreateModel(key: key);
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
|
||||
@@ -150,10 +150,10 @@ public partial class ContentTypeEditingServiceTests
|
||||
{
|
||||
var propertyTypeKey = new Guid("82DDEBD8-D2CA-423E-B88D-6890F26152B4");
|
||||
|
||||
var propertyTypeContainer = CreateContainer();
|
||||
var propertyTypeCreateModel = CreatePropertyType(key: propertyTypeKey, containerKey: propertyTypeContainer.Key);
|
||||
var propertyTypeContainer = ContentTypePropertyContainerModel();
|
||||
var propertyTypeCreateModel = ContentTypePropertyTypeModel(key: propertyTypeKey, containerKey: propertyTypeContainer.Key);
|
||||
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
propertyTypes: new[] { propertyTypeCreateModel },
|
||||
containers: new[] { propertyTypeContainer });
|
||||
|
||||
@@ -174,12 +174,12 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Assign_Allowed_Types()
|
||||
{
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result;
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result;
|
||||
Assert.IsNotNull(allowedOne);
|
||||
Assert.IsNotNull(allowedTwo);
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedOne.Key, 10, allowedOne.Alias),
|
||||
@@ -202,7 +202,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Assign_History_Cleanup()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.Cleanup = new ContentTypeCleanup
|
||||
{
|
||||
PreventCleanup = true, KeepAllVersionsNewerThanDays = 123, KeepLatestVersionPerDayForDays = 456
|
||||
@@ -226,16 +226,16 @@ public partial class ContentTypeEditingServiceTests
|
||||
// Wondering where the last case is? Look at the test below.
|
||||
public async Task Can_Create_Composite(bool compositionIsElement, bool contentTypeIsElement)
|
||||
{
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
"compositionBase",
|
||||
isElement: compositionIsElement);
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var container = CreateContainer();
|
||||
var container = ContentTypePropertyContainerModel();
|
||||
compositionBase.Containers = new[] { container };
|
||||
|
||||
var compositionProperty = CreatePropertyType("Composition Property", "compositionProperty", containerKey: container.Key);
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: container.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
@@ -243,7 +243,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
isElement: contentTypeIsElement,
|
||||
compositions: new[]
|
||||
{
|
||||
@@ -273,17 +273,17 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Create_Property_Container_Structure_Matching_Composition_Container_Structure()
|
||||
{
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
"compositionBase");
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var compositionTab = CreateContainer("Composition Tab", type: TabContainerType);
|
||||
var compositionGroup = CreateContainer("Composition Group", type: GroupContainerType);
|
||||
var compositionTab = ContentTypePropertyContainerModel("Composition Tab", type: TabContainerType);
|
||||
var compositionGroup = ContentTypePropertyContainerModel("Composition Group", type: GroupContainerType);
|
||||
compositionGroup.ParentKey = compositionTab.Key;
|
||||
compositionBase.Containers = new[] { compositionTab, compositionGroup };
|
||||
|
||||
var compositionProperty = CreatePropertyType("Composition Property", "compositionProperty", containerKey: compositionGroup.Key);
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: compositionGroup.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
@@ -291,19 +291,19 @@ public partial class ContentTypeEditingServiceTests
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
}
|
||||
);
|
||||
|
||||
var tab = CreateContainer("Composition Tab", type: TabContainerType);
|
||||
var group = CreateContainer("Composition Group", type: GroupContainerType);
|
||||
var tab = ContentTypePropertyContainerModel("Composition Tab", type: TabContainerType);
|
||||
var group = ContentTypePropertyContainerModel("Composition Group", type: GroupContainerType);
|
||||
group.ParentKey = tab.Key;
|
||||
createModel.Containers = new[] { tab, group };
|
||||
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: group.Key);
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: group.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -328,18 +328,18 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Property_Container_Aliases_Are_CamelCased_Names()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var tab = CreateContainer("My Tab", type: TabContainerType);
|
||||
var group1 = CreateContainer("My Group", type: GroupContainerType);
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
var tab = ContentTypePropertyContainerModel("My Tab", type: TabContainerType);
|
||||
var group1 = ContentTypePropertyContainerModel("My Group", type: GroupContainerType);
|
||||
group1.ParentKey = tab.Key;
|
||||
var group2 = CreateContainer("AnotherGroup", type: GroupContainerType);
|
||||
var group2 = ContentTypePropertyContainerModel("AnotherGroup", type: GroupContainerType);
|
||||
createModel.Containers = new[] { tab, group1, group2 };
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: group1.Key);
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: group1.Key);
|
||||
// assign some properties to the groups to make sure they're not cleaned out as "empty groups"
|
||||
createModel.Properties = new[]
|
||||
{
|
||||
CreatePropertyType("My Property 1", "myProperty1", containerKey: group1.Key),
|
||||
CreatePropertyType("My Property 2", "myProperty2", containerKey: group2.Key)
|
||||
ContentTypePropertyTypeModel("My Property 1", "myProperty1", containerKey: group1.Key),
|
||||
ContentTypePropertyTypeModel("My Property 2", "myProperty2", containerKey: group2.Key)
|
||||
};
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -360,7 +360,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
// Even if it's an element type, however if we look at the comment in GetAvailableCompositeContentTypes
|
||||
// We see that element types are not suppose to be allowed to be composed by non-element types.
|
||||
// Since this breaks models builder evidently.
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
isElement: false);
|
||||
|
||||
@@ -368,7 +368,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
Assert.IsTrue(compositionResult.Success);
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
"Content Type Using Composition",
|
||||
compositions: new[]
|
||||
{
|
||||
@@ -393,12 +393,12 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task ContentType_Containing_Composition_Cannot_Be_Used_As_Composition()
|
||||
{
|
||||
var compositionBase = CreateCreateModel("CompositionBase");
|
||||
var compositionBase = ContentTypeCreateModel("CompositionBase");
|
||||
|
||||
var baseResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(baseResult.Success);
|
||||
|
||||
var composition = CreateCreateModel(
|
||||
var composition = ContentTypeCreateModel(
|
||||
"Composition",
|
||||
compositions: new[]
|
||||
{
|
||||
@@ -412,7 +412,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
Assert.IsTrue(compositionResult.Success);
|
||||
|
||||
// This is not allowed because the composition also has a composition (compositionBase).
|
||||
var invalidComposition = CreateCreateModel(
|
||||
var invalidComposition = ContentTypeCreateModel(
|
||||
"Invalid",
|
||||
compositions: new[]
|
||||
{
|
||||
@@ -437,15 +437,15 @@ public partial class ContentTypeEditingServiceTests
|
||||
public async Task Can_Create_Child()
|
||||
{
|
||||
|
||||
var parentProperty = CreatePropertyType("Parent Property", "parentProperty");
|
||||
var parentModel = CreateCreateModel(
|
||||
var parentProperty = ContentTypePropertyTypeModel("Parent Property", "parentProperty");
|
||||
var parentModel = ContentTypeCreateModel(
|
||||
"Parent",
|
||||
propertyTypes: new[] { parentProperty });
|
||||
|
||||
var parentResult = await ContentTypeEditingService.CreateAsync(parentModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(parentResult.Success);
|
||||
|
||||
var childProperty = CreatePropertyType("Child Property", "childProperty");
|
||||
var childProperty = ContentTypePropertyTypeModel("Child Property", "childProperty");
|
||||
var parentKey = parentResult.Result!.Key;
|
||||
Composition[] composition =
|
||||
{
|
||||
@@ -455,7 +455,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
},
|
||||
};
|
||||
|
||||
var childModel = CreateCreateModel(
|
||||
var childModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
propertyTypes: new[] { childProperty },
|
||||
compositions: composition);
|
||||
@@ -480,15 +480,15 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Create_Grandchild()
|
||||
{
|
||||
var rootProperty = CreatePropertyType("Root property");
|
||||
ContentTypeCreateModel rootModel = CreateCreateModel(
|
||||
var rootProperty = ContentTypePropertyTypeModel("Root property");
|
||||
ContentTypeCreateModel rootModel = ContentTypeCreateModel(
|
||||
"Root",
|
||||
propertyTypes: new[] { rootProperty });
|
||||
|
||||
var rootResult = await ContentTypeEditingService.CreateAsync(rootModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(rootResult.Success);
|
||||
|
||||
var childProperty = CreatePropertyType("Child Property", "childProperty");
|
||||
var childProperty = ContentTypePropertyTypeModel("Child Property", "childProperty");
|
||||
var rootKey = rootResult.Result!.Key;
|
||||
Composition[] composition =
|
||||
{
|
||||
@@ -498,7 +498,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
},
|
||||
};
|
||||
|
||||
var childModel = CreateCreateModel(
|
||||
var childModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
propertyTypes: new[] { childProperty },
|
||||
compositions: composition);
|
||||
@@ -506,7 +506,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var childResult = await ContentTypeEditingService.CreateAsync(childModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(childResult.Success);
|
||||
|
||||
var grandchildProperty = CreatePropertyType("Grandchild Property", "grandchildProperty");
|
||||
var grandchildProperty = ContentTypePropertyTypeModel("Grandchild Property", "grandchildProperty");
|
||||
var childKey = childResult.Result!.Key;
|
||||
Composition[] grandchildComposition =
|
||||
{
|
||||
@@ -516,7 +516,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
},
|
||||
};
|
||||
|
||||
var grandchildModel = CreateCreateModel(
|
||||
var grandchildModel = ContentTypeCreateModel(
|
||||
"Grandchild",
|
||||
propertyTypes: new[] { grandchildProperty },
|
||||
compositions: grandchildComposition);
|
||||
@@ -549,12 +549,12 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Be_Both_Parent_And_Composition()
|
||||
{
|
||||
var compositionBase = CreateCreateModel("CompositionBase");
|
||||
var compositionBase = ContentTypeCreateModel("CompositionBase");
|
||||
|
||||
var baseResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(baseResult.Success);
|
||||
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition
|
||||
@@ -578,15 +578,15 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Have_Multiple_Inheritance()
|
||||
{
|
||||
var parentModel1 = CreateCreateModel("Parent1");
|
||||
var parentModel2 = CreateCreateModel("Parent2");
|
||||
var parentModel1 = ContentTypeCreateModel("Parent1");
|
||||
var parentModel2 = ContentTypeCreateModel("Parent2");
|
||||
|
||||
var parentKey1 = (await ContentTypeEditingService.CreateAsync(parentModel1, Constants.Security.SuperUserKey)).Result?.Key;
|
||||
Assert.IsTrue(parentKey1.HasValue);
|
||||
var parentKey2 = (await ContentTypeEditingService.CreateAsync(parentModel2, Constants.Security.SuperUserKey)).Result?.Key;
|
||||
Assert.IsTrue(parentKey2.HasValue);
|
||||
|
||||
var childProperty = CreatePropertyType("Child Property", "childProperty");
|
||||
var childProperty = ContentTypePropertyTypeModel("Child Property", "childProperty");
|
||||
Composition[] composition =
|
||||
{
|
||||
new()
|
||||
@@ -599,7 +599,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
},
|
||||
};
|
||||
|
||||
var childModel = CreateCreateModel(
|
||||
var childModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
propertyTypes: new[] { childProperty },
|
||||
compositions: composition);
|
||||
@@ -614,15 +614,15 @@ public partial class ContentTypeEditingServiceTests
|
||||
public async Task Cannot_Specify_Duplicate_PropertyType_Alias_From_Compositions()
|
||||
{
|
||||
var propertyTypeAlias = "testproperty";
|
||||
var compositionPropertyType = CreatePropertyType("Test Property", propertyTypeAlias);
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionPropertyType = ContentTypePropertyTypeModel("Test Property", propertyTypeAlias);
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"CompositionBase",
|
||||
propertyTypes: new[] { compositionPropertyType });
|
||||
|
||||
var compositionBaseResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(compositionBaseResult.Success);
|
||||
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition
|
||||
@@ -632,7 +632,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
},
|
||||
propertyTypes: new[]
|
||||
{
|
||||
CreatePropertyType("Test Property", propertyTypeAlias)
|
||||
ContentTypePropertyTypeModel("Test Property", propertyTypeAlias)
|
||||
});
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.Multiple(() =>
|
||||
@@ -645,7 +645,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Specify_Non_Existent_DocType_As_Composition()
|
||||
{
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition
|
||||
@@ -665,7 +665,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Mix_Inheritance_And_ParentKey()
|
||||
{
|
||||
var parentModel = CreateCreateModel("Parent");
|
||||
var parentModel = ContentTypeCreateModel("Parent");
|
||||
var parentKey = (await ContentTypeEditingService.CreateAsync(parentModel, Constants.Security.SuperUserKey)).Result?.Key;
|
||||
Assert.IsTrue(parentKey.HasValue);
|
||||
|
||||
@@ -682,9 +682,9 @@ public partial class ContentTypeEditingServiceTests
|
||||
}
|
||||
};
|
||||
|
||||
var childModel = CreateCreateModel(
|
||||
var childModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
parentKey: container.Key,
|
||||
containerKey: container.Key,
|
||||
compositions: composition);
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(childModel, Constants.Security.SuperUserKey);
|
||||
@@ -696,13 +696,13 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Use_As_ParentKey()
|
||||
{
|
||||
var parentModel = CreateCreateModel("Parent");
|
||||
var parentModel = ContentTypeCreateModel("Parent");
|
||||
var parentKey = (await ContentTypeEditingService.CreateAsync(parentModel, Constants.Security.SuperUserKey)).Result?.Key;
|
||||
Assert.IsTrue(parentKey.HasValue);
|
||||
|
||||
var childModel = CreateCreateModel(
|
||||
var childModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
parentKey: parentKey.Value);
|
||||
containerKey: parentKey.Value);
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(childModel, Constants.Security.SuperUserKey);
|
||||
|
||||
@@ -737,8 +737,8 @@ public partial class ContentTypeEditingServiceTests
|
||||
|
||||
foreach (var alias in propertyTypeAliases)
|
||||
{
|
||||
var propertyType = CreatePropertyType("Test Property", alias);
|
||||
var createModel = CreateCreateModel("Test", propertyTypes: new[] { propertyType });
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", alias);
|
||||
var createModel = ContentTypeCreateModel("Test", propertyTypes: new[] { propertyType });
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
@@ -752,9 +752,9 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase("testProperty", "testproperty")]
|
||||
public async Task Cannot_Use_Duplicate_PropertyType_Alias(string propertyTypeAlias1, string propertyTypeAlias2)
|
||||
{
|
||||
var propertyType1 = CreatePropertyType("Test Property", propertyTypeAlias1);
|
||||
var propertyType2 = CreatePropertyType("Test Property", propertyTypeAlias2);
|
||||
var createModel = CreateCreateModel("Test", propertyTypes: new[] { propertyType1, propertyType2 });
|
||||
var propertyType1 = ContentTypePropertyTypeModel("Test Property", propertyTypeAlias1);
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Test Property", propertyTypeAlias2);
|
||||
var createModel = ContentTypeCreateModel("Test", propertyTypes: new[] { propertyType1, propertyType2 });
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
@@ -769,8 +769,8 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase("TESTALIAS", "testAlias")]
|
||||
public async Task Cannot_Use_Alias_As_PropertyType_Alias(string contentTypeAlias, string propertyTypeAlias)
|
||||
{
|
||||
var propertyType = CreatePropertyType("Test Property", propertyTypeAlias);
|
||||
var createModel = CreateCreateModel("Test", contentTypeAlias, propertyTypes: new[] { propertyType });
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", propertyTypeAlias);
|
||||
var createModel = ContentTypeCreateModel("Test", contentTypeAlias, propertyTypes: new[] { propertyType });
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
@@ -780,8 +780,8 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Use_Non_Existing_DataType_For_PropertyType()
|
||||
{
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty", dataTypeKey: Guid.NewGuid());
|
||||
var createModel = CreateCreateModel("Test", "test", propertyTypes: new[] { propertyType });
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", "testProperty", dataTypeKey: Guid.NewGuid());
|
||||
var createModel = ContentTypeCreateModel("Test", "test", propertyTypes: new[] { propertyType });
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
@@ -791,8 +791,8 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Use_Empty_Alias_For_PropertyType()
|
||||
{
|
||||
var propertyType = CreatePropertyType("Test Property", string.Empty);
|
||||
var createModel = CreateCreateModel("Test", "test", propertyTypes: new[] { propertyType });
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", string.Empty);
|
||||
var createModel = ContentTypeCreateModel("Test", "test", propertyTypes: new[] { propertyType });
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
@@ -802,9 +802,9 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Use_Empty_Name_For_PropertyType_Container()
|
||||
{
|
||||
var container = CreateContainer(string.Empty);
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty", containerKey: container.Key);
|
||||
var createModel = CreateCreateModel("Test", "test", propertyTypes: new[] { propertyType });
|
||||
var container = ContentTypePropertyContainerModel(string.Empty);
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", "testProperty", containerKey: container.Key);
|
||||
var createModel = ContentTypeCreateModel("Test", "test", propertyTypes: new[] { propertyType });
|
||||
createModel.Containers = new[] { container };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -823,7 +823,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase("SYSTEM")]
|
||||
public async Task Cannot_Use_Invalid_Alias(string contentTypeAlias)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", contentTypeAlias);
|
||||
var createModel = ContentTypeCreateModel("Test", contentTypeAlias);
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
@@ -833,11 +833,11 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Use_Existing_Alias()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(result.Success);
|
||||
|
||||
createModel = CreateCreateModel("Test 2", "test");
|
||||
createModel = ContentTypeCreateModel("Test 2", "test");
|
||||
result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
Assert.AreEqual(ContentTypeOperationStatus.DuplicateAlias, result.Status);
|
||||
@@ -846,15 +846,15 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Add_Container_From_Composition()
|
||||
{
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
"compositionBase");
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var compositionContainer = CreateContainer("Composition Tab");
|
||||
var compositionContainer = ContentTypePropertyContainerModel("Composition Tab");
|
||||
compositionBase.Containers = new[] { compositionContainer };
|
||||
|
||||
var compositionProperty = CreatePropertyType("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
@@ -862,7 +862,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
@@ -871,7 +871,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
|
||||
// this is invalid; the model should not contain the composition container definitions (they will be resolved by ContentTypeEditingService)
|
||||
createModel.Containers = new[] { compositionContainer };
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: compositionContainer.Key);
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: compositionContainer.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -882,14 +882,14 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Duplicate_Container_Key_From_Composition()
|
||||
{
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
"compositionBase");
|
||||
|
||||
var compositionContainer = CreateContainer("Composition Tab");
|
||||
var compositionContainer = ContentTypePropertyContainerModel("Composition Tab");
|
||||
compositionBase.Containers = new[] { compositionContainer };
|
||||
|
||||
var compositionProperty = CreatePropertyType("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
@@ -897,7 +897,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
@@ -905,9 +905,9 @@ public partial class ContentTypeEditingServiceTests
|
||||
);
|
||||
|
||||
// this is invalid; cannot reuse the container key
|
||||
var container = CreateContainer("My Group", type: GroupContainerType, key: compositionContainer.Key);
|
||||
var container = ContentTypePropertyContainerModel("My Group", type: GroupContainerType, key: compositionContainer.Key);
|
||||
createModel.Containers = new[] { container };
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: container.Key);
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -919,12 +919,12 @@ public partial class ContentTypeEditingServiceTests
|
||||
public async Task Cannot_Have_Duplicate_Container_Key()
|
||||
{
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
|
||||
// this is invalid; cannot reuse the container key
|
||||
var containerKey = Guid.NewGuid();
|
||||
var container1 = CreateContainer("My Group 1", key: containerKey);
|
||||
var container2 = CreateContainer("My Group 2", key: containerKey);
|
||||
var container1 = ContentTypePropertyContainerModel("My Group 1", key: containerKey);
|
||||
var container2 = ContentTypePropertyContainerModel("My Group 2", key: containerKey);
|
||||
createModel.Containers = new[] { container1, container2 };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -935,14 +935,14 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Add_Property_To_Missing_Container()
|
||||
{
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
"compositionBase");
|
||||
|
||||
var compositionContainer = CreateContainer("Composition Tab");
|
||||
var compositionContainer = ContentTypePropertyContainerModel("Composition Tab");
|
||||
compositionBase.Containers = new[] { compositionContainer };
|
||||
|
||||
var compositionProperty = CreatePropertyType("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
@@ -950,7 +950,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
@@ -958,7 +958,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
);
|
||||
|
||||
// this is invalid; cannot add properties to non-existing containers
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: Guid.NewGuid());
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: Guid.NewGuid());
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -970,14 +970,14 @@ public partial class ContentTypeEditingServiceTests
|
||||
public async Task Cannot_Add_Property_Container_To_Missing_Container()
|
||||
{
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel();
|
||||
var createModel = ContentTypeCreateModel();
|
||||
|
||||
var group = CreateContainer("My Group", type: GroupContainerType);
|
||||
var group = ContentTypePropertyContainerModel("My Group", type: GroupContainerType);
|
||||
// this is invalid; a container cannot have a non-existing parent container key
|
||||
group.ParentKey = Guid.NewGuid();
|
||||
createModel.Containers = new[] { group };
|
||||
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: group.Key);
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: group.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -988,15 +988,15 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Create_Property_In_Composition_Container()
|
||||
{
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
"compositionBase");
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var compositionContainer = CreateContainer("Composition Tab");
|
||||
var compositionContainer = ContentTypePropertyContainerModel("Composition Tab");
|
||||
compositionBase.Containers = new[] { compositionContainer };
|
||||
|
||||
var compositionProperty = CreatePropertyType("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
@@ -1004,7 +1004,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
@@ -1012,7 +1012,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
);
|
||||
|
||||
// this is invalid; cannot add a property on a container that belongs to the composition (the container must be duplicated to the content type itself)
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: compositionContainer.Key);
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: compositionContainer.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -1023,15 +1023,15 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Create_Property_Container_In_Composition_Container()
|
||||
{
|
||||
var compositionBase = CreateCreateModel(
|
||||
var compositionBase = ContentTypeCreateModel(
|
||||
"Composition Base",
|
||||
"compositionBase");
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var compositionContainer = CreateContainer("Composition Tab");
|
||||
var compositionContainer = ContentTypePropertyContainerModel("Composition Tab");
|
||||
compositionBase.Containers = new[] { compositionContainer };
|
||||
|
||||
var compositionProperty = CreatePropertyType("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: compositionContainer.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
@@ -1039,7 +1039,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
@@ -1047,14 +1047,43 @@ public partial class ContentTypeEditingServiceTests
|
||||
);
|
||||
|
||||
// this is invalid; cannot create a new container within a parent container that belongs to the composition (the parent container must be duplicated to the content type itself)
|
||||
var container = CreateContainer("My Group", type: GroupContainerType);
|
||||
var container = ContentTypePropertyContainerModel("My Group", type: GroupContainerType);
|
||||
container.ParentKey = compositionContainer.Key;
|
||||
createModel.Containers = new[] { container };
|
||||
var property = CreatePropertyType("My Property", "myProperty", containerKey: container.Key);
|
||||
var property = ContentTypePropertyTypeModel("My Property", "myProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
Assert.AreEqual(ContentTypeOperationStatus.MissingContainer, result.Status);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Create_Composite_With_MediaType()
|
||||
{
|
||||
var compositionBase = MediaTypeCreateModel("Composition Base");
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var container = MediaTypePropertyContainerModel();
|
||||
compositionBase.Containers = new[] { container };
|
||||
|
||||
var compositionProperty = MediaTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: container.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await MediaTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(compositionResult.Success);
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create doc type using the composition
|
||||
var createModel = ContentTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
}
|
||||
);
|
||||
|
||||
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
Assert.AreEqual(ContentTypeOperationStatus.InvalidComposition, result.Status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
public partial class ContentTypeEditingServiceTests
|
||||
{
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public async Task Can_Get_Available_Compositions_Only_From_Content_Type_Key(bool isElement)
|
||||
{
|
||||
var contentType1 = CreateBasicContentTypeModelWithSingleProperty("Content type 1", "Property 1", isElement);
|
||||
var result1 = await ContentTypeEditingService.CreateAsync(contentType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType2 = CreateBasicContentTypeModelWithSingleProperty("Content type 2", "Property 2", isElement);
|
||||
var result2 = await ContentTypeEditingService.CreateAsync(contentType2, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType3 = CreateBasicContentTypeModelWithSingleProperty("Content type 3", "Property 3", isElement);
|
||||
var result3 = await ContentTypeEditingService.CreateAsync(contentType3, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await ContentTypeEditingService.GetAvailableCompositionsAsync(
|
||||
result1.Result!.Key,
|
||||
Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<string>(),
|
||||
isElement);
|
||||
|
||||
Assert.AreEqual(2, availableCompositions.Count());
|
||||
|
||||
// Verify that contentType2 and contentType3 are present in available compositions
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result2.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result3.Result!.Key && compositionsResult.Allowed));
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public async Task Available_Compositions_For_Content_Type_Are_Not_Media_Types(bool isElement)
|
||||
{
|
||||
var contentType = CreateBasicContentTypeModelWithSingleProperty("Content type", "Property 1", isElement);
|
||||
var result1 = await ContentTypeEditingService.CreateAsync(contentType, Constants.Security.SuperUserKey);
|
||||
|
||||
var container2 = MediaTypePropertyContainerModel();
|
||||
var propertyType2 = MediaTypePropertyTypeModel("Property 2", containerKey: container2.Key);
|
||||
var mediaType = MediaTypeCreateModel(
|
||||
"Media type",
|
||||
propertyTypes: new[] { propertyType2 },
|
||||
containers: new[] { container2 });
|
||||
|
||||
await MediaTypeEditingService.CreateAsync(mediaType, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await ContentTypeEditingService.GetAvailableCompositionsAsync(
|
||||
result1.Result!.Key,
|
||||
Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<string>(),
|
||||
false);
|
||||
|
||||
Assert.AreEqual(0, availableCompositions.Count());
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public async Task Can_Get_Available_Compositions_For_New_Item(bool isElement)
|
||||
{
|
||||
var contentType1 = CreateBasicContentTypeModelWithSingleProperty("Content type 1", "Property 1", isElement);
|
||||
var result1 = await ContentTypeEditingService.CreateAsync(contentType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType2 = CreateBasicContentTypeModelWithSingleProperty("Content type 2", "Property 2", isElement);
|
||||
var result2 = await ContentTypeEditingService.CreateAsync(contentType2, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType3 = CreateBasicContentTypeModelWithSingleProperty("Content type 3", "Property 3", isElement);
|
||||
var result3 = await ContentTypeEditingService.CreateAsync(contentType3, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await ContentTypeEditingService.GetAvailableCompositionsAsync(
|
||||
null,
|
||||
Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<string>(),
|
||||
isElement);
|
||||
|
||||
Assert.AreEqual(3, availableCompositions.Count());
|
||||
|
||||
// Verify that all content types are present in available compositions
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result1.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result2.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result3.Result!.Key && compositionsResult.Allowed));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Available_Compositions_For_Element_Types_Are_Only_Element_Types()
|
||||
{
|
||||
var elementType1 = CreateBasicContentTypeModelWithSingleProperty("Element type 1", "Property 1", true);
|
||||
var result1 = await ContentTypeEditingService.CreateAsync(elementType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var elementType2 = CreateBasicContentTypeModelWithSingleProperty("Element type 2", "Property 2", true);
|
||||
var result2 = await ContentTypeEditingService.CreateAsync(elementType2, Constants.Security.SuperUserKey);
|
||||
|
||||
var elementType3 = CreateBasicContentTypeModelWithSingleProperty("Element type 3", "Property 3", true);
|
||||
var result3 = await ContentTypeEditingService.CreateAsync(elementType3, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType = CreateBasicContentTypeModelWithSingleProperty("Content type", "Property 4", false);
|
||||
await ContentTypeEditingService.CreateAsync(contentType, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await ContentTypeEditingService.GetAvailableCompositionsAsync(
|
||||
result1.Result!.Key,
|
||||
Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<string>(),
|
||||
true);
|
||||
|
||||
Assert.AreEqual(2, availableCompositions.Count());
|
||||
|
||||
// Verify that only element types are present in available compositions
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result2.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result3.Result!.Key && compositionsResult.Allowed));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Available_Compositions_For_Content_Types_Can_Be_Element_Types()
|
||||
{
|
||||
var elementType1 = CreateBasicContentTypeModelWithSingleProperty("Element type 1", "Property 1", true);
|
||||
var result1 = await ContentTypeEditingService.CreateAsync(elementType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var elementType2 = CreateBasicContentTypeModelWithSingleProperty("Element type 2", "Property 2", true);
|
||||
var result2 = await ContentTypeEditingService.CreateAsync(elementType2, Constants.Security.SuperUserKey);
|
||||
|
||||
var elementType3 = CreateBasicContentTypeModelWithSingleProperty("Element type 3", "Property 3", true);
|
||||
var result3 = await ContentTypeEditingService.CreateAsync(elementType3, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType1 = CreateBasicContentTypeModelWithSingleProperty("Content type 1", "Property 4", false);
|
||||
var result4 = await ContentTypeEditingService.CreateAsync(contentType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType2 = CreateBasicContentTypeModelWithSingleProperty("Content type 2", "Property 5", false);
|
||||
var result5 = await ContentTypeEditingService.CreateAsync(contentType2, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await ContentTypeEditingService.GetAvailableCompositionsAsync(
|
||||
result4.Result!.Key,
|
||||
Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<string>(),
|
||||
false);
|
||||
|
||||
Assert.AreEqual(4, availableCompositions.Count());
|
||||
|
||||
// Verify that the rest of content types (element types included) are present in available compositions
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result1.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result2.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result3.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result5.Result!.Key && compositionsResult.Allowed));
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public async Task Content_Type_Picked_As_Composition_Is_Available_But_Not_Allowed(bool isElement)
|
||||
{
|
||||
var contentType1 = CreateBasicContentTypeModelWithSingleProperty("Content type 1", "Property 1", isElement);
|
||||
var result1 = await ContentTypeEditingService.CreateAsync(contentType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType2 = CreateBasicContentTypeModelWithSingleProperty("Content type 2", "Property 2", isElement);
|
||||
var result2 = await ContentTypeEditingService.CreateAsync(contentType2, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType3 = CreateBasicContentTypeModelWithSingleProperty("Content type 3", "Property 3", isElement);
|
||||
var result3 = await ContentTypeEditingService.CreateAsync(contentType3, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await ContentTypeEditingService.GetAvailableCompositionsAsync(
|
||||
null,
|
||||
new[] { result2.Result!.Key },
|
||||
Enumerable.Empty<string>(),
|
||||
isElement);
|
||||
|
||||
// Verify that all content types are present in available compositions
|
||||
Assert.AreEqual(3, availableCompositions.Count());
|
||||
|
||||
// Verify that contentType2 is not allowed because it is selected as composition already, so cannot be picked again
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result1.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result2.Result!.Key && compositionsResult.Allowed == false));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result3.Result!.Key && compositionsResult.Allowed));
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public async Task Content_Type_With_Matching_Composition_Property_Is_Available_But_Not_Allowed(bool isElement)
|
||||
{
|
||||
var contentType1 = CreateBasicContentTypeModelWithSingleProperty("Content type 1", "Property 1", isElement);
|
||||
var result1 = await ContentTypeEditingService.CreateAsync(contentType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType2 = CreateBasicContentTypeModelWithSingleProperty("Content type 2", "Property 2", isElement);
|
||||
var result2 = await ContentTypeEditingService.CreateAsync(contentType2, Constants.Security.SuperUserKey);
|
||||
|
||||
var contentType3 = CreateBasicContentTypeModelWithSingleProperty("Content type 3", "Property 3", isElement);
|
||||
var result3 = await ContentTypeEditingService.CreateAsync(contentType3, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await ContentTypeEditingService.GetAvailableCompositionsAsync(
|
||||
null,
|
||||
Enumerable.Empty<Guid>(),
|
||||
new[] { "property3" },
|
||||
isElement);
|
||||
|
||||
// Verify that all content types are present in available compositions
|
||||
Assert.AreEqual(3, availableCompositions.Count());
|
||||
|
||||
// Verify that contentType3 is not allowed because it has a matching property with the current state of the item we are using to look
|
||||
// for available compositions
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result1.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result2.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result3.Result!.Key && compositionsResult.Allowed == false));
|
||||
}
|
||||
|
||||
private ContentTypeCreateModel CreateBasicContentTypeModelWithSingleProperty(string contentTypeName, string propertyName, bool isElement)
|
||||
{
|
||||
var container = ContentTypePropertyContainerModel();
|
||||
var propertyType = ContentTypePropertyTypeModel(propertyName, containerKey: container.Key);
|
||||
var contentType = ContentTypeCreateModel(
|
||||
contentTypeName,
|
||||
isElement: isElement,
|
||||
propertyTypes: new[] { propertyType },
|
||||
containers: new[] { container });
|
||||
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,13 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Update_All_Basic_Settings(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
createModel.Description = "This is the Test description";
|
||||
createModel.Icon = "icon icon-something";
|
||||
createModel.AllowedAsRoot = true;
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test updated", "testUpdated", isElement: isElement);
|
||||
var updateModel = ContentTypeUpdateModel("Test updated", "testUpdated", isElement: isElement);
|
||||
updateModel.Description = "This is the Test description updated";
|
||||
updateModel.Icon = "icon icon-something-updated";
|
||||
updateModel.AllowedAsRoot = false;
|
||||
@@ -46,13 +46,13 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true, true)]
|
||||
public async Task Can_Update_Variation(bool variesByCulture, bool variesBySegment)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.VariesByCulture = variesByCulture;
|
||||
createModel.VariesBySegment = variesBySegment;
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.VariesByCulture = !variesByCulture;
|
||||
updateModel.VariesBySegment = !variesBySegment;
|
||||
|
||||
@@ -70,17 +70,17 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Add_Allowed_Types()
|
||||
{
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedOne.Key, 10, allowedOne.Alias),
|
||||
};
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedOne.Key, 10, allowedOne.Alias),
|
||||
@@ -104,10 +104,10 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Remove_Allowed_Types()
|
||||
{
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedOne.Key, 10, allowedOne.Alias),
|
||||
@@ -115,7 +115,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
};
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.AllowedContentTypes = Array.Empty<ContentTypeSort>();
|
||||
|
||||
var result = await ContentTypeEditingService.UpdateAsync(contentType, updateModel, Constants.Security.SuperUserKey);
|
||||
@@ -133,10 +133,10 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Rearrange_Allowed_Types()
|
||||
{
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedOne = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedOne.Key, 0, allowedOne.Alias),
|
||||
@@ -144,7 +144,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
};
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedOne.Key, 1, allowedOne.Alias),
|
||||
@@ -168,11 +168,11 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Add_Self_To_Allowed_Types()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
var id = contentType.Id;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(contentType.Key, 0, contentType.Alias)
|
||||
@@ -195,18 +195,18 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Add_Properties(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container = CreateContainer();
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container = ContentTypePropertyContainerModel();
|
||||
createModel.Containers = new[] { container };
|
||||
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty", containerKey: container.Key);
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", "testProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { propertyType };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
updateModel.Containers = new[] { container };
|
||||
var newPropertyType = CreatePropertyType("Test Property 2", "testProperty2", containerKey: container.Key);
|
||||
var newPropertyType = ContentTypePropertyTypeModel("Test Property 2", "testProperty2", containerKey: container.Key);
|
||||
newPropertyType.SortOrder = 0;
|
||||
propertyType.SortOrder = 1;
|
||||
updateModel.Properties = new[] { propertyType, newPropertyType };
|
||||
@@ -239,16 +239,16 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Remove_Properties(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container = CreateContainer();
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container = ContentTypePropertyContainerModel();
|
||||
createModel.Containers = new[] { container };
|
||||
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty", containerKey: container.Key);
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", "testProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { propertyType };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
updateModel.Containers = new[] { container };
|
||||
updateModel.Properties = Array.Empty<ContentTypePropertyTypeModel>();
|
||||
|
||||
@@ -271,16 +271,16 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Edit_Properties(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty");
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var propertyType = ContentTypePropertyTypeModel("Test Property", "testProperty");
|
||||
propertyType.Description = "The description";
|
||||
createModel.Properties = new[] { propertyType };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
var originalPropertyTypeKey = contentType.PropertyTypes.First().Key;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
propertyType = CreatePropertyType("Test Property 2", "testProperty", key: originalPropertyTypeKey);
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
propertyType = ContentTypePropertyTypeModel("Test Property 2", "testProperty", key: originalPropertyTypeKey);
|
||||
propertyType.Description = "The updated description";
|
||||
updateModel.Properties = new[] { propertyType };
|
||||
|
||||
@@ -309,18 +309,18 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Move_Properties_To_Another_Container(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container1 = CreateContainer("One");
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container1 = ContentTypePropertyContainerModel("One");
|
||||
createModel.Containers = new[] { container1 };
|
||||
|
||||
var propertyType1 = CreatePropertyType("Test Property 1", "testProperty1", containerKey: container1.Key);
|
||||
var propertyType2 = CreatePropertyType("Test Property 2", "testProperty2", containerKey: container1.Key);
|
||||
var propertyType1 = ContentTypePropertyTypeModel("Test Property 1", "testProperty1", containerKey: container1.Key);
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Test Property 2", "testProperty2", containerKey: container1.Key);
|
||||
createModel.Properties = new[] { propertyType1, propertyType2 };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
var container2 = CreateContainer("Two");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
var container2 = ContentTypePropertyContainerModel("Two");
|
||||
container2.SortOrder = 0;
|
||||
container1.SortOrder = 1;
|
||||
updateModel.Containers = new[] { container1, container2 };
|
||||
@@ -351,20 +351,20 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Rearrange_Containers(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container1 = CreateContainer("One");
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container1 = ContentTypePropertyContainerModel("One");
|
||||
container1.SortOrder = 0;
|
||||
var container2 = CreateContainer("Two");
|
||||
var container2 = ContentTypePropertyContainerModel("Two");
|
||||
container2.SortOrder = 1;
|
||||
createModel.Containers = new[] { container1, container2 };
|
||||
|
||||
var propertyType1 = CreatePropertyType("Test Property 1", "testProperty1", containerKey: container1.Key);
|
||||
var propertyType2 = CreatePropertyType("Test Property 2", "testProperty2", containerKey: container2.Key);
|
||||
var propertyType1 = ContentTypePropertyTypeModel("Test Property 1", "testProperty1", containerKey: container1.Key);
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Test Property 2", "testProperty2", containerKey: container2.Key);
|
||||
createModel.Properties = new[] { propertyType1, propertyType2 };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
container2.SortOrder = 0;
|
||||
container1.SortOrder = 1;
|
||||
updateModel.Containers = new[] { container1, container2 };
|
||||
@@ -390,18 +390,18 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Can_Make_Properties_Orphaned(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container1 = CreateContainer("One");
|
||||
var container2 = CreateContainer("Two");
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container1 = ContentTypePropertyContainerModel("One");
|
||||
var container2 = ContentTypePropertyContainerModel("Two");
|
||||
createModel.Containers = new[] { container1, container2 };
|
||||
|
||||
var propertyType1 = CreatePropertyType("Test Property 1", "testProperty1", containerKey: container1.Key);
|
||||
var propertyType2 = CreatePropertyType("Test Property 2", "testProperty2", containerKey: container2.Key);
|
||||
var propertyType1 = ContentTypePropertyTypeModel("Test Property 1", "testProperty1", containerKey: container1.Key);
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Test Property 2", "testProperty2", containerKey: container2.Key);
|
||||
createModel.Properties = new[] { propertyType1, propertyType2 };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
updateModel.Containers = new[] { container1 };
|
||||
propertyType2.ContainerKey = null;
|
||||
updateModel.Properties = new[] { propertyType1, propertyType2 };
|
||||
@@ -427,18 +427,18 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Add_Compositions()
|
||||
{
|
||||
var propertyType1 = CreatePropertyType("Test Property 1", "testProperty1");
|
||||
var propertyType2 = CreatePropertyType("Test Property 2", "testProperty2");
|
||||
var propertyType1 = ContentTypePropertyTypeModel("Test Property 1", "testProperty1");
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Test Property 2", "testProperty2");
|
||||
|
||||
var compositionCreateModel = CreateCreateModel("Composition", "composition");
|
||||
var compositionCreateModel = ContentTypeCreateModel("Composition", "composition");
|
||||
compositionCreateModel.Properties = new[] { propertyType1 };
|
||||
var compositionContentType = (await ContentTypeEditingService.CreateAsync(compositionCreateModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.Properties = new[] { propertyType2 };
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.Properties = new[] { propertyType2 };
|
||||
updateModel.Compositions = new[]
|
||||
{
|
||||
@@ -464,14 +464,14 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Reapply_Compositions()
|
||||
{
|
||||
var propertyType1 = CreatePropertyType("Test Property 1", "testProperty1");
|
||||
var propertyType2 = CreatePropertyType("Test Property 2", "testProperty2");
|
||||
var propertyType1 = ContentTypePropertyTypeModel("Test Property 1", "testProperty1");
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Test Property 2", "testProperty2");
|
||||
|
||||
var compositionCreateModel = CreateCreateModel("Composition", "composition");
|
||||
var compositionCreateModel = ContentTypeCreateModel("Composition", "composition");
|
||||
compositionCreateModel.Properties = new[] { propertyType1 };
|
||||
var compositionContentType = (await ContentTypeEditingService.CreateAsync(compositionCreateModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.Properties = new[] { propertyType2 };
|
||||
createModel.Compositions = new[]
|
||||
{
|
||||
@@ -479,7 +479,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
};
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.Properties = new[] { propertyType2 };
|
||||
updateModel.Compositions = new[]
|
||||
{
|
||||
@@ -505,14 +505,14 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Remove_Compositions()
|
||||
{
|
||||
var propertyType1 = CreatePropertyType("Test Property 1", "testProperty1");
|
||||
var propertyType2 = CreatePropertyType("Test Property 2", "testProperty2");
|
||||
var propertyType1 = ContentTypePropertyTypeModel("Test Property 1", "testProperty1");
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Test Property 2", "testProperty2");
|
||||
|
||||
var compositionCreateModel = CreateCreateModel("Composition", "composition");
|
||||
var compositionCreateModel = ContentTypeCreateModel("Composition", "composition");
|
||||
compositionCreateModel.Properties = new[] { propertyType1 };
|
||||
var compositionContentType = (await ContentTypeEditingService.CreateAsync(compositionCreateModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.Properties = new[] { propertyType2 };
|
||||
createModel.Compositions = new[]
|
||||
{
|
||||
@@ -520,7 +520,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
};
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.Properties = new[] { propertyType2 };
|
||||
updateModel.Compositions = Array.Empty<Composition>();
|
||||
|
||||
@@ -540,9 +540,9 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Reapply_Inheritance()
|
||||
{
|
||||
var parentContentType = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Parent"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Parent"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -552,7 +552,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
var originalPath = contentType.Path;
|
||||
|
||||
var updateModel = CreateUpdateModel(
|
||||
var updateModel = ContentTypeUpdateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -575,14 +575,14 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Update_History_Cleanup()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.Cleanup = new ContentTypeCleanup
|
||||
{
|
||||
PreventCleanup = true, KeepAllVersionsNewerThanDays = 123, KeepLatestVersionPerDayForDays = 456
|
||||
};
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test updated", "testUpdated");
|
||||
var updateModel = ContentTypeUpdateModel("Test updated", "testUpdated");
|
||||
updateModel.Cleanup = new ContentTypeCleanup
|
||||
{
|
||||
PreventCleanup = false, KeepAllVersionsNewerThanDays = 234, KeepLatestVersionPerDayForDays = 567
|
||||
@@ -605,16 +605,16 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Cannot_Move_Properties_To_Non_Existing_Containers(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container = CreateContainer("One");
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container = ContentTypePropertyContainerModel("One");
|
||||
createModel.Containers = new[] { container };
|
||||
|
||||
var property = CreatePropertyType("Test Property", "testProperty", containerKey: container.Key);
|
||||
var property = ContentTypePropertyTypeModel("Test Property", "testProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
property.ContainerKey = Guid.NewGuid();
|
||||
updateModel.Containers = new[] { container };
|
||||
updateModel.Properties = new[] { property };
|
||||
@@ -628,16 +628,16 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(true)]
|
||||
public async Task Cannot_Move_Containers_To_Non_Existing_Containers(bool isElement)
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test", isElement: isElement);
|
||||
var container = CreateContainer("One");
|
||||
var createModel = ContentTypeCreateModel("Test", "test", isElement: isElement);
|
||||
var container = ContentTypePropertyContainerModel("One");
|
||||
createModel.Containers = new[] { container };
|
||||
|
||||
var property = CreatePropertyType("Test Property", "testProperty", containerKey: container.Key);
|
||||
var property = ContentTypePropertyTypeModel("Test Property", "testProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { property };
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test", isElement: isElement);
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test", isElement: isElement);
|
||||
container.ParentKey = Guid.NewGuid();
|
||||
updateModel.Containers = new[] { container };
|
||||
updateModel.Properties = new[] { property };
|
||||
@@ -650,12 +650,12 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Add_Self_As_Composition()
|
||||
{
|
||||
var property = CreatePropertyType("Test Property", "testProperty");
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var property = ContentTypePropertyTypeModel("Test Property", "testProperty");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.Properties = new[] { property };
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.Properties = new[] { property };
|
||||
updateModel.Compositions = new[]
|
||||
{
|
||||
@@ -670,10 +670,10 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Change_Inheritance()
|
||||
{
|
||||
var parentContentType1 = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Parent1"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType2 = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Parent2"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType1 = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Parent1"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType2 = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Parent2"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -682,7 +682,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel(
|
||||
var updateModel = ContentTypeUpdateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -697,10 +697,10 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Add_Inheritance()
|
||||
{
|
||||
var parentContentType = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Parent"), Constants.Security.SuperUserKey)).Result!;
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Child"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Parent"), Constants.Security.SuperUserKey)).Result!;
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Child"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel(
|
||||
var updateModel = ContentTypeUpdateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -715,10 +715,10 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Add_Multiple_Inheritance()
|
||||
{
|
||||
var parentContentType1 = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Parent1"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType2 = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Parent2"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType1 = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Parent1"), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType2 = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Parent2"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel(
|
||||
var createModel = ContentTypeCreateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -727,7 +727,7 @@ public partial class ContentTypeEditingServiceTests
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel(
|
||||
var updateModel = ContentTypeUpdateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -743,11 +743,11 @@ public partial class ContentTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Cannot_Add_Self_As_Inheritance()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.Compositions = new Composition[]
|
||||
{
|
||||
new() { CompositionType = CompositionType.Inheritance, Key = contentType.Key }
|
||||
@@ -763,10 +763,10 @@ public partial class ContentTypeEditingServiceTests
|
||||
{
|
||||
EntityContainer container = ContentTypeService.CreateContainer(Constants.System.Root, Guid.NewGuid(), "Test folder").Result!.Entity;
|
||||
|
||||
var parentContentType = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Parent"), Constants.Security.SuperUserKey)).Result!;
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(CreateCreateModel("Child", parentKey: container.Key), Constants.Security.SuperUserKey)).Result!;
|
||||
var parentContentType = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Parent"), Constants.Security.SuperUserKey)).Result!;
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(ContentTypeCreateModel("Child", containerKey: container.Key), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel(
|
||||
var updateModel = ContentTypeUpdateModel(
|
||||
"Child",
|
||||
compositions: new Composition[]
|
||||
{
|
||||
@@ -782,17 +782,17 @@ public partial class ContentTypeEditingServiceTests
|
||||
[TestCase(CompositionType.Inheritance, CompositionType.Composition)]
|
||||
public async Task Cannot_Change_Composition_To_Inheritance(CompositionType from, CompositionType to)
|
||||
{
|
||||
var compositionCreateModel = CreateCreateModel("Composition", "composition");
|
||||
var compositionCreateModel = ContentTypeCreateModel("Composition", "composition");
|
||||
var compositionContentType = (await ContentTypeEditingService.CreateAsync(compositionCreateModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = ContentTypeCreateModel("Test", "test");
|
||||
createModel.Compositions = new[]
|
||||
{
|
||||
new Composition { Key = compositionContentType.Key, CompositionType = from }
|
||||
};
|
||||
var contentType = (await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = ContentTypeUpdateModel("Test", "test");
|
||||
updateModel.Compositions = new[]
|
||||
{
|
||||
new Composition { Key = compositionContentType.Key, CompositionType = to }
|
||||
|
||||
@@ -1,92 +1,5 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
using PropertyTypeValidation = Umbraco.Cms.Core.Models.ContentTypeEditing.PropertyTypeValidation;
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
[TestFixture]
|
||||
[UmbracoTest(
|
||||
Database = UmbracoTestOptions.Database.NewSchemaPerTest,
|
||||
PublishedRepositoryEvents = true,
|
||||
WithApplication = true)]
|
||||
public partial class ContentTypeEditingServiceTests : UmbracoIntegrationTest
|
||||
public partial class ContentTypeEditingServiceTests : ContentTypeEditingServiceTestsBase
|
||||
{
|
||||
private IContentTypeEditingService ContentTypeEditingService => GetRequiredService<IContentTypeEditingService>();
|
||||
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
|
||||
private const string TabContainerType = "Tab";
|
||||
|
||||
private const string GroupContainerType = "Group";
|
||||
|
||||
private ContentTypeCreateModel CreateCreateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
bool isElement = false,
|
||||
Guid? parentKey = null,
|
||||
IEnumerable<ContentTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<ContentTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
ContainerKey = parentKey,
|
||||
Properties = propertyTypes ?? Enumerable.Empty<ContentTypePropertyTypeModel>(),
|
||||
Containers = containers ?? Enumerable.Empty<ContentTypePropertyContainerModel>(),
|
||||
Compositions = compositions ?? Enumerable.Empty<Composition>(),
|
||||
IsElement = isElement
|
||||
};
|
||||
|
||||
private ContentTypeUpdateModel CreateUpdateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
bool isElement = false,
|
||||
IEnumerable<ContentTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<ContentTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Properties = propertyTypes ?? Enumerable.Empty<ContentTypePropertyTypeModel>(),
|
||||
Containers = containers ?? Enumerable.Empty<ContentTypePropertyContainerModel>(),
|
||||
Compositions = compositions ?? Enumerable.Empty<Composition>(),
|
||||
IsElement = isElement
|
||||
};
|
||||
|
||||
private ContentTypePropertyTypeModel CreatePropertyType(
|
||||
string name = "Title",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
Guid? containerKey = null,
|
||||
Guid? dataTypeKey = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
ContainerKey = containerKey,
|
||||
DataTypeKey = dataTypeKey ?? Constants.DataTypes.Guids.TextstringGuid,
|
||||
Validation = new PropertyTypeValidation(),
|
||||
Appearance = new PropertyTypeAppearance(),
|
||||
};
|
||||
|
||||
private ContentTypePropertyContainerModel CreateContainer(
|
||||
string name = "Container",
|
||||
string type = TabContainerType,
|
||||
Guid? key = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Type = type,
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
[TestFixture]
|
||||
[UmbracoTest(
|
||||
Database = UmbracoTestOptions.Database.NewSchemaPerTest,
|
||||
PublishedRepositoryEvents = true,
|
||||
WithApplication = true)]
|
||||
public abstract class ContentTypeEditingServiceTestsBase : UmbracoIntegrationTest
|
||||
{
|
||||
protected IContentTypeEditingService ContentTypeEditingService => GetRequiredService<IContentTypeEditingService>();
|
||||
|
||||
protected IMediaTypeEditingService MediaTypeEditingService => GetRequiredService<IMediaTypeEditingService>();
|
||||
|
||||
protected IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
|
||||
protected IMediaTypeService MediaTypeService => GetRequiredService<IMediaTypeService>();
|
||||
|
||||
protected const string TabContainerType = "Tab";
|
||||
|
||||
protected const string GroupContainerType = "Group";
|
||||
|
||||
protected ContentTypeCreateModel ContentTypeCreateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
bool isElement = false,
|
||||
Guid? containerKey = null,
|
||||
IEnumerable<ContentTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<ContentTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null)
|
||||
{
|
||||
var model = CreateContentEditingModel<ContentTypeCreateModel, ContentTypePropertyTypeModel, ContentTypePropertyContainerModel>(
|
||||
name,
|
||||
alias,
|
||||
isElement,
|
||||
propertyTypes,
|
||||
containers,
|
||||
compositions);
|
||||
model.Key = key ?? Guid.NewGuid();
|
||||
model.Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name);
|
||||
model.ContainerKey = containerKey;
|
||||
return model;
|
||||
}
|
||||
|
||||
protected MediaTypeCreateModel MediaTypeCreateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
bool isElement = false,
|
||||
Guid? containerKey = null,
|
||||
IEnumerable<MediaTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<MediaTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null)
|
||||
{
|
||||
var model = CreateContentEditingModel<MediaTypeCreateModel, MediaTypePropertyTypeModel, MediaTypePropertyContainerModel>(
|
||||
name,
|
||||
alias,
|
||||
isElement,
|
||||
propertyTypes,
|
||||
containers,
|
||||
compositions);
|
||||
model.Key = key ?? Guid.NewGuid();
|
||||
model.Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name);
|
||||
model.ContainerKey = containerKey;
|
||||
return model;
|
||||
}
|
||||
|
||||
protected ContentTypeUpdateModel ContentTypeUpdateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
bool isElement = false,
|
||||
IEnumerable<ContentTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<ContentTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null)
|
||||
=> CreateContentEditingModel<ContentTypeUpdateModel, ContentTypePropertyTypeModel, ContentTypePropertyContainerModel>(
|
||||
name,
|
||||
alias,
|
||||
isElement,
|
||||
propertyTypes,
|
||||
containers,
|
||||
compositions);
|
||||
|
||||
protected MediaTypeUpdateModel MediaTypeUpdateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
bool isElement = false,
|
||||
IEnumerable<MediaTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<MediaTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null)
|
||||
=> CreateContentEditingModel<MediaTypeUpdateModel, MediaTypePropertyTypeModel, MediaTypePropertyContainerModel>(
|
||||
name,
|
||||
alias,
|
||||
isElement,
|
||||
propertyTypes,
|
||||
containers,
|
||||
compositions);
|
||||
|
||||
protected ContentTypePropertyTypeModel ContentTypePropertyTypeModel(
|
||||
string name = "Title",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
Guid? containerKey = null,
|
||||
Guid? dataTypeKey = null)
|
||||
=> CreatePropertyType<ContentTypePropertyTypeModel>(name, alias, key, containerKey, dataTypeKey);
|
||||
|
||||
protected MediaTypePropertyTypeModel MediaTypePropertyTypeModel(
|
||||
string name = "Title",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
Guid? containerKey = null,
|
||||
Guid? dataTypeKey = null)
|
||||
=> CreatePropertyType<MediaTypePropertyTypeModel>(name, alias, key, containerKey, dataTypeKey);
|
||||
|
||||
protected ContentTypePropertyContainerModel ContentTypePropertyContainerModel(
|
||||
string name = "Container",
|
||||
string type = TabContainerType,
|
||||
Guid? key = null)
|
||||
=> CreateContainer<ContentTypePropertyContainerModel>(name, type, key);
|
||||
|
||||
protected MediaTypePropertyContainerModel MediaTypePropertyContainerModel(
|
||||
string name = "Container",
|
||||
string type = TabContainerType,
|
||||
Guid? key = null)
|
||||
=> CreateContainer<MediaTypePropertyContainerModel>(name, type, key);
|
||||
|
||||
private TModel CreateContentEditingModel<TModel, TPropertyType, TPropertyTypeContainer>(
|
||||
string name,
|
||||
string? alias = null,
|
||||
bool isElement = false,
|
||||
IEnumerable<TPropertyType>? propertyTypes = null,
|
||||
IEnumerable<TPropertyTypeContainer>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null)
|
||||
where TModel : ContentTypeEditingModelBase<TPropertyType, TPropertyTypeContainer>, new()
|
||||
where TPropertyType : PropertyTypeModelBase
|
||||
where TPropertyTypeContainer : PropertyTypeContainerModelBase
|
||||
=> new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Properties = propertyTypes ?? Enumerable.Empty<TPropertyType>(),
|
||||
Containers = containers ?? Enumerable.Empty<TPropertyTypeContainer>(),
|
||||
Compositions = compositions ?? Enumerable.Empty<Composition>(),
|
||||
IsElement = isElement
|
||||
};
|
||||
|
||||
private TModel CreatePropertyType<TModel>(
|
||||
string name,
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
Guid? containerKey = null,
|
||||
Guid? dataTypeKey = null)
|
||||
where TModel : PropertyTypeModelBase, new()
|
||||
=> new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
ContainerKey = containerKey,
|
||||
DataTypeKey = dataTypeKey ?? Constants.DataTypes.Guids.TextstringGuid,
|
||||
Validation = new PropertyTypeValidation(),
|
||||
Appearance = new PropertyTypeAppearance(),
|
||||
};
|
||||
|
||||
private TModel CreateContainer<TModel>(
|
||||
string name,
|
||||
string type = TabContainerType,
|
||||
Guid? key = null)
|
||||
where TModel : PropertyTypeContainerModelBase, new()
|
||||
=> new()
|
||||
{
|
||||
Name = name,
|
||||
Type = type,
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
@@ -9,7 +10,7 @@ public partial class MediaTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Create_With_All_Basic_Settings()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test Media Type", "testMediaType");
|
||||
var createModel = MediaTypeCreateModel("Test Media Type", "testMediaType");
|
||||
createModel.Description = "This is the Test description";
|
||||
createModel.Icon = "icon icon-something";
|
||||
createModel.AllowedAsRoot = true;
|
||||
@@ -40,7 +41,7 @@ public partial class MediaTypeEditingServiceTests
|
||||
var container = containerResult.Result?.Entity;
|
||||
Assert.IsNotNull(container);
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test", parentKey: container.Key);
|
||||
var createModel = MediaTypeCreateModel("Test", "test", containerKey: container.Key);
|
||||
var result = await MediaTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(result.Success);
|
||||
|
||||
@@ -53,11 +54,11 @@ public partial class MediaTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Create_With_Properties_In_A_Container()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var container = CreateContainer();
|
||||
var createModel = MediaTypeCreateModel("Test", "test");
|
||||
var container = MediaTypePropertyContainerModel();
|
||||
createModel.Containers = new[] { container };
|
||||
|
||||
var propertyType = CreatePropertyType(name: "Test Property", alias: "testProperty", containerKey: container.Key);
|
||||
var propertyType = MediaTypePropertyTypeModel(name: "Test Property", alias: "testProperty", containerKey: container.Key);
|
||||
createModel.Properties = new[] { propertyType };
|
||||
|
||||
var result = await MediaTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
@@ -78,15 +79,15 @@ public partial class MediaTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Create_As_Child()
|
||||
{
|
||||
var parentProperty = CreatePropertyType("Parent Property", "parentProperty");
|
||||
var parentModel = CreateCreateModel(
|
||||
var parentProperty = MediaTypePropertyTypeModel("Parent Property", "parentProperty");
|
||||
var parentModel = MediaTypeCreateModel(
|
||||
name: "Parent",
|
||||
propertyTypes: new[] { parentProperty });
|
||||
|
||||
var parentResult = await MediaTypeEditingService.CreateAsync(parentModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(parentResult.Success);
|
||||
|
||||
var childProperty = CreatePropertyType("Child Property", "childProperty");
|
||||
var childProperty = MediaTypePropertyTypeModel("Child Property", "childProperty");
|
||||
var parentKey = parentResult.Result!.Key;
|
||||
Composition[] composition =
|
||||
{
|
||||
@@ -96,7 +97,7 @@ public partial class MediaTypeEditingServiceTests
|
||||
},
|
||||
};
|
||||
|
||||
var childModel = CreateCreateModel(
|
||||
var childModel = MediaTypeCreateModel(
|
||||
name: "Child",
|
||||
propertyTypes: new[] { childProperty },
|
||||
compositions: composition);
|
||||
@@ -114,4 +115,72 @@ public partial class MediaTypeEditingServiceTests
|
||||
Assert.IsTrue(mediaType.CompositionPropertyTypes.Any(x => x.Alias == parentProperty.Alias));
|
||||
Assert.IsTrue(mediaType.CompositionPropertyTypes.Any(x => x.Alias == childProperty.Alias));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Create_Composite()
|
||||
{
|
||||
var compositionBase = MediaTypeCreateModel("Composition Base");
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var container = MediaTypePropertyContainerModel();
|
||||
compositionBase.Containers = new[] { container };
|
||||
|
||||
var compositionProperty = MediaTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: container.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await MediaTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(compositionResult.Success);
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create media type using the composition
|
||||
var createModel = MediaTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
}
|
||||
);
|
||||
|
||||
var result = await MediaTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(result.Success);
|
||||
var mediaType = await MediaTypeService.GetAsync(result.Result!.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(1, mediaType.ContentTypeComposition.Count());
|
||||
Assert.AreEqual(compositionType.Key, mediaType.ContentTypeComposition.First().Key);
|
||||
Assert.AreEqual(1, compositionType.CompositionPropertyGroups.Count());
|
||||
Assert.AreEqual(container.Key, compositionType.CompositionPropertyGroups.First().Key);
|
||||
Assert.AreEqual(1, compositionType.CompositionPropertyTypes.Count());
|
||||
Assert.AreEqual(compositionProperty.Key, compositionType.CompositionPropertyTypes.First().Key);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Create_Composite_With_ContentType()
|
||||
{
|
||||
var compositionBase = ContentTypeCreateModel("Composition Base");
|
||||
|
||||
// Let's add a property to ensure that it passes through
|
||||
var container = ContentTypePropertyContainerModel();
|
||||
compositionBase.Containers = new[] { container };
|
||||
|
||||
var compositionProperty = ContentTypePropertyTypeModel("Composition Property", "compositionProperty", containerKey: container.Key);
|
||||
compositionBase.Properties = new[] { compositionProperty };
|
||||
|
||||
var compositionResult = await ContentTypeEditingService.CreateAsync(compositionBase, Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(compositionResult.Success);
|
||||
var compositionType = compositionResult.Result;
|
||||
|
||||
// Create media type using the composition
|
||||
var createModel = MediaTypeCreateModel(
|
||||
compositions: new[]
|
||||
{
|
||||
new Composition { CompositionType = CompositionType.Composition, Key = compositionType.Key, },
|
||||
}
|
||||
);
|
||||
|
||||
var result = await MediaTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
Assert.AreEqual(ContentTypeOperationStatus.InvalidComposition, result.Status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// These tests are enough to test that we are not mixing content and media types when looking for compositions,
|
||||
/// even though those share a base implementation.
|
||||
/// For a more detailed test suite on compositions, check <see cref="ContentTypeEditingServiceTests" />.
|
||||
/// </summary>
|
||||
public partial class MediaTypeEditingServiceTests
|
||||
{
|
||||
[Test]
|
||||
public async Task Can_Get_Available_Compositions_Only_From_Media_Type_Key()
|
||||
{
|
||||
var container1 = MediaTypePropertyContainerModel();
|
||||
var propertyType1 = MediaTypePropertyTypeModel("Property 1", "property1", containerKey: container1.Key);
|
||||
var mediaType1 = MediaTypeCreateModel(
|
||||
"Media type 1",
|
||||
"mediaType1",
|
||||
propertyTypes: new[] { propertyType1 },
|
||||
containers: new[] { container1 });
|
||||
|
||||
var result1 = await MediaTypeEditingService.CreateAsync(mediaType1, Constants.Security.SuperUserKey);
|
||||
|
||||
var container2 = MediaTypePropertyContainerModel();
|
||||
var propertyType2 = MediaTypePropertyTypeModel("Property 2", "property2", containerKey: container2.Key);
|
||||
var mediaType2 = MediaTypeCreateModel(
|
||||
"Media type 2",
|
||||
"mediaType2",
|
||||
propertyTypes: new[] { propertyType2 },
|
||||
containers: new[] { container2 });
|
||||
|
||||
var result2 = await MediaTypeEditingService.CreateAsync(mediaType2, Constants.Security.SuperUserKey);
|
||||
|
||||
var container3 = MediaTypePropertyContainerModel();
|
||||
var propertyType3 = MediaTypePropertyTypeModel("Property 3", "property3", containerKey: container3.Key);
|
||||
var mediaType3 = MediaTypeCreateModel(
|
||||
"Media type 3",
|
||||
"mediaType3",
|
||||
propertyTypes: new[] { propertyType3 },
|
||||
containers: new[] { container3 });
|
||||
|
||||
var result3 = await MediaTypeEditingService.CreateAsync(mediaType3, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await MediaTypeEditingService.GetAvailableCompositionsAsync(
|
||||
result1.Result!.Key,
|
||||
Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<string>());
|
||||
|
||||
// Verify that mediaType2 and mediaType3 are present in available compositions
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result2.Result!.Key && compositionsResult.Allowed));
|
||||
Assert.IsTrue(availableCompositions.Any(compositionsResult =>
|
||||
compositionsResult.Composition.Key == result3.Result!.Key && compositionsResult.Allowed));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Available_Compositions_For_Media_Type_Are_Not_Content_Types()
|
||||
{
|
||||
var container1 = MediaTypePropertyContainerModel();
|
||||
var propertyType1 = MediaTypePropertyTypeModel("Property 1", "property1", containerKey: container1.Key);
|
||||
var mediaType = MediaTypeCreateModel(
|
||||
"Media type",
|
||||
"mediaType",
|
||||
propertyTypes: new[] { propertyType1 },
|
||||
containers: new[] { container1 });
|
||||
|
||||
var result1 = await MediaTypeEditingService.CreateAsync(mediaType, Constants.Security.SuperUserKey);
|
||||
|
||||
var container2 = ContentTypePropertyContainerModel();
|
||||
var propertyType2 = ContentTypePropertyTypeModel("Property 2", "property2", containerKey: container2.Key);
|
||||
var contentType = ContentTypeCreateModel(
|
||||
"Content type",
|
||||
"contentType",
|
||||
propertyTypes: new[] { propertyType2 },
|
||||
containers: new[] { container2 });
|
||||
|
||||
var result2 = await ContentTypeEditingService.CreateAsync(contentType, Constants.Security.SuperUserKey);
|
||||
|
||||
IEnumerable<ContentTypeAvailableCompositionsResult> availableCompositions =
|
||||
await MediaTypeEditingService.GetAvailableCompositionsAsync(
|
||||
result1.Result!.Key,
|
||||
Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<string>());
|
||||
|
||||
Assert.IsFalse(availableCompositions.Any(compositionsResult => compositionsResult.Composition.Key == result2.Result!.Key));
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@ public partial class MediaTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Update_All_Basic_Settings()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test Media Type", "testMediaType");
|
||||
var createModel = MediaTypeCreateModel("Test Media Type", "testMediaType");
|
||||
var mediaType = (await MediaTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test updated", "testUpdated");
|
||||
var updateModel = MediaTypeUpdateModel("Test updated", "testUpdated");
|
||||
updateModel.Description = "This is the Test description updated";
|
||||
updateModel.Icon = "icon icon-something-updated";
|
||||
updateModel.AllowedAsRoot = false;
|
||||
@@ -36,11 +36,11 @@ public partial class MediaTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Add_Allowed_Types()
|
||||
{
|
||||
var allowedOne = (await MediaTypeEditingService.CreateAsync(CreateCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await MediaTypeEditingService.CreateAsync(CreateCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedThree = (await MediaTypeEditingService.CreateAsync(CreateCreateModel("Allowed Three", "allowedThree"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedOne = (await MediaTypeEditingService.CreateAsync(MediaTypeCreateModel("Allowed One", "allowedOne"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedTwo = (await MediaTypeEditingService.CreateAsync(MediaTypeCreateModel("Allowed Two", "allowedTwo"), Constants.Security.SuperUserKey)).Result!;
|
||||
var allowedThree = (await MediaTypeEditingService.CreateAsync(MediaTypeCreateModel("Allowed Three", "allowedThree"), Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var createModel = MediaTypeCreateModel("Test", "test");
|
||||
createModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedOne.Key, 10, allowedOne.Alias),
|
||||
@@ -48,7 +48,7 @@ public partial class MediaTypeEditingServiceTests
|
||||
};
|
||||
var mediaType = (await MediaTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
var updateModel = MediaTypeUpdateModel("Test", "test");
|
||||
updateModel.AllowedContentTypes = new[]
|
||||
{
|
||||
new ContentTypeSort(allowedTwo.Key, 20, allowedTwo.Alias),
|
||||
@@ -72,19 +72,19 @@ public partial class MediaTypeEditingServiceTests
|
||||
[Test]
|
||||
public async Task Can_Edit_Properties()
|
||||
{
|
||||
var createModel = CreateCreateModel("Test", "test");
|
||||
var propertyType = CreatePropertyType("Test Property", "testProperty");
|
||||
var createModel = MediaTypeCreateModel("Test", "test");
|
||||
var propertyType = MediaTypePropertyTypeModel("Test Property", "testProperty");
|
||||
propertyType.Description = "The description";
|
||||
createModel.Properties = new[] { propertyType };
|
||||
|
||||
var mediaType = (await MediaTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey)).Result!;
|
||||
var originalPropertyTypeKey = mediaType.PropertyTypes.First().Key;
|
||||
|
||||
var updateModel = CreateUpdateModel("Test", "test");
|
||||
propertyType = CreatePropertyType("Test Property Updated", "testProperty", key: originalPropertyTypeKey);
|
||||
var updateModel = MediaTypeUpdateModel("Test", "test");
|
||||
propertyType = MediaTypePropertyTypeModel("Test Property Updated", "testProperty", key: originalPropertyTypeKey);
|
||||
propertyType.Description = "The updated description";
|
||||
propertyType.SortOrder = 10;
|
||||
var propertyType2 = CreatePropertyType("Test Property 2", "testProperty2");
|
||||
var propertyType2 = MediaTypePropertyTypeModel("Test Property 2", "testProperty2");
|
||||
propertyType2.Description = "The description 2";
|
||||
propertyType2.SortOrder = 5;
|
||||
updateModel.Properties = new[] { propertyType, propertyType2 };
|
||||
|
||||
@@ -1,92 +1,9 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
using PropertyTypeValidation = Umbraco.Cms.Core.Models.ContentTypeEditing.PropertyTypeValidation;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the media type editing service. Please notice that a lot of functional test is covered by the content type
|
||||
/// editing service tests, since these services share the same base implementation.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[UmbracoTest(
|
||||
Database = UmbracoTestOptions.Database.NewSchemaPerTest,
|
||||
PublishedRepositoryEvents = true,
|
||||
WithApplication = true)]
|
||||
public partial class MediaTypeEditingServiceTests : UmbracoIntegrationTest
|
||||
public partial class MediaTypeEditingServiceTests : ContentTypeEditingServiceTestsBase
|
||||
{
|
||||
private IMediaTypeEditingService MediaTypeEditingService => GetRequiredService<IMediaTypeEditingService>();
|
||||
|
||||
private IMediaTypeService MediaTypeService => GetRequiredService<IMediaTypeService>();
|
||||
|
||||
private const string TabContainerType = "Tab";
|
||||
|
||||
private const string GroupContainerType = "Group";
|
||||
|
||||
private MediaTypeCreateModel CreateCreateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
Guid? parentKey = null,
|
||||
IEnumerable<MediaTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<MediaTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
ParentKey = parentKey,
|
||||
Properties = propertyTypes ?? Enumerable.Empty<MediaTypePropertyTypeModel>(),
|
||||
Containers = containers ?? Enumerable.Empty<MediaTypePropertyContainerModel>(),
|
||||
Compositions = compositions ?? Enumerable.Empty<Composition>(),
|
||||
};
|
||||
|
||||
private MediaTypeUpdateModel CreateUpdateModel(
|
||||
string name = "Test",
|
||||
string? alias = null,
|
||||
IEnumerable<MediaTypePropertyTypeModel>? propertyTypes = null,
|
||||
IEnumerable<MediaTypePropertyContainerModel>? containers = null,
|
||||
IEnumerable<Composition>? compositions = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Properties = propertyTypes ?? Enumerable.Empty<MediaTypePropertyTypeModel>(),
|
||||
Containers = containers ?? Enumerable.Empty<MediaTypePropertyContainerModel>(),
|
||||
Compositions = compositions ?? Enumerable.Empty<Composition>()
|
||||
};
|
||||
|
||||
private MediaTypePropertyTypeModel CreatePropertyType(
|
||||
string name = "Title",
|
||||
string? alias = null,
|
||||
Guid? key = null,
|
||||
Guid? containerKey = null,
|
||||
Guid? dataTypeKey = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Alias = alias ?? ShortStringHelper.CleanStringForSafeAlias(name),
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
ContainerKey = containerKey,
|
||||
DataTypeKey = dataTypeKey ?? Constants.DataTypes.Guids.TextstringGuid,
|
||||
Validation = new PropertyTypeValidation(),
|
||||
Appearance = new PropertyTypeAppearance(),
|
||||
};
|
||||
|
||||
private MediaTypePropertyContainerModel CreateContainer(
|
||||
string name = "Container",
|
||||
string type = TabContainerType,
|
||||
Guid? key = null) =>
|
||||
new()
|
||||
{
|
||||
Name = name,
|
||||
Type = type,
|
||||
Key = key ?? Guid.NewGuid(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user