chore 优化代码
This commit is contained in:
@ -5,5 +5,4 @@ namespace KonSoft.Admin;
|
||||
public abstract class AdminApplicationTestBase<TStartupModule> : AdminTestBase<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -8,5 +8,4 @@ namespace KonSoft.Admin;
|
||||
)]
|
||||
public class AdminApplicationTestModule : AbpModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
using Shouldly;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Volo.Abp.Identity;
|
||||
using Volo.Abp.Modularity;
|
||||
using Xunit;
|
||||
@ -31,4 +31,4 @@ public abstract class SampleAppServiceTests<TStartupModule> : AdminApplicationTe
|
||||
result.TotalCount.ShouldBeGreaterThan(0);
|
||||
result.Items.ShouldContain(u => u.UserName == "admin");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,5 +6,4 @@ namespace KonSoft.Admin;
|
||||
public abstract class AdminDomainTestBase<TStartupModule> : AdminTestBase<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -8,5 +8,4 @@ namespace KonSoft.Admin;
|
||||
)]
|
||||
public class AdminDomainTestModule : AbpModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -14,8 +14,8 @@ namespace KonSoft.Admin.Samples;
|
||||
public abstract class SampleDomainTests<TStartupModule> : AdminDomainTestBase<TStartupModule>
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
private readonly IIdentityUserRepository _identityUserRepository;
|
||||
private readonly IdentityUserManager _identityUserManager;
|
||||
private readonly IIdentityUserRepository _identityUserRepository;
|
||||
|
||||
protected SampleDomainTests()
|
||||
{
|
||||
@ -43,4 +43,4 @@ public abstract class SampleDomainTests<TStartupModule> : AdminDomainTestBase<TS
|
||||
adminUser = await _identityUserRepository.FindByNormalizedUserNameAsync("ADMIN");
|
||||
adminUser.Email.ShouldBe("newemail@abp.io");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,5 +5,4 @@ namespace KonSoft.Admin.EntityFrameworkCore;
|
||||
[CollectionDefinition(AdminTestConsts.CollectionDefinitionName)]
|
||||
public class AdminEntityFrameworkCoreCollection : ICollectionFixture<AdminEntityFrameworkCoreFixture>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
using KonSoft.Admin.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
using Xunit;
|
||||
|
||||
namespace KonSoft.Admin.EntityFrameworkCore;
|
||||
|
||||
public class AdminEntityFrameworkCoreCollectionFixtureBase : ICollectionFixture<AdminEntityFrameworkCoreFixture>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,5 @@ public class AdminEntityFrameworkCoreFixture : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,5 @@
|
||||
using Volo.Abp;
|
||||
|
||||
namespace KonSoft.Admin.EntityFrameworkCore;
|
||||
namespace KonSoft.Admin.EntityFrameworkCore;
|
||||
|
||||
public abstract class AdminEntityFrameworkCoreTestBase : AdminTestBase<AdminEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ namespace KonSoft.Admin.EntityFrameworkCore;
|
||||
typeof(AdminApplicationTestModule),
|
||||
typeof(AdminEntityFrameworkCoreModule),
|
||||
typeof(AbpEntityFrameworkCoreSqliteModule)
|
||||
)]
|
||||
)]
|
||||
public class AdminEntityFrameworkCoreTestModule : AbpModule
|
||||
{
|
||||
private SqliteConnection? _sqliteConnection;
|
||||
@ -51,10 +51,7 @@ public class AdminEntityFrameworkCoreTestModule : AbpModule
|
||||
|
||||
services.Configure<AbpDbContextOptions>(options =>
|
||||
{
|
||||
options.Configure(context =>
|
||||
{
|
||||
context.DbContextOptions.UseSqlite(_sqliteConnection);
|
||||
});
|
||||
options.Configure(context => { context.DbContextOptions.UseSqlite(_sqliteConnection); });
|
||||
});
|
||||
}
|
||||
|
||||
@ -79,4 +76,4 @@ public class AdminEntityFrameworkCoreTestModule : AbpModule
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,5 +6,4 @@ namespace KonSoft.Admin.EntityFrameworkCore.Applications;
|
||||
[Collection(AdminTestConsts.CollectionDefinitionName)]
|
||||
public class EfCoreSampleAppServiceTests : SampleAppServiceTests<AdminEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -6,5 +6,4 @@ namespace KonSoft.Admin.EntityFrameworkCore.Domains;
|
||||
[Collection(AdminTestConsts.CollectionDefinitionName)]
|
||||
public class EfCoreSampleDomainTests : SampleDomainTests<AdminEntityFrameworkCoreTestModule>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shouldly;
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shouldly;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Identity;
|
||||
using Xunit;
|
||||
@ -32,13 +32,13 @@ public class SampleRepositoryTests : AdminEntityFrameworkCoreTestBase
|
||||
*/
|
||||
await WithUnitOfWorkAsync(async () =>
|
||||
{
|
||||
//Act
|
||||
var adminUser = await (await _appUserRepository.GetQueryableAsync())
|
||||
//Act
|
||||
var adminUser = await (await _appUserRepository.GetQueryableAsync())
|
||||
.Where(u => u.UserName == "admin")
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
//Assert
|
||||
adminUser.ShouldNotBeNull();
|
||||
//Assert
|
||||
adminUser.ShouldNotBeNull();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,7 @@ namespace KonSoft.Admin.HttpApi.Client.ConsoleTestApp;
|
||||
typeof(AbpAutofacModule),
|
||||
typeof(AdminHttpApiClientModule),
|
||||
typeof(AbpHttpClientIdentityModelModule)
|
||||
)]
|
||||
)]
|
||||
public class AdminConsoleApiClientModule : AbpModule
|
||||
{
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
@ -21,10 +21,10 @@ public class AdminConsoleApiClientModule : AbpModule
|
||||
{
|
||||
options.ProxyClientBuildActions.Add((remoteServiceName, clientBuilder) =>
|
||||
{
|
||||
clientBuilder.AddTransientHttpErrorPolicy(
|
||||
policyBuilder => policyBuilder.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(2, i)))
|
||||
clientBuilder.AddTransientHttpErrorPolicy(policyBuilder =>
|
||||
policyBuilder.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(Math.Pow(2, i)))
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,4 +22,4 @@ public class ClientDemoService : ITransientDependency
|
||||
Console.WriteLine($"Name : {output.Name}");
|
||||
Console.WriteLine($"Surname : {output.Surname}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Volo.Abp;
|
||||
|
||||
namespace KonSoft.Admin.HttpApi.Client.ConsoleTestApp;
|
||||
@ -19,10 +19,10 @@ public class ConsoleTestAppHostedService : IHostedService
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
using (var application = await AbpApplicationFactory.CreateAsync<AdminConsoleApiClientModule>(options =>
|
||||
{
|
||||
options.Services.ReplaceConfiguration(_configuration);
|
||||
options.UseAutofac();
|
||||
}))
|
||||
{
|
||||
options.Services.ReplaceConfiguration(_configuration);
|
||||
options.UseAutofac();
|
||||
}))
|
||||
{
|
||||
await application.InitializeAsync();
|
||||
|
||||
@ -37,4 +37,4 @@ public class ConsoleTestAppHostedService : IHostedService
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,22 +1,23 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace KonSoft.Admin.HttpApi.Client.ConsoleTestApp;
|
||||
|
||||
class Program
|
||||
internal class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
await CreateHostBuilder(args).RunConsoleAsync();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||
{
|
||||
return Host.CreateDefaultBuilder(args)
|
||||
.AddAppSettingsSecretsJson()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddHostedService<ConsoleTestAppHostedService>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.Uow;
|
||||
using Volo.Abp.Testing;
|
||||
using Volo.Abp.Uow;
|
||||
|
||||
namespace KonSoft.Admin;
|
||||
|
||||
@ -43,7 +43,8 @@ public abstract class AdminTestBase<TStartupModule> : AbpIntegratedTest<TStartup
|
||||
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
|
||||
}
|
||||
|
||||
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options, Func<Task<TResult>> func)
|
||||
protected virtual async Task<TResult> WithUnitOfWorkAsync<TResult>(AbpUnitOfWorkOptions options,
|
||||
Func<Task<TResult>> func)
|
||||
{
|
||||
using (var scope = ServiceProvider.CreateScope())
|
||||
{
|
||||
@ -57,4 +58,4 @@ public abstract class AdminTestBase<TStartupModule> : AbpIntegratedTest<TStartup
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -14,15 +14,12 @@ namespace KonSoft.Admin;
|
||||
typeof(AbpTestBaseModule),
|
||||
typeof(AbpAuthorizationModule),
|
||||
typeof(AbpBackgroundJobsAbstractionsModule)
|
||||
)]
|
||||
)]
|
||||
public class AdminTestBaseModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpBackgroundJobOptions>(options =>
|
||||
{
|
||||
options.IsJobExecutionEnabled = false;
|
||||
});
|
||||
Configure<AbpBackgroundJobOptions>(options => { options.IsJobExecutionEnabled = false; });
|
||||
|
||||
context.Services.AddAlwaysAllowAuthorization();
|
||||
}
|
||||
@ -44,4 +41,4 @@ public class AdminTestBaseModule : AbpModule
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,4 +3,4 @@
|
||||
public static class AdminTestConsts
|
||||
{
|
||||
public const string CollectionDefinitionName = "Admin collection";
|
||||
}
|
||||
}
|
||||
@ -12,4 +12,4 @@ public class AdminTestDataSeedContributor : IDataSeedContributor, ITransientDepe
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -17,9 +17,9 @@ public class FakeCurrentPrincipalAccessor : ThreadCurrentPrincipalAccessor
|
||||
{
|
||||
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")
|
||||
new(AbpClaimTypes.UserId, "2e701e62-0953-4dd3-910b-dc6cc93ccb0d"),
|
||||
new(AbpClaimTypes.UserName, "admin"),
|
||||
new(AbpClaimTypes.Email, "admin@abp.io")
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user