mirror of https://github.com/abpframework/abp.git
12 changed files with 276 additions and 7 deletions
@ -0,0 +1,80 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using NSubstitute; |
|||
using Shouldly; |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.Users; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class FeatureAppService_Tests : FeatureManagementApplicationTestBase |
|||
{ |
|||
private readonly IFeatureAppService _featureAppService; |
|||
private readonly IFeatureValueRepository _featureValueRepository; |
|||
private ICurrentUser _currentUser; |
|||
private readonly FeatureManagementTestData _testData; |
|||
|
|||
|
|||
public FeatureAppService_Tests() |
|||
{ |
|||
_featureAppService = GetRequiredService<IFeatureAppService>(); |
|||
_featureValueRepository = GetRequiredService<IFeatureValueRepository>(); |
|||
_testData = GetRequiredService<FeatureManagementTestData>(); |
|||
} |
|||
|
|||
protected override void AfterAddApplication(IServiceCollection services) |
|||
{ |
|||
_currentUser = Substitute.For<ICurrentUser>(); |
|||
services.AddSingleton(_currentUser); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetAsync() |
|||
{ |
|||
Login(_testData.User1Id); |
|||
|
|||
var featureList = await _featureAppService.GetAsync(EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N")); |
|||
|
|||
featureList.ShouldNotBeNull(); |
|||
featureList.Features.ShouldContain(feature => feature.Name == TestFeatureDefinitionProvider.SocialLogins); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateAsync() |
|||
{ |
|||
Login(_testData.User1Id); |
|||
|
|||
await _featureAppService.UpdateAsync(EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"), new UpdateFeaturesDto() |
|||
{ |
|||
Features = new List<UpdateFeatureDto>() |
|||
{ |
|||
new UpdateFeatureDto() |
|||
{ |
|||
Name = TestFeatureDefinitionProvider.SocialLogins, |
|||
Value = false.ToString().ToLowerInvariant() |
|||
} |
|||
} |
|||
}); |
|||
|
|||
(await _featureAppService.GetAsync(EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).Features.Any(x => |
|||
x.Name == TestFeatureDefinitionProvider.SocialLogins && |
|||
x.Value == false.ToString().ToLowerInvariant()) |
|||
.ShouldBeTrue(); |
|||
|
|||
} |
|||
|
|||
private void Login(Guid userId) |
|||
{ |
|||
_currentUser.Id.Returns(userId); |
|||
_currentUser.IsAuthenticated.Returns(true); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class FeatureManagementApplicationTestBase : FeatureManagementTestBase<FeatureManagementApplicationTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.Features; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class FeatureValueCacheItemInvalidator_Tests : FeatureManagementTestBase<AbpFeatureManagementDomainTestModule> |
|||
{ |
|||
private IDistributedCache<FeatureValueCacheItem> _cache; |
|||
private IFeatureValueRepository _featureValueRepository; |
|||
private IFeatureManagementStore _featureManagementStore; |
|||
|
|||
public FeatureValueCacheItemInvalidator_Tests() |
|||
{ |
|||
_cache = GetRequiredService<IDistributedCache<FeatureValueCacheItem>>(); |
|||
_featureValueRepository = GetRequiredService<IFeatureValueRepository>(); |
|||
_featureManagementStore = GetRequiredService<IFeatureManagementStore>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Cache_Should_Invalidator_WhenFeatureChanged() |
|||
{ |
|||
// Arrange cache feature.
|
|||
await _featureManagementStore.GetOrNullAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N")); |
|||
|
|||
var feature = await _featureValueRepository.FindAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N")); |
|||
|
|||
// Act
|
|||
await _featureValueRepository.DeleteAsync(feature); |
|||
|
|||
// Assert
|
|||
(await _cache.GetAsync(FeatureValueCacheItem.CalculateCacheKey(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N")))).ShouldBeNull(); |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp.FeatureManagement.EntityFrameworkCore |
|||
{ |
|||
public class FeatureManagementStore_Tests : FeatureManagementStore_Tests<AbpFeatureManagementEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp.FeatureManagement.MongoDB |
|||
{ |
|||
public class FeatureManagementStore_Tests : FeatureManagementStore_Tests<AbpFeatureManagementMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public abstract class FeatureManagementStore_Tests<TStartupModule> : FeatureManagementTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private IFeatureManagementStore FeatureManagementStore { get; set; } |
|||
private IFeatureValueRepository FeatureValueRepository { get; set; } |
|||
|
|||
protected FeatureManagementStore_Tests() |
|||
{ |
|||
FeatureManagementStore = GetRequiredService<IFeatureManagementStore>(); |
|||
FeatureValueRepository = GetRequiredService<IFeatureValueRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetOrNullAsync() |
|||
{ |
|||
// Act
|
|||
(await FeatureManagementStore.GetOrNullAsync(Guid.NewGuid().ToString("N"), |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).ShouldBeNull(); |
|||
|
|||
(await FeatureManagementStore.GetOrNullAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).ShouldNotBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Get_Null_Where_Feature_Deleted() |
|||
{ |
|||
// Arrange
|
|||
(await FeatureManagementStore.GetOrNullAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).ShouldNotBeNull(); |
|||
|
|||
// Act
|
|||
await FeatureManagementStore.DeleteAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N")); |
|||
|
|||
// Assert
|
|||
(await FeatureManagementStore.GetOrNullAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetAsync() |
|||
{ |
|||
// Arrange
|
|||
(await FeatureValueRepository.FindAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).Value.ShouldBe(true.ToString().ToLowerInvariant()); |
|||
|
|||
// Act
|
|||
await FeatureManagementStore.SetAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
false.ToString().ToUpperInvariant(), |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N")); |
|||
|
|||
// Assert
|
|||
(await FeatureValueRepository.FindAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).Value.ShouldBe(false.ToString().ToUpperInvariant()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteAsync() |
|||
{ |
|||
// Arrange
|
|||
(await FeatureValueRepository.FindAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).ShouldNotBeNull(); |
|||
|
|||
// Act
|
|||
await FeatureManagementStore.DeleteAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N")); |
|||
|
|||
|
|||
// Assert
|
|||
(await FeatureValueRepository.FindAsync(TestFeatureDefinitionProvider.SocialLogins, |
|||
EditionFeatureValueProvider.ProviderName, |
|||
TestEditionIds.Regular.ToString("N"))).ShouldBeNull(); |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +1,10 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
using System; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class FeatureManagementTestData : ISingletonDependency |
|||
{ |
|||
|
|||
public Guid User1Id { get; } = Guid.NewGuid(); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue