Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentListViewServiceTestsBase.cs
Elitsa Marinovska c8180d508b V14: Test new content and media list view service (#16193)
* Fix operation status msg

* Cleanup

* Removing unused status

* Adding WithConfigurationEditor on DataEditorBuilder to be able to create new list views with custom configuration

* Adding list view service tests for content and media

* Adding list view service tests base

* Consistency

* Clean up

* More cleanup

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2024-05-01 10:54:26 +02:00

54 lines
2.1 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public abstract class ContentListViewServiceTestsBase : UmbracoIntegrationTest
{
protected IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
protected IUserGroupService UserGroupService => GetRequiredService<IUserGroupService>();
protected IUserService UserService => GetRequiredService<IUserService>();
protected async Task<IUser> GetSuperUser()
=> await UserService.GetAsync(Constants.Security.SuperUserKey);
protected async Task AssertListViewConfiguration(ListViewConfiguration actualConfiguration, Guid expectedListViewDataTypeKey)
{
var actualCollectionPropertyAliases = actualConfiguration
.IncludeProperties
.Select(p => p.Alias)
.WhereNotNull()
.ToArray();
// The configured list view
var expectedContentListViewConfig = await GetListViewConfigurationFromListViewDataType(expectedListViewDataTypeKey);
var expectedCollectionPropertyAliases = expectedContentListViewConfig
.IncludeProperties
.Select(p => p.Alias)
.WhereNotNull()
.ToArray();
Assert.AreEqual(expectedCollectionPropertyAliases.Length, actualCollectionPropertyAliases.Length);
Assert.IsTrue(expectedCollectionPropertyAliases.SequenceEqual(actualCollectionPropertyAliases));
}
private async Task<ListViewConfiguration> GetListViewConfigurationFromListViewDataType(Guid dataTypeKey)
{
IDataType? dataType = await DataTypeService.GetAsync(dataTypeKey);
var listViewConfiguration = dataType.ConfigurationObject;
Assert.IsTrue(listViewConfiguration is ListViewConfiguration);
return listViewConfiguration as ListViewConfiguration;
}
}