committed by
GitHub
23 changed files with 274 additions and 186 deletions
@ -1,12 +0,0 @@ |
|||||
namespace LINGYUN.Abp.Dapr.Actors |
|
||||
{ |
|
||||
public class AbpDaprActorOptions |
|
||||
{ |
|
||||
public DaprActorConfigurationDictionary RemoteActors { get; set; } |
|
||||
|
|
||||
public AbpDaprActorOptions() |
|
||||
{ |
|
||||
RemoteActors = new DaprActorConfigurationDictionary(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,24 +1,28 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.Configuration; |
||||
using Volo.Abp.Castle; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp.ExceptionHandling; |
using Volo.Abp.Http.Client; |
||||
using Volo.Abp.Modularity; |
using Volo.Abp.Modularity; |
||||
using Volo.Abp.MultiTenancy; |
|
||||
using Volo.Abp.Validation; |
|
||||
|
|
||||
namespace LINGYUN.Abp.Dapr.Actors |
namespace LINGYUN.Abp.Dapr.Actors |
||||
{ |
{ |
||||
[DependsOn( |
[DependsOn( |
||||
typeof(AbpCastleCoreModule), |
typeof(AbpHttpClientModule) |
||||
typeof(AbpMultiTenancyModule), |
|
||||
typeof(AbpValidationModule), |
|
||||
typeof(AbpExceptionHandlingModule) |
|
||||
)] |
)] |
||||
public class AbpDaprActorsModule : AbpModule |
public class AbpDaprActorsModule : AbpModule |
||||
{ |
{ |
||||
|
/// <summary>
|
||||
|
/// 与AbpHttpClient集成,创建一个命名HttpClient
|
||||
|
/// </summary>
|
||||
|
internal const string DaprHttpClient = "_AbpDaprActorsClient"; |
||||
|
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
{ |
{ |
||||
var configuration = context.Services.GetConfiguration(); |
var configuration = context.Services.GetConfiguration(); |
||||
Configure<AbpDaprActorOptions>(configuration); |
Configure<AbpDaprRemoteServiceOptions>(options => |
||||
|
{ |
||||
|
configuration.Bind(options); |
||||
|
}); |
||||
|
context.Services.AddHttpClient(DaprHttpClient); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,14 @@ |
|||||
|
using Volo.Abp.Http.Client; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Dapr.Actors |
||||
|
{ |
||||
|
public class AbpDaprRemoteServiceOptions |
||||
|
{ |
||||
|
public RemoteServiceConfigurationDictionary RemoteServices { get; set; } |
||||
|
|
||||
|
public AbpDaprRemoteServiceOptions() |
||||
|
{ |
||||
|
RemoteServices = new RemoteServiceConfigurationDictionary(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,21 +0,0 @@ |
|||||
using LINGYUN.Abp.Dapr.Actors.DynamicProxying; |
|
||||
|
|
||||
namespace LINGYUN.Abp.Dapr.Actors.Authentication |
|
||||
{ |
|
||||
public class DaprActorProxyAuthenticateContext |
|
||||
{ |
|
||||
public DaprHttpClientHandler Handler { get; } |
|
||||
public DaprActorConfiguration RemoteService { get; } |
|
||||
|
|
||||
public string RemoteServiceName { get; } |
|
||||
public DaprActorProxyAuthenticateContext( |
|
||||
DaprHttpClientHandler handler, |
|
||||
DaprActorConfiguration remoteService, |
|
||||
string remoteServiceName) |
|
||||
{ |
|
||||
Handler = handler; |
|
||||
RemoteService = remoteService; |
|
||||
RemoteServiceName = remoteServiceName; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,9 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
|
|
||||
namespace LINGYUN.Abp.Dapr.Actors.Authentication |
|
||||
{ |
|
||||
public interface IDaprActorProxyAuthenticator |
|
||||
{ |
|
||||
Task AuthenticateAsync(DaprActorProxyAuthenticateContext context); |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace LINGYUN.Abp.Dapr.Actors.Authentication |
|
||||
{ |
|
||||
[Dependency(TryRegister = true)] |
|
||||
public class NullDaprActorProxyAuthenticator : IDaprActorProxyAuthenticator, ISingletonDependency |
|
||||
{ |
|
||||
public Task AuthenticateAsync(DaprActorProxyAuthenticateContext context) |
|
||||
{ |
|
||||
return Task.CompletedTask; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,37 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace LINGYUN.Abp.Dapr.Actors |
|
||||
{ |
|
||||
public class DaprActorConfiguration : Dictionary<string, string> |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Base ActorId.
|
|
||||
/// </summary>
|
|
||||
public string ActorId |
|
||||
{ |
|
||||
get => this.GetOrDefault(nameof(ActorId)); |
|
||||
set => this[nameof(ActorId)] = value; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Base Url.
|
|
||||
/// </summary>
|
|
||||
public string BaseUrl |
|
||||
{ |
|
||||
get => this.GetOrDefault(nameof(BaseUrl)); |
|
||||
set => this[nameof(BaseUrl)] = value; |
|
||||
} |
|
||||
|
|
||||
public DaprActorConfiguration() |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public DaprActorConfiguration( |
|
||||
string actorId, |
|
||||
string baseUrl) |
|
||||
{ |
|
||||
this[nameof(ActorId)] = actorId; |
|
||||
this[nameof(BaseUrl)] = baseUrl; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,23 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
using Volo.Abp; |
|
||||
|
|
||||
namespace LINGYUN.Abp.Dapr.Actors |
|
||||
{ |
|
||||
public class DaprActorConfigurationDictionary : Dictionary<string, DaprActorConfiguration> |
|
||||
{ |
|
||||
public const string DefaultName = "Default"; |
|
||||
|
|
||||
public DaprActorConfiguration Default |
|
||||
{ |
|
||||
get => this.GetOrDefault(DefaultName); |
|
||||
set => this[DefaultName] = value; |
|
||||
} |
|
||||
|
|
||||
public DaprActorConfiguration GetConfigurationOrDefault(string name) |
|
||||
{ |
|
||||
return this.GetOrDefault(name) |
|
||||
?? Default |
|
||||
?? throw new AbpException($"Dapr service '{name}' was not found and there is no default configuration."); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,34 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net5.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
<IsPackable>false</IsPackable> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> |
||||
|
<PackageReference Include="xunit" Version="2.4.1" /> |
||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> |
||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
||||
|
<PrivateAssets>all</PrivateAssets> |
||||
|
</PackageReference> |
||||
|
<PackageReference Include="coverlet.collector" Version="1.3.0"> |
||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
||||
|
<PrivateAssets>all</PrivateAssets> |
||||
|
</PackageReference> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\modules\dapr\LINGYUN.Abp.Dapr.Actors\LINGYUN.Abp.Dapr.Actors.csproj" /> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Dapr.Tests\LINGYUN.Abp.Dapr.Tests.csproj" /> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Update="appsettings.Development.json"> |
||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
||||
|
</None> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,34 @@ |
|||||
|
using LINGYUN.Abp.Tests; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using System.Diagnostics; |
||||
|
using System.IO; |
||||
|
using System.Threading; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Dapr.Actors.Tests |
||||
|
{ |
||||
|
public class AbpDaprActorsTestBase : AbpTestsBase<AbpDaprActorsTestModule> |
||||
|
{ |
||||
|
// private Process _hostProcess;
|
||||
|
|
||||
|
//protected override void BeforeAddApplication(IServiceCollection services)
|
||||
|
//{
|
||||
|
// // TODO: 运行测试前先启动宿主进程 dapr run --app-id testdapr --app-port 5000 -H 10000 -- dotnet run --no-build
|
||||
|
// var workingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "../../../../LINGYUN.Abp.Dapr.AspNetCore.TestHost");
|
||||
|
// _hostProcess = Process.Start(new ProcessStartInfo
|
||||
|
// {
|
||||
|
// WorkingDirectory = workingDirectory,
|
||||
|
// FileName = "powershell",
|
||||
|
// Arguments = "dapr run --app-id testdapr --app-port 5000 -H 10000 -- dotnet run --no-build",
|
||||
|
// UseShellExecute = true
|
||||
|
// });
|
||||
|
|
||||
|
// // 等待.NET进程启动完毕
|
||||
|
// Thread.Sleep(15000);
|
||||
|
//}
|
||||
|
|
||||
|
//public override void Dispose()
|
||||
|
//{
|
||||
|
// _hostProcess?.CloseMainWindow();
|
||||
|
//}
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using LINGYUN.Abp.Tests; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using System.IO; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Dapr.Actors.Tests |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpDaprTestModule), |
||||
|
typeof(AbpTestsBaseModule), |
||||
|
typeof(AbpDaprActorsModule))] |
||||
|
public class AbpDaprActorsTestModule : AbpModule |
||||
|
{ |
||||
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.ReplaceConfiguration( |
||||
|
ConfigurationHelper.BuildConfiguration( |
||||
|
new AbpConfigurationBuilderOptions |
||||
|
{ |
||||
|
EnvironmentName = "Development", |
||||
|
BasePath = Directory.GetCurrentDirectory() |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddDaprActorProxies( |
||||
|
typeof(AbpDaprTestModule).Assembly, |
||||
|
"TestDapr"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using System.Threading.Tasks; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Dapr.Actors.Tests |
||||
|
{ |
||||
|
public class TestAppServiceTests : AbpDaprActorsTestBase |
||||
|
{ |
||||
|
private readonly ITestActor _actor; |
||||
|
|
||||
|
public TestAppServiceTests() |
||||
|
{ |
||||
|
_actor = GetRequiredService<ITestActor>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Get_Result_Items_Count_Should_5() |
||||
|
{ |
||||
|
var result = await _actor.GetAsync(); |
||||
|
|
||||
|
result.Count.ShouldBe(5); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Update_Result_Value_Should_Value_Updated_1() |
||||
|
{ |
||||
|
var result = await _actor.UpdateAsync(); |
||||
|
|
||||
|
result.Value.ShouldBe("value:updated:1"); |
||||
|
} |
||||
|
|
||||
|
public override void Dispose() |
||||
|
{ |
||||
|
_ = _actor.ClearAsync(); |
||||
|
base.Dispose(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Dapr |
||||
|
{ |
||||
|
[System.Serializable] |
||||
|
public class NameValue |
||||
|
{ |
||||
|
public string Key { get; set; } |
||||
|
public string Value { get; set; } |
||||
|
public NameValue() { } |
||||
|
public NameValue(string key, string value) |
||||
|
{ |
||||
|
Key = key; |
||||
|
Value = value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue