test:添加线程db单元测试
This commit is contained in:
110
Yi.Abp.Net8/test/Yi.Abp.Test/Demo/ThreadDb_Test.cs
Normal file
110
Yi.Abp.Net8/test/Yi.Abp.Test/Demo/ThreadDb_Test.cs
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Volo.Abp.Uow;
|
||||||
|
using Xunit;
|
||||||
|
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||||
|
using Yi.Framework.Rbac.Domain.Entities;
|
||||||
|
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
|
namespace Yi.Abp.Test.Demo
|
||||||
|
{
|
||||||
|
public class ThreadDb_Test : YiAbpTestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 并发
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Fact]
|
||||||
|
public async Task Repository_Test()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var rep = GetRequiredService<ISqlSugarRepository<UserAggregateRoot>>();
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
tasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await rep.GetListAsync();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
await Console.Out.WriteLineAsync("成功");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 工作单元
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Fact]
|
||||||
|
public async Task Uow_In_Test()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var rep = GetRequiredService<ISqlSugarRepository<UserAggregateRoot>>();
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
tasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
using (var uow = GetRequiredService<IUnitOfWorkManager>().Begin(true, true))
|
||||||
|
{
|
||||||
|
await rep.GetListAsync();
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
await Console.Out.WriteLineAsync("成功");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 工作单元
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Fact]
|
||||||
|
public async Task Uow_Out_Test()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var rep = GetRequiredService<ISqlSugarRepository<UserAggregateRoot>>();
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
using (var uow = GetRequiredService<IUnitOfWorkManager>().Begin(true, true))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
tasks.Add(Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await rep.GetListAsync();
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
await Console.Out.WriteLineAsync("成功");
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,15 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Remove="appsettings.Development.json" />
|
||||||
<None Remove="appsettings.json" />
|
<None Remove="appsettings.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="appsettings.Development.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||||
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||||
|
</Content>
|
||||||
<Content Include="appsettings.json">
|
<Content Include="appsettings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace Yi.Abp.Test
|
|||||||
protected virtual void ConfigureAppConfiguration(IConfigurationBuilder configurationBuilder)
|
protected virtual void ConfigureAppConfiguration(IConfigurationBuilder configurationBuilder)
|
||||||
{
|
{
|
||||||
configurationBuilder.AddJsonFile("appsettings.json");
|
configurationBuilder.AddJsonFile("appsettings.json");
|
||||||
//configurationBuilder.AddJsonFile("appsettings.Development.json");
|
configurationBuilder.AddJsonFile("appsettings.Development.json");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user