first commit

This commit is contained in:
2025-09-08 14:15:45 +08:00
commit 0ecba9619f
622 changed files with 37941 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>KonSoft.Payment</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\KonSoft.Payment.Application\KonSoft.Payment.Application.csproj" />
<ProjectReference Include="..\KonSoft.Payment.Domain.Tests\KonSoft.Payment.Domain.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,9 @@
using Volo.Abp.Modularity;
namespace KonSoft.Payment;
public abstract class PaymentApplicationTestBase<TStartupModule> : PaymentTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
}

View File

@ -0,0 +1,12 @@
using Volo.Abp.Modularity;
namespace KonSoft.Payment;
[DependsOn(
typeof(PaymentApplicationModule),
typeof(PaymentDomainTestModule)
)]
public class PaymentApplicationTestModule : AbpModule
{
}

View File

@ -0,0 +1,34 @@
using Shouldly;
using System.Threading.Tasks;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Xunit;
namespace KonSoft.Payment.Samples;
/* This is just an example test class.
* Normally, you don't test code of the modules you are using
* (like IIdentityUserAppService here).
* Only test your own application services.
*/
public abstract class SampleAppServiceTests<TStartupModule> : PaymentApplicationTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IIdentityUserAppService _userAppService;
protected SampleAppServiceTests()
{
_userAppService = GetRequiredService<IIdentityUserAppService>();
}
[Fact]
public async Task Initial_Data_Should_Contain_Admin_User()
{
//Act
var result = await _userAppService.GetListAsync(new GetIdentityUsersInput());
//Assert
result.TotalCount.ShouldBeGreaterThan(0);
result.Items.ShouldContain(u => u.UserName == "admin");
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>KonSoft.Payment</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\KonSoft.Payment.Domain\KonSoft.Payment.Domain.csproj" />
<ProjectReference Include="..\KonSoft.Payment.TestBase\KonSoft.Payment.TestBase.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
using Volo.Abp.Modularity;
namespace KonSoft.Payment;
/* Inherit from this class for your domain layer tests. */
public abstract class PaymentDomainTestBase<TStartupModule> : PaymentTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
}

View File

@ -0,0 +1,12 @@
using Volo.Abp.Modularity;
namespace KonSoft.Payment;
[DependsOn(
typeof(PaymentDomainModule),
typeof(PaymentTestBaseModule)
)]
public class PaymentDomainTestModule : AbpModule
{
}

View File

@ -0,0 +1,46 @@
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Xunit;
namespace KonSoft.Payment.Samples;
/* This is just an example test class.
* Normally, you don't test code of the modules you are using
* (like IdentityUserManager here).
* Only test your own domain services.
*/
public abstract class SampleDomainTests<TStartupModule> : PaymentDomainTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IIdentityUserRepository _identityUserRepository;
private readonly IdentityUserManager _identityUserManager;
protected SampleDomainTests()
{
_identityUserRepository = GetRequiredService<IIdentityUserRepository>();
_identityUserManager = GetRequiredService<IdentityUserManager>();
}
[Fact]
public async Task Should_Set_Email_Of_A_User()
{
IdentityUser adminUser;
/* Need to manually start Unit Of Work because
* FirstOrDefaultAsync should be executed while db connection / context is available.
*/
await WithUnitOfWorkAsync(async () =>
{
adminUser = await _identityUserRepository
.FindByNormalizedUserNameAsync("ADMIN");
await _identityUserManager.SetEmailAsync(adminUser, "newemail@abp.io");
await _identityUserRepository.UpdateAsync(adminUser);
});
adminUser = await _identityUserRepository.FindByNormalizedUserNameAsync("ADMIN");
adminUser.Email.ShouldBe("newemail@abp.io");
}
}

View File

@ -0,0 +1,10 @@
using KonSoft.Payment.Samples;
using Xunit;
namespace KonSoft.Payment.EntityFrameworkCore.Applications;
[Collection(PaymentTestConsts.CollectionDefinitionName)]
public class EfCoreSampleAppServiceTests : SampleAppServiceTests<PaymentEntityFrameworkCoreTestModule>
{
}

View File

@ -0,0 +1,10 @@
using KonSoft.Payment.Samples;
using Xunit;
namespace KonSoft.Payment.EntityFrameworkCore.Domains;
[Collection(PaymentTestConsts.CollectionDefinitionName)]
public class EfCoreSampleDomainTests : SampleDomainTests<PaymentEntityFrameworkCoreTestModule>
{
}

View File

@ -0,0 +1,9 @@
using Xunit;
namespace KonSoft.Payment.EntityFrameworkCore;
[CollectionDefinition(PaymentTestConsts.CollectionDefinitionName)]
public class PaymentEntityFrameworkCoreCollection : ICollectionFixture<PaymentEntityFrameworkCoreFixture>
{
}

View File

@ -0,0 +1,9 @@
using KonSoft.Payment.EntityFrameworkCore;
using Xunit;
namespace KonSoft.Payment.EntityFrameworkCore;
public class PaymentEntityFrameworkCoreCollectionFixtureBase : ICollectionFixture<PaymentEntityFrameworkCoreFixture>
{
}

View File

@ -0,0 +1,11 @@
using System;
namespace KonSoft.Payment.EntityFrameworkCore;
public class PaymentEntityFrameworkCoreFixture : IDisposable
{
public void Dispose()
{
}
}

View File

@ -0,0 +1,8 @@
using Volo.Abp;
namespace KonSoft.Payment.EntityFrameworkCore;
public abstract class PaymentEntityFrameworkCoreTestBase : PaymentTestBase<PaymentEntityFrameworkCoreTestModule>
{
}

View File

@ -0,0 +1,82 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Sqlite;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.SettingManagement;
using Volo.Abp.Uow;
namespace KonSoft.Payment.EntityFrameworkCore;
[DependsOn(
typeof(PaymentApplicationTestModule),
typeof(PaymentEntityFrameworkCoreModule),
typeof(AbpEntityFrameworkCoreSqliteModule)
)]
public class PaymentEntityFrameworkCoreTestModule : AbpModule
{
private SqliteConnection? _sqliteConnection;
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<FeatureManagementOptions>(options =>
{
options.SaveStaticFeaturesToDatabase = false;
options.IsDynamicFeatureStoreEnabled = false;
});
Configure<PermissionManagementOptions>(options =>
{
options.SaveStaticPermissionsToDatabase = false;
options.IsDynamicPermissionStoreEnabled = false;
});
Configure<SettingManagementOptions>(options =>
{
options.SaveStaticSettingsToDatabase = false;
options.IsDynamicSettingStoreEnabled = false;
});
context.Services.AddAlwaysDisableUnitOfWorkTransaction();
ConfigureInMemorySqlite(context.Services);
}
private void ConfigureInMemorySqlite(IServiceCollection services)
{
_sqliteConnection = CreateDatabaseAndGetConnection();
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseSqlite(_sqliteConnection);
});
});
}
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
_sqliteConnection?.Dispose();
}
private static SqliteConnection CreateDatabaseAndGetConnection()
{
var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<PaymentDbContext>()
.UseSqlite(connection)
.Options;
using (var context = new PaymentDbContext(options))
{
context.GetService<IRelationalDatabaseCreator>().CreateTables();
}
return connection;
}
}

View File

@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Shouldly;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Xunit;
namespace KonSoft.Payment.EntityFrameworkCore.Samples;
/* This is just an example test class.
* Normally, you don't test ABP framework code
* (like default AppUser repository IRepository<AppUser, Guid> here).
* Only test your custom repository methods.
*/
[Collection(PaymentTestConsts.CollectionDefinitionName)]
public class SampleRepositoryTests : PaymentEntityFrameworkCoreTestBase
{
private readonly IRepository<IdentityUser, Guid> _appUserRepository;
public SampleRepositoryTests()
{
_appUserRepository = GetRequiredService<IRepository<IdentityUser, Guid>>();
}
[Fact]
public async Task Should_Query_AppUser()
{
/* Need to manually start Unit Of Work because
* FirstOrDefaultAsync should be executed while db connection / context is available.
*/
await WithUnitOfWorkAsync(async () =>
{
//Act
var adminUser = await (await _appUserRepository.GetQueryableAsync())
.Where(u => u.UserName == "admin")
.FirstOrDefaultAsync();
//Assert
adminUser.ShouldNotBeNull();
});
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>KonSoft.Payment</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\KonSoft.Payment.EntityFrameworkCore\KonSoft.Payment.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\KonSoft.Payment.Application.Tests\KonSoft.Payment.Application.Tests.csproj" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.Sqlite" Version="8.3.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,25 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Account;
using Volo.Abp.DependencyInjection;
namespace KonSoft.Payment.HttpApi.Client.ConsoleTestApp;
public class ClientDemoService : ITransientDependency
{
private readonly IProfileAppService _profileAppService;
public ClientDemoService(IProfileAppService profileAppService)
{
_profileAppService = profileAppService;
}
public async Task RunAsync()
{
var output = await _profileAppService.GetAsync();
Console.WriteLine($"UserName : {output.UserName}");
Console.WriteLine($"Email : {output.Email}");
Console.WriteLine($"Name : {output.Name}");
Console.WriteLine($"Surname : {output.Surname}");
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace KonSoft.Payment.HttpApi.Client.ConsoleTestApp;
public class ConsoleTestAppHostedService : IHostedService
{
private readonly IConfiguration _configuration;
public ConsoleTestAppHostedService(IConfiguration configuration)
{
_configuration = configuration;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = await AbpApplicationFactory.CreateAsync<PaymentConsoleApiClientModule>(options =>
{
options.Services.ReplaceConfiguration(_configuration);
options.UseAutofac();
}))
{
await application.InitializeAsync();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
await application.ShutdownAsync();
}
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}

View File

@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<Content Include="appsettings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="appsettings.secrets.json" />
<Content Include="appsettings.secrets.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Http.Client.IdentityModel" Version="8.3.4" />
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.4" />
<ProjectReference Include="..\..\src\KonSoft.Payment.HttpApi.Client\KonSoft.Payment.HttpApi.Client.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,30 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using Volo.Abp.Autofac;
using Volo.Abp.Http.Client;
using Volo.Abp.Http.Client.IdentityModel;
using Volo.Abp.Modularity;
namespace KonSoft.Payment.HttpApi.Client.ConsoleTestApp;
[DependsOn(
typeof(AbpAutofacModule),
typeof(PaymentHttpApiClientModule),
typeof(AbpHttpClientIdentityModelModule)
)]
public class PaymentConsoleApiClientModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpHttpClientBuilderOptions>(options =>
{
options.ProxyClientBuildActions.Add((remoteServiceName, clientBuilder) =>
{
clientBuilder.AddTransientHttpErrorPolicy(
policyBuilder => policyBuilder.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(2, i)))
);
});
});
}
}

