消息修复
This commit is contained in:
@@ -3,14 +3,50 @@ using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class NotificationsControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public void Send_message_request_validation_metadata_is_compatible_with_mvc_record_binding()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
services.AddControllers()
|
||||
.AddApplicationPart(typeof(NotificationsController).Assembly);
|
||||
|
||||
using var serviceProvider = services.BuildServiceProvider();
|
||||
var objectValidator = serviceProvider.GetRequiredService<IObjectModelValidator>();
|
||||
var httpContext = new DefaultHttpContext
|
||||
{
|
||||
RequestServices = serviceProvider
|
||||
};
|
||||
var actionContext = new ActionContext(
|
||||
httpContext,
|
||||
new RouteData(),
|
||||
new ActionDescriptor(),
|
||||
new ModelStateDictionary());
|
||||
var request = new SendMessageRequest(
|
||||
"校内通知",
|
||||
"<p>这是一条用于验证请求模型绑定的通知。</p>");
|
||||
|
||||
var exception = Record.Exception(() =>
|
||||
objectValidator.Validate(actionContext, null, string.Empty, request));
|
||||
|
||||
Assert.Null(exception);
|
||||
Assert.True(actionContext.ModelState.IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task College_administrator_can_only_send_to_enabled_users_in_own_college()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user