Browse Source

Improve MarkedItems module based on review feedback

- Refactor CmsKitMarkedItemOptions to prevent duplicate entity type definitions
- Enhance exception handling in DefaultMarkedItemDefinitionStore
- Remove redundant GetAsync method from MarkedItemManager
- Remove IQueryable exposure from IUserMarkedItemRepository
- Align EntityTagRepository approach with other repositories
- Rename GetForToggleAsync to GetAsync or GetForUserAsync in IMarkedItemPublicAppService

These changes improve code clarity, consistency, and adherence to ABP.io best practices.
pull/20056/head
Suhaib 2 years ago
parent
commit
0cd0761cf5
  1. 25
      docs/en/Modules/Cms-Kit/MarkedItems.md
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs
  3. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ar.json
  4. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json
  5. 16
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DefaultMarkedItemDefinitionStore.cs
  6. 16
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DuplicateMarkedItemDefinitionException.cs
  7. 5
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/IUserMarkedItemRepository.cs
  8. 16
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemDefinitionNotFoundException.cs
  9. 10
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemManager.cs
  10. 23
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/MarkedItems/EfCoreUserMarkedItemRepository.cs
  11. 24
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs
  12. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs
  13. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicAppService.cs
  14. 2
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs
  15. 4
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicClientProxy.Generated.cs
  16. 8
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json
  17. 4
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicController.cs
  18. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/MarkedItemToggle/MarkedItemToggleViewComponent.cs
  19. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/wwwroot/client-proxies/cms-kit-proxy.js
  20. 4
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/MarkedItems/MarkedItemPublicAppService_Tests.cs
  21. 13
      modules/cms-kit/test/Volo.CmsKit.Domain.Tests/MarkedItems/MarkedItemManager_Tests.cs
  22. 4
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs
  23. 19
      modules/cms-kit/test/Volo.CmsKit.TestBase/MarkedItems/UserMarkedItemRepository_Tests.cs

25
docs/en/Modules/Cms-Kit/MarkedItems.md

@ -58,31 +58,6 @@ The marking system provides a toggle widget to allow users to add/remove the mar
* `entityId` should be the unique id of the product, in this example. If you have a Product entity, you can use its Id here.
* `needsConfirmation` An optional parameter to let the user confirm when removing the mark.
# Filter on marked items
Filtering on marked items enhances the user experience by making it easier to search marked items.
![markedItemsFilter](../../images/cmskit-module-markedItemsFilter.gif)
There is an ability to utilize the marking system to let users filter on their marked items. The code below shows how you can filter on your query filter:
```csharp
protected async override Task<IQueryable<YourEntity>> CreateFilteredQueryAsync(YourEntityPagedAndSortedResultDto input)
{
IQueryable<YourEntity> query = await base.CreateFilteredQueryAsync(input);
if (input.FilterOnFavorites && CurrentUser.IsAuthenticated)
{
var markedQuery = await UserMarkedItemRepository.GetQueryForUserAsync("entityType", CurrentUser.GetId());
query = query.Where(e => markedQuery.Any(m => m.EntityId == e.Id));
}
// ...
return query;
}
```
# Internals
## Domain Layer

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs

@ -48,5 +48,7 @@ public static class CmsKitErrorCodes
public static class MarkedItems
{
public const string EntityCannotBeMarked = "CmsKit:MarkedItem:0001";
public const string MarkedItemDefinitionNotFound = "CmsKit:MarkedItem:0002";
public const string DuplicateMarkedItem = "CmsKit:MarkedItem:0003";
}
}

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ar.json

@ -26,6 +26,8 @@
"CmsKit:Rating:0001": "لا يمكن تصنيف الكيان {EntityType}.",
"CmsKit:Reaction:0001": "لا يمكن أن يحتوي الكيان {EntityType} على ردود أفعال.",
"CmsKit:MarkedItem:0001": "لا يمكن أن تمييز الكيان {EntityType}.",
"CmsKit:MarkedItem:0002": "لم يتم العثور على تعريف لنوع الكيان '{EntityType}'.",
"CmsKit:MarkedItem:0003": "يوجد بالفعل تعريف لنوع الكيان '{EntityType}'. يجب أن يكون لكل نوع كيان تعريف واحد فقط.",
"CmsKit:Tag:0002": "الكيان غير قابل للوسم!",
"CommentAuthorizationExceptionMessage": "هذه التعليقات غير مسموح بها للعرض العام.",
"CommentDeletionConfirmationMessage": "سيتم حذف هذا التعليق وجميع الردود!",

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json

