-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
Support for UnitOfWork
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.AspNetCore.TestHost; | ||
namespace EasyMicroservices.Cores.AspCore.Tests | ||
{ | ||
public class BasicTests | ||
{ | ||
protected TestServer _testServer; | ||
public BasicTests() | ||
{ | ||
var webBuilder = new WebHostBuilder(); | ||
webBuilder.UseStartup<Startup>(); | ||
|
||
_testServer = new TestServer(webBuilder); | ||
} | ||
|
||
[Theory] | ||
[InlineData("/")] | ||
public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url) | ||
Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs GitHub Actions / os-tests
Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs GitHub Actions / os-tests
Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs GitHub Actions / os-tests
Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs GitHub Actions / os-tests
Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs GitHub Actions / os-tests
Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs GitHub Actions / os-tests
|
||
{ | ||
var client = _testServer.CreateClient(); | ||
var data = await client.GetStringAsync($"api/user/getall"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using EasyMicroservices.Cores.AspCoreApi; | ||
using EasyMicroservices.Cores.Database.Interfaces; | ||
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Entities; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace EasyMicroservices.Cores.AspCore.Tests.Controllers | ||
{ | ||
public class UserController : SimpleQueryServiceController<UserEntity, UserEntity, UserEntity, UserEntity, long> | ||
{ | ||
public UserController(IContractLogic<UserEntity, UserEntity, UserEntity, UserEntity, long> contractLogic) : base(contractLogic) | ||
{ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net7.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<IsPackable>false</IsPackable> | ||
<GenerateProgramFile>false</GenerateProgramFile> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="EasyMicroservices.Tests" Version="0.0.0.3" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.10" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\EasyMicroservices.Cores.AspEntityFrameworkCoreApi\EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj" /> | ||
<ProjectReference Include="..\EasyMicroservices.Cores.Tests\EasyMicroservices.Cores.Tests.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'"> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing"> | ||
<Version>7.0.10</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi; | ||
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces; | ||
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; | ||
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Entities; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace EasyMicroservices.Cores.AspCore.Tests | ||
{ | ||
public class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs GitHub Actions / os-tests
Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs GitHub Actions / os-tests
Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs GitHub Actions / os-tests
Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs GitHub Actions / os-tests
Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs GitHub Actions / os-tests
Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs GitHub Actions / os-tests
|
||
{ | ||
var app = StartUpExtensions.Create<MyTestContext>(args); | ||
app.Services.Builder<MyTestContext>(); | ||
app.Services.AddScoped((serviceProvider) => new UnitOfWork(serviceProvider).GetContractLogic<UserEntity, UserEntity, UserEntity, UserEntity>()); | ||
app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService<IEntityFrameworkCoreDatabaseBuilder>())); | ||
app.Services.AddScoped<IEntityFrameworkCoreDatabaseBuilder>(serviceProvider => new DatabaseBuilder()); | ||
|
||
var build = app.Build<MyTestContext>(); | ||
build.MapControllers(); | ||
build.Run(); | ||
} | ||
} | ||
|
||
public class DatabaseBuilder : IEntityFrameworkCoreDatabaseBuilder | ||
{ | ||
public void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
optionsBuilder.UseInMemoryDatabase("Test DB"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"dotnetRunMessages": true, | ||
"applicationUrl": "http://localhost:4564" | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"ASPNETCORE_URLS": "http://localhost:4564" | ||
}, | ||
"dotnetRunMessages": true, | ||
"applicationUrl": "http://localhost:4564" | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
}, | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:21417", | ||
"sslPort": 44358 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi; | ||
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces; | ||
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; | ||
using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Entities; | ||
|
||
namespace EasyMicroservices.Cores.AspCore.Tests | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
UnitOfWork.DefaultUniqueIdentity = "1-2"; | ||
UnitOfWork.MicroserviceId = 1250; | ||
StartUpExtensions.Builder<MyTestContext>(services); | ||
services.AddScoped((serviceProvider) => new UnitOfWork(serviceProvider).GetContractLogic<UserEntity, UserEntity, UserEntity, UserEntity>()); | ||
services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService<IEntityFrameworkCoreDatabaseBuilder>())); | ||
services.AddScoped<IEntityFrameworkCoreDatabaseBuilder>(serviceProvider => new DatabaseBuilder()); | ||
|
||
//services.AddMvc().AddApplicationPart(typeof(UserController).Assembly).AddControllersAsServices(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.UseRouting(); | ||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
app.Build<MyTestContext>(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"local": "connection string" | ||
}, | ||
"RootAddresses": { | ||
"WhiteLabel": "http://localhost:1041" | ||
}, | ||
"AllowedHosts": "*", | ||
"Urls": "http://*:4564" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>0.0.0.19</Version> | ||
<Version>0.0.0.20</Version> | ||
<Description>asp core servces.</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>core,cores,base,database,services,asp,aspnet</PackageTags> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks> | ||
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>0.0.0.1</Version> | ||
<Description>asp core servces.</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>core,cores,base,database,services,asp,aspnet,aspcore,efcore</PackageTags> | ||
<PackageProjectUrl>https://github.com/EasyMicroservices/Cores</PackageProjectUrl> | ||
<LangVersion>latest</LangVersion> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.Cores.AspEntityFrameworkCoreApi.xml</DocumentationFile> | ||
<OpenApiGenerateDocumentsOnBuild>false</OpenApiGenerateDocumentsOnBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="0.0.0.5" /> | ||
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.3" /> | ||
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="0.0.0.2" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\EasyMicroservices.Cores.AspCoreApi\EasyMicroservices.Cores.AspCoreApi.csproj" /> | ||
<ProjectReference Include="..\EasyMicroservices.Cores.Relational.EntityFrameworkCore\EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using EasyMicroservices.Cores.Database.Interfaces; | ||
using EasyMicroservices.Cores.Relational.EntityFrameworkCore; | ||
using EasyMicroservices.Database.Interfaces; | ||
using EasyMicroservices.Mapper.Interfaces; | ||
using System; | ||
|
||
namespace EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IUnitOfWork : IDisposable, IAsyncDisposable | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
IDatabase GetDatabase(); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
IDatabase GetDatabase<TContext>() | ||
where TContext : RelationalCoreContext; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
IMapperProvider GetMapper(); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
IUniqueIdentityManager GetUniqueIdentityManager(); | ||
} | ||
} |