Skip to content

Commit

Permalink
Merge pull request #29 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
Support for UnitOfWork
  • Loading branch information
Ali-YousefiTelori authored Aug 22, 2023
2 parents 98554f8 + 8813364 commit 10e9f2a
Show file tree
Hide file tree
Showing 28 changed files with 783 additions and 11 deletions.
23 changes: 23 additions & 0 deletions src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs
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

View workflow job for this annotation

GitHub Actions / os-tests

Theory method 'Get_EndpointsReturnSuccessAndCorrectContentType' on test class 'BasicTests' does not use parameter 'url'. Use the parameter, or remove the parameter and associated data. (https://xunit.net/xunit.analyzers/rules/xUnit1026)

Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs

View workflow job for this annotation

GitHub Actions / os-tests

Theory method 'Get_EndpointsReturnSuccessAndCorrectContentType' on test class 'BasicTests' does not use parameter 'url'. Use the parameter, or remove the parameter and associated data. (https://xunit.net/xunit.analyzers/rules/xUnit1026)

Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs

View workflow job for this annotation

GitHub Actions / os-tests

Theory method 'Get_EndpointsReturnSuccessAndCorrectContentType' on test class 'BasicTests' does not use parameter 'url'. Use the parameter, or remove the parameter and associated data. (https://xunit.net/xunit.analyzers/rules/xUnit1026)

Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs

View workflow job for this annotation

GitHub Actions / os-tests

Theory method 'Get_EndpointsReturnSuccessAndCorrectContentType' on test class 'BasicTests' does not use parameter 'url'. Use the parameter, or remove the parameter and associated data. (https://xunit.net/xunit.analyzers/rules/xUnit1026)

Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs

View workflow job for this annotation

GitHub Actions / os-tests

Theory method 'Get_EndpointsReturnSuccessAndCorrectContentType' on test class 'BasicTests' does not use parameter 'url'. Use the parameter, or remove the parameter and associated data. (https://xunit.net/xunit.analyzers/rules/xUnit1026)

Check warning on line 17 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/BasicTests.cs

View workflow job for this annotation

GitHub Actions / os-tests

Theory method 'Get_EndpointsReturnSuccessAndCorrectContentType' on test class 'BasicTests' does not use parameter 'url'. Use the parameter, or remove the parameter and associated data. (https://xunit.net/xunit.analyzers/rules/xUnit1026)
{
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>
32 changes: 32 additions & 0 deletions src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs
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

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
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
}
}
}
39 changes: 39 additions & 0 deletions src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Startup.cs
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>();
}
}
}
1 change: 1 addition & 0 deletions src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Usings.cs
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"
}
}
}
16 changes: 16 additions & 0 deletions src/CSharp/EasyMicroservices.Cores.AspCore.Tests/appsettings.json
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
Expand Up @@ -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>
Expand Down
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();
}
}
Loading

0 comments on commit 10e9f2a

Please sign in to comment.