-
Notifications
You must be signed in to change notification settings - Fork 22
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
2dd82e7
commit baca5a5
Showing
12 changed files
with
173 additions
and
18 deletions.
There are no files selected for viewing
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ork/Options/DelegateModelConfiguration.cs → ...ork/Options/DelegateModelConfiguration.cs
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
2 changes: 1 addition & 1 deletion
2
...yFramework/Options/IModelConfiguration.cs → ...yFramework/Options/IModelConfiguration.cs
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
2 changes: 1 addition & 1 deletion
2
...ntityFramework/Options/ModelCustomizer.cs → ...ntityFramework/Options/ModelCustomizer.cs
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
2 changes: 1 addition & 1 deletion
2
...ptions/ModelDbContextOptionsExtensions.cs → ...ptions/ModelDbContextOptionsExtensions.cs
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
2 changes: 1 addition & 1 deletion
2
...ns/ModelDbContextOptionsExtensionsInfo.cs → ...ns/ModelDbContextOptionsExtensionsInfo.cs
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,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>13</LangVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Version>$(Version)</Version> | ||
<Authors>Leonardo Porro</Authors> | ||
<Company /> | ||
<Product>Detached</Product> | ||
<Description>A general purpose object-oriented mapper.</Description> | ||
<Copyright>2017</Copyright> | ||
<PackageProjectUrl>https://github.com/leonardoporro/Detached</PackageProjectUrl> | ||
<PackageLicenseExpression>(LGPL-2.0-only WITH FLTK-exception OR Apache-2.0+)</PackageLicenseExpression> | ||
<NeutralLanguage /> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<PackageIcon>logo.png</PackageIcon> | ||
<PackageId>Detached.Mappers.EntityFramework</PackageId> | ||
<PackageReadmeFile>Readme.MD</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\logo.png" Link="logo.png"> | ||
<PackagePath></PackagePath> | ||
<Pack>True</Pack> | ||
</None> | ||
<None Include="..\..\Readme.MD" Link="Readme.MD"> | ||
<PackagePath>\</PackagePath> | ||
<Pack>True</Pack> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
71 changes: 71 additions & 0 deletions
71
test/Detached.Models.EntityFramework.Tests/ConfigureModelTests.cs
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,71 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Detached.Models.EntityFramework.Tests | ||
{ | ||
public class ConfigureModelTests | ||
{ | ||
[Fact] | ||
public void DbContext_ConfigureModel_Success() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddDbContext<TestDbContext>((services, options) => | ||
{ | ||
options.UseSqlite($"DataSource=file:test_configure_model?mode=memory&cache=shared"); | ||
options.UseModel(services); | ||
}); | ||
|
||
services.ConfigureModel<TestDbContext>((model, dbContext) => | ||
{ | ||
model.Entity<Entity1>().HasKey(e => e.Id1); | ||
}); | ||
|
||
services.ConfigureModel<TestDbContext>((model, dbContext) => | ||
{ | ||
model.Entity<Entity2>().HasKey(e => e.Id2); | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var dbContext = serviceProvider.GetRequiredService<TestDbContext>(); | ||
dbContext.Database.EnsureCreated(); | ||
dbContext.Set<Entity1>().Add(new Entity1 { Id1 = 1, Name = "Entity 1" }); | ||
dbContext.Set<Entity2>().Add(new Entity2 { Id2 = 2, Name = "Entity 2" }); | ||
|
||
dbContext.SaveChanges(); | ||
|
||
var entity1 = dbContext.Find<Entity1>(1); | ||
var entity2 = dbContext.Find<Entity2>(2); | ||
|
||
Assert.NotNull(entity1); | ||
Assert.Equal("Entity 1", entity1.Name); | ||
|
||
Assert.NotNull(entity2); | ||
Assert.Equal("Entity 2", entity2.Name); | ||
} | ||
} | ||
|
||
public class TestDbContext : DbContext | ||
{ | ||
public TestDbContext(DbContextOptions<TestDbContext> options) | ||
: base(options) | ||
{ | ||
} | ||
} | ||
|
||
public class Entity1 | ||
{ | ||
public int Id1 { get; set; } | ||
|
||
public string Name { get; set; } | ||
} | ||
|
||
public class Entity2 | ||
{ | ||
public int Id2 { get; set; } | ||
|
||
public string Name { get; set; } | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
test/Detached.Models.EntityFramework.Tests/Detached.Models.EntityFramework.Tests.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Detached.Models.EntityFramework\Detached.Models.EntityFramework.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> | ||
<PackageReference Include="xunit" Version="2.9.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Fixture\" /> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |