Browse Source

CmsKit: enhancement after reviewing

pull/5216/head
EngincanV 6 years ago
parent
commit
e0c46f9434
  1. 1
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs
  2. 4
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Ratings/RatingConsts.cs
  3. 6
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Ratings/IRatingRepository.cs
  4. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Ratings/Rating.cs
  5. 2
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs
  6. 12
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs
  7. 12
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs
  8. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/CreateUpdateRatingInput.cs
  9. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/IRatingPublicAppService.cs
  10. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/RatingWithStarCountDto.cs
  11. 10
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/UpdateRatingInput.cs
  12. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs
  13. 69
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Ratings/RatingPublicAppService.cs
  14. 26
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Ratings/RatingPublicController.cs
  15. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/Default.cshtml
  16. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/RatingViewComponent.cs
  17. 100
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js
  18. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Volo.CmsKit.Public.Web.csproj
  19. 70
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Ratings/RatingPublicAppService_Tests.cs
  20. 8
      modules/cms-kit/test/Volo.CmsKit.TestBase/Ratings/RatingRepository_Tests.cs

1
modules/cms-kit/host/Volo.CmsKit.Web.Unified/CmsKitWebUnifiedModule.cs

@ -1,4 +1,5 @@
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

4
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Ratings/RatingConsts.cs

@ -7,5 +7,9 @@ namespace Volo.CmsKit.Ratings
public static int MaxEntityTypeLength { get; set; } = CmsEntityConsts.MaxEntityTypeLength;
public static int MaxEntityIdLength { get; set; } = CmsEntityConsts.MaxEntityIdLength;
public static int MaxRating { get; set; } = 5;
public static int MinRating { get; set; } = 0;
}
}

6
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Ratings/IRatingRepository.cs

@ -9,12 +9,6 @@ namespace Volo.CmsKit.Ratings
{
public interface IRatingRepository : IBasicRepository<Rating, Guid>
{
Task<List<Rating>> GetListAsync(
[NotNull] string entityType,
[NotNull] string entityId,
CancellationToken cancellationToken = default
);
Task<Rating> GetCurrentUserRatingAsync(
[NotNull] string entityType,
[NotNull] string entityId,

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Ratings/Rating.cs

@ -44,7 +44,7 @@ namespace Volo.CmsKit.Ratings
public virtual void SetStarCount(short starCount)
{
if(starCount <= 5 && starCount > 0)
if(starCount <= RatingConsts.MaxRating && starCount > RatingConsts.MinRating)
{
StarCount = starCount;
}

2
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

@ -85,7 +85,7 @@ namespace Volo.CmsKit.EntityFrameworkCore
r.Property(x => x.EntityType).IsRequired().HasMaxLength(RatingConsts.MaxEntityTypeLength);
r.Property(x => x.EntityId).IsRequired().HasMaxLength(RatingConsts.MaxEntityIdLength);
r.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId});
r.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId, x.CreatorId});
});
}
}

12
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Ratings/EfCoreRatingRepository.cs

@ -18,18 +18,6 @@ namespace Volo.CmsKit.Ratings
{
}
public async Task<List<Rating>> GetListAsync(string entityType, string entityId,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = DbSet.Where(r => r.EntityType == entityType && r.EntityId == entityId);
var ratings = await query.ToListAsync(GetCancellationToken(cancellationToken));
return ratings;
}
public async Task<Rating> GetCurrentUserRatingAsync(string entityType, string entityId, Guid userId,
CancellationToken cancellationToken = default)
{

12
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Ratings/MongoRatingRepository.cs

@ -19,18 +19,6 @@ namespace Volo.CmsKit.MongoDB.Ratings
{
}
public async Task<List<Rating>> GetListAsync(string entityType, string entityId,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = GetMongoQueryable().Where(r => r.EntityType == entityType && r.EntityId == entityId);
var ratings = await query.ToListAsync(GetCancellationToken(cancellationToken));
return ratings;
}
public async Task<Rating> GetCurrentUserRatingAsync(string entityType, string entityId, Guid userId,
CancellationToken cancellationToken = default)
{

4
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/CreateRatingInput.cs → modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/CreateUpdateRatingInput.cs

@ -2,9 +2,9 @@
namespace Volo.CmsKit.Public.Ratings
{
public class CreateRatingInput
public class CreateUpdateRatingInput
{
[Required]
[Required, Range(1, 5)]
public short StarCount { get; set; }
}
}

8
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/IRatingPublicAppService.cs

@ -8,13 +8,9 @@ namespace Volo.CmsKit.Public.Ratings
{
public interface IRatingPublicAppService : IApplicationService
{
Task<ListResultDto<RatingDto>> GetListAsync(string entityType, string entityId);
Task<RatingDto> CreateAsync(string entityType, string entityId, CreateRatingInput input);
Task<RatingDto> UpdateAsync(Guid id, UpdateRatingInput input);
Task<RatingDto> CreateAsync(string entityType, string entityId, CreateUpdateRatingInput input);
Task DeleteAsync(Guid id);
Task DeleteAsync(string entityType, string entityId);
Task<RatingDto> GetCurrentUserRatingAsync(string entityType, string entityId);

2
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/RatingWithStarCountDto.cs

@ -5,5 +5,7 @@
public short StarCount { get; set; }
public int Count { get; set; }
public bool IsSelectedByCurrentUser { get; set; }
}
}

10
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Ratings/UpdateRatingInput.cs

@ -1,10 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Volo.CmsKit.Public.Ratings
{
public class UpdateRatingInput
{
[Required]
public short StarCount { get; set; }
}
}

2
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs

@ -22,8 +22,6 @@ namespace Volo.CmsKit.Public
.Ignore(x=> x.Author);
CreateMap<Rating, RatingDto>();
CreateMap<RatingWithStarCountQueryResultItem, RatingWithStarCountDto>();
}
}
}

69
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Ratings/RatingPublicAppService.cs

@ -22,18 +22,22 @@ namespace Volo.CmsKit.Public.Ratings
CmsUserLookupService = cmsUserLookupService;
}
public virtual async Task<ListResultDto<RatingDto>> GetListAsync(string entityType, string entityId)
[Authorize]
public virtual async Task<RatingDto> CreateAsync(string entityType, string entityId,
CreateUpdateRatingInput input)
{
var ratings = await RatingRepository.GetListAsync(entityType, entityId);
var ratingDto = ObjectMapper.Map<List<Rating>, List<RatingDto>>(ratings);
var userId = CurrentUser.GetId();
var user = await CmsUserLookupService.GetByIdAsync(userId);
return new ListResultDto<RatingDto>(ratingDto);
}
var currentUserRating = await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, userId);
[Authorize]
public virtual async Task<RatingDto> CreateAsync(string entityType, string entityId, CreateRatingInput input)
{
var user = await CmsUserLookupService.GetByIdAsync(CurrentUser.GetId());
if (currentUserRating != null)
{
currentUserRating.SetStarCount(input.StarCount);
var updatedRating = await RatingRepository.UpdateAsync(currentUserRating);
return ObjectMapper.Map<Rating, RatingDto>(updatedRating);
}
var rating = await RatingRepository.InsertAsync(
new Rating(
@ -50,50 +54,51 @@ namespace Volo.CmsKit.Public.Ratings
}
[Authorize]
public virtual async Task<RatingDto> UpdateAsync(Guid id, UpdateRatingInput input)
{
var rating = await RatingRepository.GetAsync(id);
if (rating.CreatorId != CurrentUser.GetId())
{
throw new AbpAuthorizationException();
}
rating.SetStarCount(input.StarCount);
var updatedRating = await RatingRepository.UpdateAsync(rating);
return ObjectMapper.Map<Rating, RatingDto>(updatedRating);
}
[Authorize]
public virtual async Task DeleteAsync(Guid id)
public virtual async Task DeleteAsync(string entityType, string entityId)
{
var rating = await RatingRepository.GetAsync(id);
var rating = await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, CurrentUser.GetId());
if (rating.CreatorId != CurrentUser.GetId())
{
throw new AbpAuthorizationException();
}
await RatingRepository.DeleteAsync(id);
await RatingRepository.DeleteAsync(rating.Id);
}
[Authorize]
public virtual async Task<RatingDto> GetCurrentUserRatingAsync(string entityType, string entityId)
{
var currentUserId = CurrentUser.GetId();
var rating = await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, currentUserId);
return ObjectMapper.Map<Rating, RatingDto>(rating);
}
public virtual async Task<List<RatingWithStarCountDto>> GetGroupedStarCountsAsync(string entityType, string entityId)
public virtual async Task<List<RatingWithStarCountDto>> GetGroupedStarCountsAsync(string entityType,
string entityId)
{
var ratings = await RatingRepository.GetGroupedStarCountsAsync(entityType, entityId);
return ObjectMapper.Map<List<RatingWithStarCountQueryResultItem>, List<RatingWithStarCountDto>>(ratings);
var userRatingOrNull = CurrentUser.IsAuthenticated
? await RatingRepository.GetCurrentUserRatingAsync(entityType, entityId, CurrentUser.GetId())
: null;
var ratingWithStarCountDto = new List<RatingWithStarCountDto>();
foreach (var rating in ratings)
{
ratingWithStarCountDto.Add(
new RatingWithStarCountDto
{
StarCount = rating.StarCount,
Count = rating.Count,
IsSelectedByCurrentUser = userRatingOrNull != null && userRatingOrNull.StarCount == rating.StarCount
});
}
return ratingWithStarCountDto;
}
}
}

