Open Source Web Application Framework for ASP.NET Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
1.2 KiB

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Http.Modeling;
using Volo.Abp.Modularity;
using Volo.Abp.Testing;
namespace Volo.Abp.Http.FluentValidation;
public abstract class AbpHttpFluentValidationTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected virtual async Task<PropertyApiDescriptionModel> GetPropertyAsync<TDto>(string propertyName)
{
var typeModel = await CreateTypeModelAsync(typeof(TDto));
return typeModel.Properties!.Single(x => x.Name == propertyName);
}
protected virtual async Task<TypeApiDescriptionModel> CreateTypeModelAsync(Type type)
{
var typeModel = TypeApiDescriptionModel.Create(type);
var contributors = ServiceProvider.GetServices<IPropertyApiDescriptionModelContributor>().ToArray();
foreach (var propertyModel in typeModel.Properties!)
{
var context = new PropertyApiDescriptionModelContributionContext(propertyModel, type);
foreach (var contributor in contributors)
{
await contributor.ContributeAsync(context);
}
}
return typeModel;
}
}