mirror of https://github.com/abpframework/abp.git
64 changed files with 476 additions and 701 deletions
@ -0,0 +1,38 @@ |
|||
# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app |
|||
|
|||
# Number of days of inactivity before a closed issue or pull request is locked |
|||
daysUntilLock: 30 |
|||
|
|||
# Skip issues and pull requests created before a given timestamp. Timestamp must |
|||
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable |
|||
skipCreatedBefore: false |
|||
|
|||
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable |
|||
exemptLabels: [] |
|||
|
|||
# Label to add before locking, such as `outdated`. Set to `false` to disable |
|||
lockLabel: false |
|||
|
|||
# Comment to post before locking. Set to `false` to disable |
|||
lockComment: > |
|||
This thread has been automatically locked since there has not been |
|||
any recent activity after it was closed. Please open a new issue for |
|||
related bugs. |
|||
|
|||
# Assign `resolved` as the reason for locking. Set to `false` to disable |
|||
setLockReason: true |
|||
|
|||
# Limit to only `issues` or `pulls` |
|||
# only: issues |
|||
|
|||
# Optionally, specify configuration settings just for `issues` or `pulls` |
|||
# issues: |
|||
# exemptLabels: |
|||
# - help-wanted |
|||
# lockLabel: outdated |
|||
|
|||
# pulls: |
|||
# daysUntilLock: 30 |
|||
|
|||
# Repository to extend settings from |
|||
# _extends: repo |
|||
@ -0,0 +1,15 @@ |
|||
# Number of days of inactivity before an issue becomes stale |
|||
daysUntilStale: 60 |
|||
# Number of days of inactivity before a stale issue is closed |
|||
daysUntilClose: 7 |
|||
# Set to true to ignore issues in a milestone (defaults to false) |
|||
exemptMilestones: true |
|||
# Label to use when marking an issue as stale |
|||
staleLabel: inactive |
|||
# Comment to post when marking an issue as stale. Set to `false` to disable |
|||
markComment: > |
|||
This issue has been automatically marked as stale because it has not had |
|||
recent activity. It will be closed if no further activity occurs. Thank you |
|||
for your contributions. |
|||
# Comment to post when closing a stale issue. Set to `false` to disable |
|||
closeComment: false |
|||
@ -0,0 +1,15 @@ |
|||
using Newtonsoft.Json; |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace Volo.Abp.Json.Newtonsoft |
|||
{ |
|||
public class AbpNewtonsoftJsonSerializerOptions |
|||
{ |
|||
public ITypeList<JsonConverter> Converters { get; } |
|||
|
|||
public AbpNewtonsoftJsonSerializerOptions() |
|||
{ |
|||
Converters = new TypeList<JsonConverter>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Linq; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Validation.StringValues; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class StringValueTypeJsonConverter : JsonConverter, ITransientDependency |
|||
{ |
|||
public override bool CanWrite => false; |
|||
|
|||
public override bool CanConvert(Type objectType) |
|||
{ |
|||
return objectType == typeof(IStringValueType); |
|||
} |
|||
|
|||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) |
|||
{ |
|||
throw new NotImplementedException("This method should not be called to write (since CanWrite is false)."); |
|||
} |
|||
|
|||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) |
|||
{ |
|||
if (reader.TokenType != JsonToken.StartObject) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
var jsonObject = JObject.Load(reader); |
|||
|
|||
var stringValue = CreateStringValueTypeByName(jsonObject, jsonObject["name"].ToString()); |
|||
foreach (var o in serializer.Deserialize<Dictionary<string, object>>( |
|||
new JsonTextReader(new StringReader(jsonObject["properties"].ToString())))) |
|||
{ |
|||
stringValue[o.Key] = o.Value; |
|||
} |
|||
|
|||
stringValue.Validator = CreateValueValidatorByName(jsonObject["validator"], jsonObject["validator"]["name"].ToString()); |
|||
foreach (var o in serializer.Deserialize<Dictionary<string, object>>( |
|||
new JsonTextReader(new StringReader(jsonObject["validator"]["properties"].ToString())))) |
|||
{ |
|||
stringValue.Validator[o.Key] = o.Value; |
|||
} |
|||
|
|||
return stringValue; |
|||
} |
|||
|
|||
protected virtual IStringValueType CreateStringValueTypeByName(JObject jObject, string name) |
|||
{ |
|||
if (name == "SelectionStringValueType") |
|||
{ |
|||
var selectionStringValueType = new SelectionStringValueType(); |
|||
if (jObject["itemSource"].HasValues) |
|||
{ |
|||
selectionStringValueType.ItemSource = new StaticSelectionStringValueItemSource(jObject["itemSource"]["items"] |
|||
.Select(item => new LocalizableSelectionStringValueItem() |
|||
{ |
|||
Value = item["value"].ToString(), |
|||
DisplayText = new LocalizableStringInfo(item["displayText"]["resourceName"].ToString(), item["displayText"]["name"].ToString()) |
|||
}).ToArray()); |
|||
} |
|||
|
|||
return selectionStringValueType; |
|||
} |
|||
|
|||
return name switch |
|||
{ |
|||
"FreeTextStringValueType" => new FreeTextStringValueType(), |
|||
"ToggleStringValueType" => new ToggleStringValueType(), |
|||
_ => throw new ArgumentException($"{nameof(IStringValueType)} named {name} was not found!") |
|||
}; |
|||
} |
|||
|
|||
protected virtual IValueValidator CreateValueValidatorByName(JToken jObject, string name) |
|||
{ |
|||
return name switch |
|||
{ |
|||
"NULL" => new AlwaysValidValueValidator(), |
|||
"BOOLEAN" => new BooleanValueValidator(), |
|||
"NUMERIC" => new NumericValueValidator(), |
|||
"STRING" => new StringValueValidator(), |
|||
_ => throw new ArgumentException($"{nameof(IValueValidator)} named {name} was not found!") |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Newtonsoft.Json; |
|||
using Shouldly; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.Validation.StringValues; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.FeatureManagement |
|||
{ |
|||
public class StringValueJsonConverter_Tests : FeatureManagementApplicationTestBase |
|||
{ |
|||
private readonly IJsonSerializer _jsonSerializer; |
|||
|
|||
public StringValueJsonConverter_Tests() |
|||
{ |
|||
_jsonSerializer = GetRequiredService<IJsonSerializer>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Serialize_And_Deserialize() |
|||
{ |
|||
var featureListDto = new FeatureListDto |
|||
{ |
|||
Features = new List<FeatureDto> |
|||
{ |
|||
new FeatureDto |
|||
{ |
|||
ValueType = new FreeTextStringValueType |
|||
{ |
|||
Validator = new BooleanValueValidator() |
|||
} |
|||
}, |
|||
new FeatureDto |
|||
{ |
|||
ValueType = new SelectionStringValueType |
|||
{ |
|||
ItemSource = new StaticSelectionStringValueItemSource( |
|||
new LocalizableSelectionStringValueItem |
|||
{ |
|||
Value = "TestValue", |
|||
DisplayText = new LocalizableStringInfo("TestResourceName", "TestName") |
|||
}), |
|||
Validator = new AlwaysValidValueValidator() |
|||
} |
|||
}, |
|||
new FeatureDto |
|||
{ |
|||
ValueType = new ToggleStringValueType |
|||
{ |
|||
Validator = new NumericValueValidator |
|||
{ |
|||
MaxValue = 1000, |
|||
MinValue = 10 |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var serialized = _jsonSerializer.Serialize(featureListDto, indented: true); |
|||
var featureListDto2 = _jsonSerializer.Deserialize<FeatureListDto>(serialized); |
|||
|
|||
featureListDto2.Features[0].ValueType.ShouldBeOfType<FreeTextStringValueType>(); |
|||
featureListDto2.Features[0].ValueType.Validator.ShouldBeOfType<BooleanValueValidator>(); |
|||
|
|||
featureListDto2.Features[1].ValueType.ShouldBeOfType<SelectionStringValueType>(); |
|||
featureListDto2.Features[1].ValueType.Validator.ShouldBeOfType<AlwaysValidValueValidator>(); |
|||
featureListDto2.Features[1].ValueType.As<SelectionStringValueType>().ItemSource.Items.ShouldBeOfType<LocalizableSelectionStringValueItem[]>(); |
|||
featureListDto2.Features[1].ValueType.As<SelectionStringValueType>().ItemSource.Items.ShouldContain(x => |
|||
x.Value == "TestValue" && x.DisplayText.ResourceName == "TestResourceName" && |
|||
x.DisplayText.Name == "TestName"); |
|||
|
|||
featureListDto2.Features[2].ValueType.ShouldBeOfType<ToggleStringValueType>(); |
|||
featureListDto2.Features[2].ValueType.Validator.ShouldBeOfType<NumericValueValidator>(); |
|||
featureListDto2.Features[2].ValueType.Validator.As<NumericValueValidator>().MaxValue.ShouldBe(1000); |
|||
featureListDto2.Features[2].ValueType.Validator.As<NumericValueValidator>().MinValue.ShouldBe(10); |
|||
} |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.2</TargetFramework> |
|||
<AssemblyName>Volo.Abp.Users.EntityFrameworkCore.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.Users.EntityFrameworkCore.Tests</PackageId> |
|||
<LangVersion>latest</LangVersion> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Users.EntityFrameworkCore\Volo.Abp.Users.EntityFrameworkCore.csproj" /> |
|||
<ProjectReference Include="..\..\test\Volo.Abp.Users.Tests.Shared\Volo.Abp.Users.Tests.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.4" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,2 +0,0 @@ |
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
|||
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary> |
|||
@ -1,7 +0,0 @@ |
|||
namespace Volo.Abp.Users.EntityFrameworkCore |
|||
{ |
|||
public class AbpUserRepository_Tests : AbpUserRepository_Tests<AbpUsersEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,38 +0,0 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.Users.EntityFrameworkCore |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpUsersTestsSharedModule), |
|||
typeof(AbpUsersEntityFrameworkCoreModule) |
|||
)] |
|||
public class AbpUsersEntityFrameworkCoreTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddEntityFrameworkInMemoryDatabase(); |
|||
|
|||
var databaseName = Guid.NewGuid().ToString(); |
|||
|
|||
services.Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.Configure(context => |
|||
{ |
|||
context.DbContextOptions.UseInMemoryDatabase(databaseName); |
|||
}); |
|||
}); |
|||
|
|||
services.Configure<AbpUnitOfWorkDefaultOptions>(options => |
|||
{ |
|||
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
|
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpUsersEntityFrameworkCoreTestModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,7 +0,0 @@ |
|||
namespace Volo.Abp.Users.EntityFrameworkCore |
|||
{ |
|||
public class ExternalUserLookupService_Tests : ExternalUserLookupService_Tests<AbpUsersEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,7 +0,0 @@ |
|||
namespace Volo.Abp.Users.EntityFrameworkCore |
|||
{ |
|||
public class LocalUserLookupService_Tests : LocalUserLookupService_Tests<AbpUsersEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.2</TargetFramework> |
|||
<AssemblyName>Volo.Abp.Users.MongoDB.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.Users.MongoDB.Tests</PackageId> |
|||
<LangVersion>latest</LangVersion> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Users.MongoDB\Volo.Abp.Users.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\..\test\Volo.Abp.Users.Tests.Shared\Volo.Abp.Users.Tests.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> |
|||
<PackageReference Include="Mongo2Go" Version="2.2.12" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,8 +0,0 @@ |
|||
namespace Volo.Abp.Users.MongoDB |
|||
{ |
|||
[Collection(MongoTestCollection.Name)] |
|||
public class AbpUserRepository_Tests : AbpUserRepository_Tests<AbpUsersMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Mongo2Go; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Users.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpUsersMongoDbModule), |
|||
typeof(AbpUsersTestsSharedModule) |
|||
)] |
|||
public class AbpUsersMongoDbTestModule : AbpModule |
|||
{ |
|||
private static readonly MongoDbRunner MongoDbRunner = MongoDbRunner.Start(); |
|||
|
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
var connectionString = MongoDbFixture.ConnectionString.EnsureEndsWith('/') + |
|||
"Db_" + |
|||
Guid.NewGuid().ToString("N"); |
|||
|
|||
Configure<AbpDbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = connectionString; |
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpUsersMongoDbTestModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,8 +0,0 @@ |
|||
namespace Volo.Abp.Users.MongoDB |
|||
{ |
|||
[Collection(MongoTestCollection.Name)] |
|||
public class ExternalUserLookupService_Tests : ExternalUserLookupService_Tests<AbpUsersMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,8 +0,0 @@ |
|||
namespace Volo.Abp.Users.MongoDB |
|||
{ |
|||
[Collection(MongoTestCollection.Name)] |
|||
public class LocalUserLookupService_Tests : LocalUserLookupService_Tests<AbpUsersMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
using System; |
|||
using Mongo2Go; |
|||
|
|||
namespace Volo.Abp.Users.MongoDB |
|||
{ |
|||
public class MongoDbFixture : IDisposable |
|||
{ |
|||
private static readonly MongoDbRunner MongoDbRunner; |
|||
public static readonly string ConnectionString; |
|||
|
|||
static MongoDbFixture() |
|||
{ |
|||
MongoDbRunner = MongoDbRunner.Start(); |
|||
ConnectionString = MongoDbRunner.ConnectionString; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
MongoDbRunner?.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Users.MongoDB |
|||
{ |
|||
[CollectionDefinition(Name)] |
|||
public class MongoTestCollection : ICollectionFixture<MongoDbFixture> |
|||
{ |
|||
public const string Name = "MongoDB Collection"; |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.2</TargetFramework> |
|||
<AssemblyName>Volo.Abp.Users.Tests.Shared</AssemblyName> |
|||
<PackageId>Volo.Abp.Users.Tests.Shared</PackageId> |
|||
<LangVersion>latest</LangVersion> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Users.Domain\Volo.Abp.Users.Domain.csproj" /> |
|||
|
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> |
|||
<PackageReference Include="NSubstitute" Version="4.2.1" /> |
|||
<PackageReference Include="Shouldly" Version="3.0.2" /> |
|||
<PackageReference Include="xunit" Version="2.4.1" /> |
|||
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" /> |
|||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,2 +0,0 @@ |
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
|||
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary> |
|||
@ -1,53 +0,0 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public abstract class AbpUserRepository_Tests<TStartupModule> : AbpUsersTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly AbpUsersLocalTestData _localTestData; |
|||
private readonly IAbpUserRepository _userRepository; |
|||
|
|||
protected AbpUserRepository_Tests() |
|||
{ |
|||
_userRepository = GetRequiredService<IAbpUserRepository>(); |
|||
_localTestData = GetRequiredService<AbpUsersLocalTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync() |
|||
{ |
|||
var john = await _userRepository.FindAsync(_localTestData.John.Id); |
|||
john.ShouldNotBeNull(); |
|||
john.UserName.ShouldBe(_localTestData.John.UserName); |
|||
|
|||
//Undefined user
|
|||
(await _userRepository.FindAsync(Guid.NewGuid())).ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByUserNameAsync() |
|||
{ |
|||
var john = await _userRepository.FindByUserNameAsync(_localTestData.John.UserName); |
|||
john.ShouldNotBeNull(); |
|||
john.Id.ShouldBe(_localTestData.John.Id); |
|||
|
|||
//Undefined user
|
|||
(await _userRepository.FindByUserNameAsync("undefined-user")).ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync() |
|||
{ |
|||
(await _userRepository.GetListAsync(new Guid[0])).Any().ShouldBeFalse(); |
|||
(await _userRepository.GetListAsync(new[] { _localTestData.John.Id })).Count.ShouldBe(1); |
|||
(await _userRepository.GetListAsync(new[] { _localTestData.John.Id, _localTestData.David.Id })).Count.ShouldBe(2); |
|||
(await _userRepository.GetListAsync(new[] { _localTestData.John.Id, _localTestData.David.Id, Guid.NewGuid() })).Count.ShouldBe(2); |
|||
} |
|||
} |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public class AbpUsersExternalTestData : ISingletonDependency |
|||
{ |
|||
public IAbpUserData David { get; } |
|||
public IAbpUserData Neo { get; } |
|||
|
|||
public AbpUsersExternalTestData(AbpUsersLocalTestData localTestData) |
|||
{ |
|||
Neo = new AbpUserData(Guid.NewGuid(), "neo"); |
|||
David = localTestData.David.ToAbpUserData(); |
|||
} |
|||
|
|||
public List<IAbpUserData> GetAllUsers() |
|||
{ |
|||
return new List<IAbpUserData> |
|||
{ |
|||
David, |
|||
Neo |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using System; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public class AbpUsersLocalTestData : ISingletonDependency |
|||
{ |
|||
public AbpUser John { get; } |
|||
public AbpUser David { get; } |
|||
|
|||
public AbpUsersLocalTestData() |
|||
{ |
|||
John = new AbpUser(Guid.NewGuid(), "john"); |
|||
David = new AbpUser(Guid.NewGuid(), "david", "david@abp.io"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Testing; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public abstract class AbpUsersTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public class AbpUsersTestDataBuilder : ITransientDependency |
|||
{ |
|||
private readonly IAbpUserRepository _userRepository; |
|||
private readonly AbpUsersLocalTestData _localTestData; |
|||
|
|||
public AbpUsersTestDataBuilder( |
|||
IAbpUserRepository userRepository, |
|||
AbpUsersLocalTestData localTestData) |
|||
{ |
|||
_userRepository = userRepository; |
|||
_localTestData = localTestData; |
|||
} |
|||
|
|||
public void Build() |
|||
{ |
|||
AddUsers(); |
|||
} |
|||
|
|||
private void AddUsers() |
|||
{ |
|||
_userRepository.Insert(_localTestData.John); |
|||
_userRepository.Insert(_localTestData.David); |
|||
} |
|||
} |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpUsersDomainModule), |
|||
typeof(AbpTestBaseModule), |
|||
typeof(AbpAutofacModule) |
|||
)] |
|||
public class AbpUsersTestsSharedModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpUsersTestsSharedModule>(); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
SeedTestData(context); |
|||
} |
|||
|
|||
private static void SeedTestData(ApplicationInitializationContext context) |
|||
{ |
|||
using (var scope = context.ServiceProvider.CreateScope()) |
|||
{ |
|||
scope.ServiceProvider |
|||
.GetRequiredService<AbpUsersTestDataBuilder>() |
|||
.Build(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,77 +0,0 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public abstract class ExternalUserLookupService_Tests<TStartupModule> : AbpUsersTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly IAbpUserLookupService _lookupService; |
|||
private readonly AbpUsersLocalTestData _localTestData; |
|||
private readonly AbpUsersExternalTestData _externalTestData; |
|||
|
|||
protected ExternalUserLookupService_Tests() |
|||
{ |
|||
_lookupService = GetRequiredService<IAbpUserLookupService>(); |
|||
_localTestData = GetRequiredService<AbpUsersLocalTestData>(); |
|||
_externalTestData = GetRequiredService<AbpUsersExternalTestData>(); |
|||
} |
|||
|
|||
protected override void AfterAddApplication(IServiceCollection services) |
|||
{ |
|||
services.AddTransient<IExternalAbpUserLookupServiceProvider, TestExternalAbpUserLookupServiceProvider>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByUserNameAsync() |
|||
{ |
|||
(await GetRequiredService<IAbpUserRepository>().FindByUserNameAsync(_localTestData.John.UserName)).ShouldNotBeNull(); |
|||
|
|||
(await _lookupService.FindByUserNameAsync("undefined-user")).ShouldBeNull(); |
|||
(await _lookupService.FindByUserNameAsync(_localTestData.John.UserName)).ShouldBeNull(); //Because it's not available in the external provider. And this will delete the user!
|
|||
(await _lookupService.FindByUserNameAsync(_localTestData.David.UserName)).ShouldNotBeNull(); |
|||
(await _lookupService.FindByUserNameAsync(_externalTestData.Neo.UserName)).ShouldNotBeNull(); |
|||
|
|||
(await GetRequiredService<IAbpUserRepository>().FindByUserNameAsync(_localTestData.John.UserName)).ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByIdAsync() |
|||
{ |
|||
(await GetRequiredService<IAbpUserRepository>().FindAsync(_localTestData.John.Id)).ShouldNotBeNull(); |
|||
|
|||
(await _lookupService.FindByIdAsync(Guid.NewGuid())).ShouldBeNull(); |
|||
(await _lookupService.FindByIdAsync(_localTestData.John.Id)).ShouldBeNull(); //Because it's not available in the external provider. And this will delete the user!
|
|||
(await _lookupService.FindByIdAsync(_localTestData.David.Id)).ShouldNotBeNull(); |
|||
(await _lookupService.FindByIdAsync(_externalTestData.Neo.Id)).ShouldNotBeNull(); |
|||
|
|||
(await GetRequiredService<IAbpUserRepository>().FindAsync(_localTestData.John.Id)).ShouldBeNull(); |
|||
} |
|||
|
|||
public class TestExternalAbpUserLookupServiceProvider : IExternalAbpUserLookupServiceProvider |
|||
{ |
|||
private readonly AbpUsersExternalTestData _externalTestData; |
|||
|
|||
public TestExternalAbpUserLookupServiceProvider(AbpUsersExternalTestData externalTestData) |
|||
{ |
|||
_externalTestData = externalTestData; |
|||
} |
|||
|
|||
public Task<IAbpUserData> FindByIdAsync(Guid id, CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(_externalTestData.GetAllUsers().FirstOrDefault(u => u.Id == id)); |
|||
} |
|||
|
|||
public Task<IAbpUserData> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(_externalTestData.GetAllUsers().FirstOrDefault(u => u.UserName == userName)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,28 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Users |
|||
{ |
|||
public abstract class LocalUserLookupService_Tests<TStartupModule> : AbpUsersTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly IAbpUserLookupService _lookupService; |
|||
private readonly AbpUsersLocalTestData _localTestData; |
|||
|
|||
protected LocalUserLookupService_Tests() |
|||
{ |
|||
_lookupService = GetRequiredService<IAbpUserLookupService>(); |
|||
_localTestData = GetRequiredService<AbpUsersLocalTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByUserNameAsync() |
|||
{ |
|||
(await _lookupService.FindByUserNameAsync(_localTestData.John.UserName)).ShouldNotBeNull(); |
|||
(await _lookupService.FindByUserNameAsync(_localTestData.David.UserName)).ShouldNotBeNull(); |
|||
(await _lookupService.FindByUserNameAsync("undefined-user")).ShouldBeNull(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue