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.
abp/test/Volo.Abp.Settings.Tests/Volo/Abp/Settings/SettingsTestBase.cs

46 lines
1.4 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Session;
using Volo.Abp.Settings.EntityFrameworkCore;
using Volo.Abp.TestBase;
namespace Volo.Abp.Settings
{
public class SettingsTestBase : AbpIntegratedTest<AbpSettingsTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
protected virtual void UsingDbContext(Action<IAbpSettingsDbContext> action)
{
using (var dbContext = GetRequiredService<IAbpSettingsDbContext>())
{
action.Invoke(dbContext);
}
}
protected virtual T UsingDbContext<T>(Func<IAbpSettingsDbContext, T> action)
{
using (var dbContext = GetRequiredService<IAbpSettingsDbContext>())
{
return action.Invoke(dbContext);
}
}
protected List<Setting> GetSettingsFromDbContext(string entityType, string entityId, string name)
{
return UsingDbContext(context =>
context.Settings.Where(
s =>
s.ProviderName == UserSettingValueProvider.ProviderName &&
s.ProviderKey == SettingTestDataBuilder.User1Id.ToString() &&
s.Name == "MySetting2"
).ToList()
);
}
}
}