mirror of https://github.com/abpframework/abp.git
10 changed files with 135 additions and 61 deletions
@ -1,20 +1,21 @@ |
|||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
namespace Volo.Abp.Settings |
namespace Volo.Abp.Settings |
||||
{ |
{ |
||||
public interface ISettingManager |
public interface ISettingManager |
||||
{ |
{ |
||||
Task<string> GetOrNullAsync(string name, bool fallback = true); |
Task<string> GetOrNullAsync([NotNull]string name); |
||||
|
|
||||
Task<string> GetOrNullAsync(string name, string entityType, string entityId, bool fallback = true); |
Task<string> GetOrNullAsync([NotNull]string name, [NotNull] string entityType, string entityId, bool fallback = true); |
||||
|
|
||||
Task<List<SettingValue>> GetAllAsync(); |
Task<List<SettingValue>> GetAllAsync(); |
||||
|
|
||||
Task<List<SettingValue>> GetAllAsync(string entityType, string entityId, bool fallback = true); |
Task<List<SettingValue>> GetAllAsync([NotNull] string entityType, string entityId, bool fallback = true); |
||||
|
|
||||
Task SetAsync(string name, string value); |
Task SetAsync([NotNull] string name, string value, bool forceToSet = false); |
||||
|
|
||||
Task SetAsync(string name, string value, string entityType, string entityId); |
Task SetAsync([NotNull] string name, string value, [NotNull] string entityType, string entityId, bool forceToSet = false); |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using NSubstitute; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Session; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Settings |
||||
|
{ |
||||
|
public class SettingManager_User_Based_Tests: AbpSettingsTestBase |
||||
|
{ |
||||
|
private Guid _currentUserId; |
||||
|
private readonly ISettingManager _settingManager; |
||||
|
|
||||
|
public SettingManager_User_Based_Tests() |
||||
|
{ |
||||
|
_settingManager = GetRequiredService<ISettingManager>(); |
||||
|
} |
||||
|
|
||||
|
protected override void AfterAddApplication(IServiceCollection services) |
||||
|
{ |
||||
|
ICurrentUser currentUser = Substitute.For<ICurrentUser>(); |
||||
|
currentUser.Id.Returns(ci => _currentUserId); |
||||
|
services.AddSingleton(currentUser); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Get_From_Store_For_Given_User() |
||||
|
{ |
||||
|
(await _settingManager.GetOrNullForUserAsync("MySetting2", AbpIdentityTestDataBuilder.User1Id)).ShouldBe("user1-store-value"); |
||||
|
(await _settingManager.GetOrNullForUserAsync("MySetting2", AbpIdentityTestDataBuilder.User2Id)).ShouldBe("user2-store-value"); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Get_From_Store_For_Current_User() |
||||
|
{ |
||||
|
_currentUserId = AbpIdentityTestDataBuilder.User1Id; |
||||
|
(await _settingManager.GetOrNullAsync("MySetting2")).ShouldBe("user1-store-value"); |
||||
|
|
||||
|
_currentUserId = AbpIdentityTestDataBuilder.User2Id; |
||||
|
(await _settingManager.GetOrNullAsync("MySetting2")).ShouldBe("user2-store-value"); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Fallback_To_Default_Store_Value_When_No_Value_For_Given_User() |
||||
|
{ |
||||
|
(await _settingManager.GetOrNullForUserAsync("MySetting2", Guid.NewGuid())).ShouldBe("default-store-value"); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Not_Fallback_To_Default_Store_Value_When_No_Value_For_Given_User_But_Specified_Fallback_As_False() |
||||
|
{ |
||||
|
(await _settingManager.GetOrNullForUserAsync("MySetting2", Guid.NewGuid(), fallback: false)).ShouldBeNull(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,12 +1,11 @@ |
|||||
using System; |
namespace Volo.Abp.Settings |
||||
|
|
||||
namespace Volo.Abp.Settings |
|
||||
{ |
{ |
||||
public class TestSettingProvider : SettingProvider |
public class TestSettingProvider : SettingProvider |
||||
{ |
{ |
||||
public override void Define(ISettingDefinitionContext context) |
public override void Define(ISettingDefinitionContext context) |
||||
{ |
{ |
||||
context.Add(new SettingDefinition("MySetting1")); |
context.Add(new SettingDefinition("MySetting1")); |
||||
|
context.Add(new SettingDefinition("MySetting2")); |
||||
context.Add(new SettingDefinition("SettingNotSetInStore", defaultValue: "default-value")); |
context.Add(new SettingDefinition("SettingNotSetInStore", defaultValue: "default-value")); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue