-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29c5864
commit 9354699
Showing
10 changed files
with
179 additions
and
119 deletions.
There are no files selected for viewing
40 changes: 20 additions & 20 deletions
40
Oibi.Repository.Demo.Models/Oibi.Repository.Demo.Models.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.4" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" /> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" /> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Oibi.Repository\Oibi.Repository.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Oibi.Repository\Oibi.Repository.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Oibi.Repository.Demo.Models\Oibi.Repository.Demo.Models.csproj" /> | ||
<ProjectReference Include="..\Oibi.Repository\Oibi.Repository.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Oibi.Repository.Demo.Models\Oibi.Repository.Demo.Models.csproj" /> | ||
<ProjectReference Include="..\Oibi.Repository\Oibi.Repository.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AspNetCore.RouteAnalyzer" Version="0.5.3" /> | ||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" /> | ||
<PackageReference Include="IDisposableAnalyzers" Version="4.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.5" /> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AspNetCore.RouteAnalyzer" Version="0.5.3" /> | ||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> | ||
<PackageReference Include="IDisposableAnalyzers" Version="4.0.7"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" /> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
using Oibi.Repository.Abstracts; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking; | ||
using Oibi.Repository.Abstracts; | ||
using Oibi.Repository.Demo.Models; | ||
using System; | ||
|
||
namespace Oibi.Repository.Demo.Repositories | ||
{ | ||
/// <summary> | ||
/// Repositories scope | ||
/// </summary> | ||
public class LibraryDbScope : DbContextScope<LibraryContext> | ||
{ | ||
public LibraryDbScope(LibraryContext context, BookRepository bookRepository, AuthorRepository authorRepository) : base(context) | ||
{ | ||
BookRepository = bookRepository; | ||
AuthorRepository = authorRepository; | ||
} | ||
/// <summary> | ||
/// Repositories scope | ||
/// </summary> | ||
public class LibraryDbScope : DbContextScope<LibraryContext> | ||
{ | ||
public LibraryDbScope(LibraryContext context, BookRepository bookRepository, AuthorRepository authorRepository) : base(context) | ||
{ | ||
BookRepository = bookRepository; | ||
AuthorRepository = authorRepository; | ||
|
||
public BookRepository BookRepository { get; } | ||
public AuthorRepository AuthorRepository { get; } | ||
} | ||
context.ChangeTracker.Tracked += ChangeTracker_Tracked; | ||
} | ||
|
||
private void ChangeTracker_StateChanged(object sender, EntityStateChangedEventArgs e) | ||
{ | ||
var student = e.Entry.Entity; | ||
// e.Entry.State | ||
} | ||
|
||
private void ChangeTracker_Tracked(object sender, EntityTrackedEventArgs e) | ||
{ | ||
// create dto: state, context, entity ? | ||
var entity = e.Entry.Entity; | ||
//throw new NotImplementedException(); | ||
} | ||
|
||
|
||
public BookRepository BookRepository { get; } | ||
public AuthorRepository AuthorRepository { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Oibi.Repository.Demo; | ||
using Oibi.Repository.Demo.Repositories; | ||
using Oibi.TestHelper; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Oibi.Repository.Tests; | ||
|
||
public class DatabaseConnectionTest : IClassFixture<ServerFixture<Startup>> | ||
{ | ||
private readonly ServerFixture<Startup> _serverFixture; | ||
private readonly LibraryDbScope _libraryScope; | ||
|
||
public DatabaseConnectionTest(ServerFixture<Startup> serverFixture) | ||
{ | ||
_serverFixture = serverFixture; | ||
_libraryScope = _serverFixture.GetService<LibraryDbScope>(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestDatabaseConnection() | ||
{ | ||
Exception connectionException = null; | ||
|
||
try | ||
{ | ||
// Tentativo di eseguire una semplice operazione di lettura dal database. | ||
var count = await _libraryScope.BookRepository.CountAsync(); | ||
Assert.True(count >= 0, "Connessione al database riuscita e conteggio libri ottenuto."); | ||
} | ||
catch (Exception ex) | ||
{ | ||
connectionException = ex; | ||
Assert.Fail(ex.Message); | ||
} | ||
|
||
Assert.Null(connectionException); // Assicurati che non ci siano eccezioni, indicando problemi di connessione. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="appsettings.tests.json" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Remove="appsettings.test.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="appsettings.tests.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
</Content> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="appsettings.test.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="Oibi.TestHelper" Version="6.0.8" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="Oibi.TestHelper" Version="8.0.0" /> | ||
<PackageReference Include="xunit" Version="2.6.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Oibi.Repository.Demo\Oibi.Repository.Demo.csproj" /> | ||
<ProjectReference Include="..\Oibi.Repository\Oibi.Repository.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Oibi.Repository.Demo\Oibi.Repository.Demo.csproj" /> | ||
<ProjectReference Include="..\Oibi.Repository\Oibi.Repository.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Authors>[email protected]</Authors> | ||
<Description>Generic repository base pattern for EF Core + DatabaseScope</Description> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Authors>[email protected]</Authors> | ||
<Description>Generic repository base pattern for EF Core + DatabaseScope</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Meziantou.Analyzer" Version="2.0.20"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.4" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Meziantou.Analyzer" Version="2.0.120"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageProjectUrl>https://github.com/TheTrigger/Oibi.Repository</PackageProjectUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/TheTrigger/Oibi.Repository</RepositoryUrl> | ||
<PackageTags>repository, pattern, aspnetcore, efcore, scope</PackageTags> | ||
<PackageReleaseNotes></PackageReleaseNotes> | ||
<PackageIconUrl>https://image.flaticon.com/icons/svg/2232/2232243.svg</PackageIconUrl> | ||
<Version>7.0.4</Version> | ||
<Company>oibi.dev</Company> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<UserSecretsId>320f5e09-36cb-4c5b-8f02-72cbf1003ad1</UserSecretsId> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageProjectUrl>https://github.com/TheTrigger/Oibi.Repository</PackageProjectUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/TheTrigger/Oibi.Repository</RepositoryUrl> | ||
<PackageTags>repository, pattern, aspnetcore, efcore, scope</PackageTags> | ||
<PackageReleaseNotes></PackageReleaseNotes> | ||
<PackageIconUrl>https://image.flaticon.com/icons/svg/2232/2232243.svg</PackageIconUrl> | ||
<Version>8.0.0</Version> | ||
<Company>oibi.dev</Company> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<UserSecretsId>320f5e09-36cb-4c5b-8f02-72cbf1003ad1</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
</Project> |