@ -33,6 +33,8 @@
"CmsKit:Modals:YouAreNotAuthenticated": "This operation is not authorized for you.",
"CommentDeletionConfirmationMessage": "This comment and all replies will be deleted!",
"CmsKit:MarkedItem:0001": "The entity {EntityType} can't be marked.",
"CmsKit:MarkedItem:0002": "No definition found for entity type '{EntityType}'.",
"CmsKit:MarkedItem:0003": "A definition for entity type '{EntityType}' already exists. Each entity type should have only one definition.",
"CmsKit:MarkedItem:LoginMessage": "Please login to mark this item.",
"Comments": "Comments",
"Content": "Content",

16
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DefaultMarkedItemDefinitionStore.cs

@ -29,8 +29,20 @@ public class DefaultMarkedItemDefinitionStore : IMarkedItemDefinitionStore
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
var definition = Options.EntityTypes.SingleOrDefault(x => x.EntityType.Equals(entityType, StringComparison.InvariantCultureIgnoreCase));
var definitions = Options.EntityTypes
.Where(x => x.EntityType.Equals(entityType, StringComparison.InvariantCultureIgnoreCase))
.ToList();
return Task.FromResult(definition);
if (definitions.Count == 0)
{
throw new MarkedItemDefinitionNotFoundException(entityType);
}
if (definitions.Count > 1)
{
throw new DuplicateMarkedItemDefinitionException(entityType);
}
return Task.FromResult(definitions.Single());
}
}

16
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/DuplicateMarkedItemDefinitionException.cs

@ -0,0 +1,16 @@
using JetBrains.Annotations;
using Volo.Abp;
namespace Volo.CmsKit.MarkedItems;
public class DuplicateMarkedItemDefinitionException : BusinessException
{
public DuplicateMarkedItemDefinitionException([NotNull] string entityType)
{
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType));
Code = CmsKitErrorCodes.MarkedItems.DuplicateMarkedItem;
WithData(nameof(EntityType), EntityType);
}
public string EntityType { get; }
}

5
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/IUserMarkedItemRepository.cs

@ -23,9 +23,10 @@ public interface IUserMarkedItemRepository : IBasicRepository<UserMarkedItem, Gu
CancellationToken cancellationToken = default
);
Task<IQueryable<UserMarkedItem>> GetQueryForUserAsync(
[NotNull] string entityType,
Task<List<string>> GetEntityIdsFilteredByUserAsync(
[NotNull] Guid userId,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId = null,
CancellationToken cancellationToken = default
);
}

16
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemDefinitionNotFoundException.cs

@ -0,0 +1,16 @@
using JetBrains.Annotations;
using Volo.Abp;
namespace Volo.CmsKit.MarkedItems;
public class MarkedItemDefinitionNotFoundException : BusinessException
{
public MarkedItemDefinitionNotFoundException([NotNull] string entityType)
{
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType));
Code = CmsKitErrorCodes.MarkedItems.MarkedItemDefinitionNotFound;
WithData(nameof(EntityType), EntityType);
}
public string EntityType { get; }
}

10
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/MarkedItems/MarkedItemManager.cs

@ -18,7 +18,7 @@ public class MarkedItemManager : CmsKitDomainServiceBase
MarkedItemDefinitionStore = markedItemDefinitionStore;
}
public virtual async Task<bool> ToggleAsync(
public virtual async Task<bool> ToggleUserMarkedItemAsync(
Guid creatorId,
[NotNull] string entityType,
[NotNull] string entityId)
@ -49,12 +49,4 @@ public class MarkedItemManager : CmsKitDomainServiceBase
);
return true;
}
public virtual async Task<MarkedItemEntityTypeDefinition> GetAsync(
[NotNull] string entityType)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
return await MarkedItemDefinitionStore.GetAsync(entityType);
}
}

23
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/MarkedItems/EfCoreUserMarkedItemRepository.cs

@ -45,23 +45,18 @@ public class EfCoreUserMarkedItemRepository : EfCoreRepository<ICmsKitDbContext,
.ToListAsync(GetCancellationToken(cancellationToken));
}
/// <summary>
/// Retrieves an IQueryable representing the user's marked items based on the specified entity type and user ID.
/// </summary>
/// <param name="entityType">The type of entity to filter by.</param>
/// <param name="userId">The ID of the user whose marked items are being retrieved.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>An IQueryable representing the user's marked items filtered by the specified entity type and user ID.</returns>
public async Task<IQueryable<UserMarkedItem>> GetQueryForUserAsync([NotNull] string entityType, [NotNull] Guid userId, CancellationToken cancellationToken = default)
public async Task<List<string>> GetEntityIdsFilteredByUserAsync([NotNull] Guid userId, [NotNull] string entityType, [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNull(userId, nameof(userId));
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
var dbSet = await GetDbSetAsync();
var query = dbSet
.Where(x => x.EntityType == entityType && x.CreatorId == userId);
var dbContext = await GetDbContextAsync();
var result = from umi in dbContext.Set<UserMarkedItem>()
where umi.CreatorId == userId
&& umi.EntityType == entityType
&& umi.TenantId == tenantId
select umi.EntityId;
return query;
return await result.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
}
}

24
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/MarkedItems/MongoUserMarkedItemRepository.cs

@ -46,22 +46,18 @@ public class MongoUserMarkedItemRepository : MongoDbRepository<ICmsKitMongoDbCon
.ToListAsync(GetCancellationToken(cancellationToken));
}
/// <summary>
/// Retrieves an IQueryable representing the user's marked items based on the specified entity type and user ID.
/// </summary>
/// <param name="entityType">The type of entity to filter by.</param>
/// <param name="userId">The ID of the user whose marked items are being retrieved.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>An IQueryable representing the user's marked items filtered by the specified entity type and user ID.</returns>
public virtual async Task<IQueryable<UserMarkedItem>> GetQueryForUserAsync([NotNull] string entityType, [NotNull] Guid userId, CancellationToken cancellationToken = default)
public virtual async Task<List<string>> GetEntityIdsFilteredByUserAsync([NotNull] Guid userId, [NotNull] string entityType, [CanBeNull] Guid? tenantId = null, CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNull(userId, nameof(userId));
var dbContext = await GetDbContextAsync();
var userMarkedItemQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken));
var queryable = await GetMongoQueryableAsync(cancellationToken);
var query = queryable
.Where(x => x.EntityType == entityType && x.CreatorId == userId);
var resultQueryable = userMarkedItemQueryable
.Where(x => x.CreatorId == userId
&& x.EntityType == entityType
&& x.TenantId == tenantId
)
.Select(s => s.EntityId);
return query;
return await AsyncExecuter.ToListAsync(resultQueryable, GetCancellationToken(cancellationToken));
}
}

2
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs

@ -5,6 +5,6 @@ namespace Volo.CmsKit.Public.MarkedItems;
public interface IMarkedItemPublicAppService : IApplicationService
{
Task<MarkedItemWithToggleDto> GetForToggleAsync(string entityType, string entityId);
Task<MarkedItemWithToggleDto> GetForUserAsync(string entityType, string entityId);
Task<bool> ToggleAsync(string entityType, string entityId);
}

6
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicAppService.cs

@ -30,9 +30,9 @@ public class MarkedItemPublicAppService : CmsKitPublicAppServiceBase, IMarkedIte
}
[AllowAnonymous]
public virtual async Task<MarkedItemWithToggleDto> GetForToggleAsync(string entityType, string entityId)
public virtual async Task<MarkedItemWithToggleDto> GetForUserAsync(string entityType, string entityId)
{
var markedItem = await MarkedItemManager.GetAsync(entityType);
var markedItem = await MarkedItemDefinitionStore.GetAsync(entityType);
var userMarkedItem = CurrentUser.IsAuthenticated
? (await UserMarkedItemRepository
@ -53,7 +53,7 @@ public class MarkedItemPublicAppService : CmsKitPublicAppServiceBase, IMarkedIte
[Authorize]
public virtual async Task<bool> ToggleAsync(string entityType, string entityId)
{
return await MarkedItemManager.ToggleAsync(
return await MarkedItemManager.ToggleUserMarkedItemAsync(
CurrentUser.GetId(),
entityType,
entityId

2
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/IMarkedItemPublicAppService.cs

@ -12,7 +12,7 @@ namespace Volo.CmsKit.Public.MarkedItems;
public interface IMarkedItemPublicAppService : IApplicationService
{
Task<MarkedItemWithToggleDto> GetForToggleAsync(string entityType, string entityId);
Task<MarkedItemWithToggleDto> GetForUserAsync(string entityType, string entityId);
Task<bool> ToggleAsync(string entityType, string entityId);
}

4
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicClientProxy.Generated.cs

@ -17,9 +17,9 @@ namespace Volo.CmsKit.Public.MarkedItems;
[ExposeServices(typeof(IMarkedItemPublicAppService), typeof(MarkedItemPublicClientProxy))]
public partial class MarkedItemPublicClientProxy : ClientProxyBase<IMarkedItemPublicAppService>, IMarkedItemPublicAppService
{
public virtual async Task<MarkedItemWithToggleDto> GetForToggleAsync(string entityType, string entityId)
public virtual async Task<MarkedItemWithToggleDto> GetForUserAsync(string entityType, string entityId)
{
return await RequestAsync<MarkedItemWithToggleDto>(nameof(GetForToggleAsync), new ClientProxyRequestTypeValue
return await RequestAsync<MarkedItemWithToggleDto>(nameof(GetForUserAsync), new ClientProxyRequestTypeValue
{
{ typeof(string), entityType },
{ typeof(string), entityId }

8
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json

@ -921,7 +921,7 @@
"name": "IMarkedItemPublicAppService",
"methods": [
{
"name": "GetForToggleAsync",
"name": "GetForUserAsync",
"parametersOnMethod": [
{
"name": "entityType",
@ -974,9 +974,9 @@
}
],
"actions": {
"GetForToggleAsyncByEntityTypeAndEntityId": {
"uniqueName": "GetForToggleAsyncByEntityTypeAndEntityId",
"name": "GetForToggleAsync",
"GetForUserAsyncByEntityTypeAndEntityId": {
"uniqueName": "GetForUserAsyncByEntityTypeAndEntityId",
"name": "GetForUserAsync",
"httpMethod": "GET",
"url": "api/cms-kit-public/marked-items/{entityType}/{entityId}",
"supportedVersions": [],

4
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/MarkedItems/MarkedItemPublicController.cs

@ -24,9 +24,9 @@ public class MarkedItemPublicController : CmsKitPublicControllerBase, IMarkedIte
[HttpGet]
[Route("{entityType}/{entityId}")]
public virtual Task<MarkedItemWithToggleDto> GetForToggleAsync(string entityType, string entityId)
public virtual Task<MarkedItemWithToggleDto> GetForUserAsync(string entityType, string entityId)
{
return MarkedItemPublicAppService.GetForToggleAsync(entityType, entityId);
return MarkedItemPublicAppService.GetForUserAsync(entityType, entityId);
}
[HttpPut]

2
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/MarkedItemToggle/MarkedItemToggleViewComponent.cs

@ -36,7 +36,7 @@ public class MarkedItemToggleViewComponent : AbpViewComponent
string entityId,
bool? needsConfirmation = false)
{
var result = await MarkedItemPublicAppService.GetForToggleAsync(entityType, entityId);
var result = await MarkedItemPublicAppService.GetForUserAsync(entityType, entityId);
var returnUrl = HttpContext.Request.Path.ToString();
var viewModel = new MarkedItemToggleViewModel

2
modules/cms-kit/src/Volo.CmsKit.Public.Web/wwwroot/client-proxies/cms-kit-proxy.js

@ -123,7 +123,7 @@
abp.utils.createNamespace(window, 'volo.cmsKit.public.markedItems.markedItemPublic');
volo.cmsKit.public.markedItems.markedItemPublic.getForToggle = function(entityType, entityId, ajaxParams) {
volo.cmsKit.public.markedItems.markedItemPublic.getForUser = function(entityType, entityId, ajaxParams) {
return abp.ajax($.extend(true, {
url: abp.appPath + 'api/cms-kit-public/marked-items/' + entityType + '/' + entityId + '',
type: 'GET'

4
modules/cms-kit/test/Volo.CmsKit.Application.Tests/MarkedItems/MarkedItemPublicAppService_Tests.cs

@ -32,11 +32,11 @@ public class MarkedItemPublicAppService_Tests : CmsKitApplicationTestBase
_currentUser.Id.Returns(_cmsKitTestData.User1Id);
_currentUser.IsAuthenticated.Returns(true);
var firstMarkedItem = await _markedItemPublicAppService.GetForToggleAsync(
var firstMarkedItem = await _markedItemPublicAppService.GetForUserAsync(
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1
);
var secondMarkedItem = await _markedItemPublicAppService.GetForToggleAsync(
var secondMarkedItem = await _markedItemPublicAppService.GetForUserAsync(
_cmsKitTestData.EntityType2,
_cmsKitTestData.EntityId1
);

13
modules/cms-kit/test/Volo.CmsKit.Domain.Tests/MarkedItems/MarkedItemManager_Tests.cs

@ -18,13 +18,13 @@ public class MarkedItemManager_Tests : CmsKitDomainTestBase
[Fact]
public async Task ToggleAsync()
{
var firstToggleResult = await _markedItemManager.ToggleAsync(
var firstToggleResult = await _markedItemManager.ToggleUserMarkedItemAsync(
_cmsKitTestData.User1Id,
_cmsKitTestData.EntityType2,
_cmsKitTestData.EntityId1
);
var secondToggleResult = await _markedItemManager.ToggleAsync(
var secondToggleResult = await _markedItemManager.ToggleUserMarkedItemAsync(
_cmsKitTestData.User1Id,
_cmsKitTestData.EntityType2,
_cmsKitTestData.EntityId1
@ -33,13 +33,4 @@ public class MarkedItemManager_Tests : CmsKitDomainTestBase
firstToggleResult.ShouldBeTrue();
secondToggleResult.ShouldBeFalse();
}
[Fact]
public async Task GetAsync()
{
var markedItem = await _markedItemManager.GetAsync(_cmsKitTestData.EntityType1);
markedItem.EntityType.ShouldBe(_cmsKitTestData.EntityType1);
markedItem.IconName.ShouldBe(StandardMarkedItems.Favorite);
}
}

4
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs

@ -457,12 +457,12 @@ public class CmsKitDataSeedContributor : IDataSeedContributor, ITransientDepende
private async Task SeedMarkedItemsAsync()
{
await _markedItemManager.ToggleAsync(
await _markedItemManager.ToggleUserMarkedItemAsync(
_cmsKitTestData.User1Id,
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1
);
await _markedItemManager.ToggleAsync(
await _markedItemManager.ToggleUserMarkedItemAsync(
_cmsKitTestData.User1Id,
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId2

19
modules/cms-kit/test/Volo.CmsKit.TestBase/MarkedItems/UserMarkedItemRepository_Tests.cs

@ -43,22 +43,15 @@ public abstract class UserMarkedItemRepository_Tests<TStartupModule> : CmsKitTes
markedItems.Count.ShouldBe(2);
}
[Fact]
public async Task GetQueryForUserAsync()
public async Task GetEntityIdsFilteredByUserAsync()
{
await WithUnitOfWorkAsync(async () =>
{
var query = await _userMarkedItemRepository.GetQueryForUserAsync(
_cmsKitTestData.EntityType1,
_cmsKitTestData.User1Id
);
var entityIds = await _userMarkedItemRepository.GetEntityIdsFilteredByUserAsync(_cmsKitTestData.User1Id, _cmsKitTestData.EntityType1);
var markedItems = query.ToList();
entityIds.ShouldNotBeNull();
entityIds.ShouldNotBeEmpty();
markedItems.Count.ShouldBe(2);
markedItems.All(x => x.CreatorId == _cmsKitTestData.User1Id).ShouldBeTrue();
markedItems.All(x => x.EntityType == _cmsKitTestData.EntityType1).ShouldBeTrue();
});
entityIds.Count.ShouldBe(2);
}
}

Loading…
Cancel
Save