1 |
fad0afca
|
Dominik Chlouba
|
using ExtCore.Data.Abstractions;
|
2 |
|
|
using ExtCore.Data.EntityFramework;
|
3 |
|
|
using Leuze.Core.Application.Identity;
|
4 |
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
5 |
|
|
using Microsoft.EntityFrameworkCore;
|
6 |
|
|
using Microsoft.Extensions.DependencyInjection;
|
7 |
|
|
using Microsoft.Extensions.Logging;
|
8 |
|
|
using System;
|
9 |
|
|
|
10 |
|
|
namespace Leuze.Tests.Configuration
|
11 |
|
|
{
|
12 |
|
|
/// <summary>
|
13 |
|
|
///
|
14 |
|
|
/// </summary>
|
15 |
|
|
public class TestingStorageContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid, ApplicationUserClaim, ApplicationUserRole,
|
16 |
|
|
ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>, IStorageContext
|
17 |
|
|
{
|
18 |
|
|
|
19 |
|
|
/// <summary>
|
20 |
|
|
///
|
21 |
|
|
/// </summary>
|
22 |
|
|
public DbSet<ApplicationPermission> Permissions { get; set; } = null!;
|
23 |
|
|
|
24 |
|
|
/// <summary>
|
25 |
|
|
///
|
26 |
|
|
/// </summary>
|
27 |
|
|
/// <param name="options_"></param>
|
28 |
|
|
public TestingStorageContext(DbContextOptions<TestingStorageContext> options_) : base(options_) { }
|
29 |
|
|
|
30 |
|
|
/// <summary>
|
31 |
|
|
///
|
32 |
|
|
/// </summary>
|
33 |
|
|
/// <param name="optionsBuilder"></param>
|
34 |
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
35 |
|
|
{
|
36 |
|
|
#if DEBUG
|
37 |
|
|
base.OnConfiguring(optionsBuilder.EnableSensitiveDataLogging().UseLoggerFactory(GetLoggerFactory()));
|
38 |
|
|
#endif
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
/// <summary>
|
42 |
|
|
///
|
43 |
|
|
/// </summary>
|
44 |
|
|
/// <param name="modelBuilder"></param>
|
45 |
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
46 |
|
|
{
|
47 |
|
|
base.OnModelCreating(modelBuilder);
|
48 |
|
|
this.RegisterEntities(modelBuilder);
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
private ILoggerFactory GetLoggerFactory()
|
52 |
|
|
{
|
53 |
|
|
IServiceCollection serviceCollection = new ServiceCollection();
|
54 |
|
|
serviceCollection.AddLogging(builder =>
|
55 |
|
|
builder.AddFilter(DbLoggerCategory.Database.Command.Name, LogLevel.Debug));
|
56 |
|
|
return serviceCollection.BuildServiceProvider().GetService<ILoggerFactory>()!;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
}
|
60 |
|
|
}
|