View File

@ -0,0 +1,22 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace KonSoft.Payment.HttpApi.Client.ConsoleTestApp;
class Program
{
static async Task Main(string[] args)
{
await CreateHostBuilder(args).RunConsoleAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.AddAppSettingsSecretsJson()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
}

View File

@ -0,0 +1,17 @@
{
"RemoteServices": {
"Default": {
"BaseUrl": "https://localhost:44355"
}
},
"IdentityClients": {
"Default": {
"GrantType": "password",
"ClientId": "Payment_App",
"UserName": "admin",
"UserPassword": "1q2w3E*",
"Authority": "https://localhost:44355",
"Scope": "Payment"
}
}
}

View File

@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>KonSoft.Payment</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.TestBase" Version="8.3.4" />
<PackageReference Include="Volo.Abp.Autofac" Version="8.3.4" />
<PackageReference Include="Volo.Abp.Authorization" Version="8.3.4" />
<PackageReference Include="Volo.Abp.BackgroundJobs.Abstractions" Version="8.3.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,60 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Abp.Uow;
using Volo.Abp.Testing;
namespace KonSoft.Payment;
/* All test classes are derived from this class, directly or indirectly.
*/
public abstract class PaymentTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
{
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
}
protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func<Task> action)
{
using (var scope = ServiceProvider.CreateScope())
{
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
using (var uow = uowManager.Begin(options))
{
await action();
await uow.CompleteAsync();
}
}
}
protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
{
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
}
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
{
using (var scope = ServiceProvider.CreateScope())
{
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
using (var uow = uowManager.Begin(options))
{
var result = await func();
await uow.CompleteAsync();
return result;
}
}
}
}

View File

@ -0,0 +1,47 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Authorization;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace KonSoft.Payment;
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpTestBaseModule),
typeof(AbpAuthorizationModule),
typeof(AbpBackgroundJobsAbstractionsModule)
)]
public class PaymentTestBaseModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundJobOptions>(options =>
{
options.IsJobExecutionEnabled = false;
});
context.Services.AddAlwaysAllowAuthorization();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
SeedTestData(context);
}
private static void SeedTestData(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(async () =>
{
using (var scope = context.ServiceProvider.CreateScope())
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>()
.SeedAsync();
}
});
}
}

View File

@ -0,0 +1,6 @@
namespace KonSoft.Payment;
public static class PaymentTestConsts
{
public const string CollectionDefinitionName = "Payment collection";
}

View File

@ -0,0 +1,15 @@
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
namespace KonSoft.Payment;
public class PaymentTestDataSeedContributor : IDataSeedContributor, ITransientDependency
{
public Task SeedAsync(DataSeedContext context)
{
/* Seed additional test data... */
return Task.CompletedTask;
}
}

View File

@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Security.Claims;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims;
namespace KonSoft.Payment.Security;
[Dependency(ReplaceServices = true)]
public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
{
protected override ClaimsPrincipal GetClaimsPrincipal()
{
return GetPrincipal();
}
private ClaimsPrincipal GetPrincipal()
{
return new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
{
new Claim(AbpClaimTypes.UserId, "2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
new Claim(AbpClaimTypes.UserName, "admin"),
new Claim(AbpClaimTypes.Email, "admin@abp.io")
}));
}
}