26
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Ratings/RatingPublicController.cs

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.GlobalFeatures;
@ -22,32 +20,18 @@ namespace Volo.CmsKit.Public.Ratings
RatingPublicAppService = ratingPublicAppService;
}
[HttpGet]
[Route("{entityType}/{entityId}")]
public virtual Task<ListResultDto<RatingDto>> GetListAsync(string entityType, string entityId)
{
return RatingPublicAppService.GetListAsync(entityType, entityId);
}
[HttpPut]
[Route("{entityType}/{entityId}")]
public virtual Task<RatingDto> CreateAsync(string entityType, string entityId, CreateRatingInput input)
public virtual Task<RatingDto> CreateAsync(string entityType, string entityId, CreateUpdateRatingInput input)
{
return RatingPublicAppService.CreateAsync(entityType, entityId, input);
}
[HttpPut]
[Route("{id}")]
public virtual Task<RatingDto> UpdateAsync(Guid id, UpdateRatingInput input)
{
return RatingPublicAppService.UpdateAsync(id, input);
}
[HttpDelete]
[Route("{id}")]
public virtual Task DeleteAsync(Guid id)
[Route("{entityType}/{entityId}")]
public virtual Task DeleteAsync(string entityType, string entityId)
{
return RatingPublicAppService.DeleteAsync(id);
return RatingPublicAppService.DeleteAsync(entityType, entityId);
}
[HttpGet]

6
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/Default.cshtml

@ -9,11 +9,11 @@
@if (CurrentUser.IsAuthenticated)
{
<div class="m-auto">
<span class="my-rating-5" data-rating="@(Model.CurrentRating != null ? Model.CurrentRating.StarCount : 0)" data-authenticated="@(Model.CurrentRating != null)"></span>
<span class="live-rating">@(Model.CurrentRating != null ? Model.CurrentRating.StarCount + " | " : 0 + "")</span>
<span class="my-rating-5" data-rating="@(Model.CurrentRating ?? 0)" data-authenticated="@(Model.CurrentRating != null)"></span>
<span class="live-rating">@(Model.CurrentRating != null ? Model.CurrentRating + " | " : 0 + "")</span>
@if (Model.CurrentRating != null)
{
<a href="#" class="rating-undo-link m-auto" data-id="@Model.CurrentRating.Id">
<a href="#" class="rating-undo-link m-auto">
<i class="fa fa-undo"></i> @L["Undo"]
</a>
}

8
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/RatingViewComponent.cs

@ -34,11 +34,11 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating
{
var ratings = await RatingPublicAppService.GetGroupedStarCountsAsync(entityType, entityId);
var totalRating = ratings.Sum(x => x.Count);
RatingDto currentUserRating = null;
short? currentUserRating = null;
if (CurrentUser.IsAuthenticated)
{
currentUserRating = await RatingPublicAppService.GetCurrentUserRatingAsync(entityType, entityId);
currentUserRating = ratings.Find(x => x.IsSelectedByCurrentUser)?.StarCount;
}
var loginUrl =
@ -68,7 +68,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating
public List<RatingWithStarCountDto> Ratings { get; set; }
public RatingDto CurrentRating { get; set; }
public short? CurrentRating { get; set; }
public int TotalRating { get; set; }
}

100
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Rating/default.js

@ -1,81 +1,89 @@
(function () {
var l = abp.localization.getResource("CmsKit");
$(document).ready(function () {
abp.widgets.CmsRating = function ($widget) {
var widgetManager = $widget.data("abp-widget-manager");
var $ratingArea = $widget.find(".cms-rating-area");
function getFilters() {
return {
entityType: $ratingArea.attr("data-entity-type"),
entityId: $ratingArea.attr("data-entity-id")
};
}
function registerCreateOfNewRating() {
var authenticated = $(".my-rating-5").attr("data-authenticated");
$widget.find(".my-rating-5").each(function () {
var authenticated = $(this).attr("data-authenticated");
$(".my-rating-5").starRating({
initialRating: 0,
disableAfterRate: true,
useFullStars: true,
readOnly: authenticated === "True",
onHover: function(currentIndex, currentRating, $el) {
$(".live-rating").text(currentIndex);
},
onLeave: function(currentIndex, currentRating, $el) {
$(".live-rating").text(currentRating);
},
callback: function(currentRating, $el) {
volo.cmsKit.public.ratings.ratingPublic.create(
$ratingArea.attr("data-entity-type"),
$ratingArea.attr("data-entity-id"),
{
starCount: parseInt(currentRating)
$(this).starRating({
initialRating: 0,
disableAfterRate: true,
useFullStars: true,
readOnly: authenticated === "True",
onHover: function (currentIndex, currentRating, $el) {
$widget.find(".live-rating").text(currentIndex);
},
onLeave: function (currentIndex, currentRating, $el) {
$widget.find(".live-rating").text(currentRating);
},
callback: function (currentRating, $el) {
volo.cmsKit.public.ratings.ratingPublic.create(
$ratingArea.attr("data-entity-type"),
$ratingArea.attr("data-entity-id"),
{
starCount: parseInt(currentRating)
}
).then(function () {
widgetManager.refresh($widget);
})
}
).then(function () {
widgetManager.refresh($widget);
})
});
}
});
);
}
function registerUndoLink() {
$(".rating-undo-link").on('click', '', function (e) {
e.preventDefault();
abp.message.confirm(l("RatingUndoMessage"), function (ok) {
if(ok) {
var id = $(".rating-undo-link").attr("data-id");
volo.cmsKit.public.ratings.ratingPublic.delete(
id
).then(function () {
widgetManager.refresh($widget);
});
}
})
$widget.find(".rating-undo-link").each(function () {
$(this).on('click', '', function (e) {
e.preventDefault();
abp.message.confirm(l("RatingUndoMessage"), function (ok) {
if (ok) {
volo.cmsKit.public.ratings.ratingPublic.delete(
$ratingArea.attr("data-entity-type"),
$ratingArea.attr("data-entity-id")
).then(function () {
widgetManager.refresh($widget);
});
}
})
});
});
}
function init() {
registerCreateOfNewRating();
registerUndoLink();
}
return {
init: init,
getFilters: getFilters
}
};
}
;
$('.abp-widget-wrapper[data-widget-name="CmsRating"]')
.each(function () {
var widgetManager = new abp.WidgetManager({
wrapper: $(this),
});
widgetManager.init($(this));
});
});
})(jQuery);
})
;
})
(jQuery);

4
modules/cms-kit/src/Volo.CmsKit.Public.Web/Volo.CmsKit.Public.Web.csproj

@ -27,10 +27,6 @@
<EmbeddedResource Include="Components\**\*.css" />
<Content Remove="Components\**\*.js" />
<Content Remove="Components\**\*.css" />
<Content Update="Pages\CmsKit\Shared\Components\Rating\Default.cshtml">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Project>

70
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Ratings/RatingPublicAppService_Tests.cs

@ -1,5 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shouldly;
@ -34,8 +35,8 @@ namespace Volo.CmsKit.Ratings
var newRating = await _ratingAppService.CreateAsync(
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1,
new CreateRatingInput
_cmsKitTestData.EntityId2,
new CreateUpdateRatingInput
{
StarCount = 4
});
@ -44,53 +45,86 @@ namespace Volo.CmsKit.Ratings
{
var ratings = context.Set<Rating>().Where(x =>
x.EntityId == _cmsKitTestData.EntityId1 && x.EntityType == _cmsKitTestData.EntityType1).ToList();
ratings
.Any(c => c.Id == newRating.Id && c.CreatorId == newRating.CreatorId && c.StarCount == newRating.StarCount)
.Any(c => c.Id == newRating.Id && c.CreatorId == newRating.CreatorId &&
c.StarCount == newRating.StarCount)
.ShouldBeTrue();
});
}
[Fact]
public async Task UpdateAsync()
public async Task CreateAsync_Should_Update_If_Rating_Is_Exist()
{
_currentUser.Id.Returns(_cmsKitTestData.User1Id);
var rating = await _ratingAppService.CreateAsync(
var entity =
await _ratingAppService.GetCurrentUserRatingAsync(_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1);
var updatedEntity = await _ratingAppService.CreateAsync(
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1,
new CreateRatingInput
new CreateUpdateRatingInput
{
StarCount = 4
StarCount = 5
});
await _ratingAppService.UpdateAsync(rating.Id, new UpdateRatingInput
{
StarCount = 5
});
entity.Id.ShouldBe(updatedEntity.Id);
entity.EntityId.ShouldBe(updatedEntity.EntityId);
entity.EntityType.ShouldBe(updatedEntity.EntityType);
entity.StarCount.ShouldBe(updatedEntity.StarCount);
}
[Fact]
public async Task GetCurrentUserRatingAsync()
{
_currentUser.Id.Returns(_cmsKitTestData.User1Id);
var rating = await _ratingAppService.GetCurrentUserRatingAsync(
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1
);
UsingDbContext(context =>
{
var updatedRating = context.Set<Rating>().Single(x => x.Id == rating.Id);
updatedRating.StarCount.ShouldBe((short)5);
var ratings = context.Set<Rating>().Where(x =>
x.EntityId == _cmsKitTestData.EntityId1 && x.EntityType == _cmsKitTestData.EntityType1).ToList();
ratings
.Any(c => c.Id == rating.Id && c.EntityId == rating.EntityId && c.EntityType == rating.EntityType)
.ShouldBeTrue();
});
}
[Fact]
public async Task GetGroupedStarCountsAsync()
{
_currentUser.Id.Returns(_cmsKitTestData.User1Id);
var ratings = await _ratingAppService.GetGroupedStarCountsAsync(
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1
);
ratings.ShouldNotBeNull();
ratings.Count.ShouldBeGreaterThan(0);
}
[Fact]
public async Task DeleteAsync()
{
_currentUser.Id.Returns(_cmsKitTestData.User1Id);
var rating = await _ratingAppService.CreateAsync(
_cmsKitTestData.EntityType1,
_cmsKitTestData.EntityId1,
new CreateRatingInput
new CreateUpdateRatingInput
{
StarCount = 4
});
await _ratingAppService.DeleteAsync(rating.Id);
await _ratingAppService.DeleteAsync(_cmsKitTestData.EntityType1, _cmsKitTestData.EntityId1);
UsingDbContext(context =>
{

8
modules/cms-kit/test/Volo.CmsKit.TestBase/Ratings/RatingRepository_Tests.cs

@ -17,14 +17,6 @@ namespace Volo.CmsKit.Ratings
_ratingRepository = GetRequiredService<IRatingRepository>();
}
[Fact]
public async Task GetListAsync()
{
var list = await _ratingRepository.GetListAsync(_cmsKitTestData.EntityType1, _cmsKitTestData.EntityId1);
list.Count.ShouldBeGreaterThan(0);
}
[Fact]
public async Task GetCurrentUserRatingAsync()
{

Loading…
Cancel
Save