123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using Luticate2.Auth.Controllers;
- using Luticate2.Auth.DataAccess;
- using Luticate2.Utils.DataAccess;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.DependencyInjection;
-
- namespace TestAuth
- {
- public class Tests
- {
- public const string RealDbConnectionString =
- "User ID=dev;Password=dev;Host=localhost;Port=5432;Database=luticate2;Pooling=true;";
-
- public static IServiceProvider BuildRealDbServiceProvider()
- {
- IServiceCollection serviceCollection = new ServiceCollection();
- serviceCollection.AddLuticateAuth(dbo =>
- {
- dbo.Version = "tests";
- }, builder =>
- {
- builder.UseNpgsql(RealDbConnectionString);
- });
- return serviceCollection.BuildServiceProvider();
- }
-
- protected static void _TestRealDb(Action<IServiceProvider> func)
- {
- var serviceProvider = BuildRealDbServiceProvider();
- var transactionScope = serviceProvider.GetService<LuEfTransactionScope>();
- transactionScope.BeginTransaction<LuAuthDatabaseContext>(null);
- try
- {
- func(serviceProvider);
- }
- finally
- {
- transactionScope.RollbackTransaction<LuAuthDatabaseContext>();
- }
- }
-
- public static void TestRealDb<TService>(Action<TService> func)
- {
- _TestRealDb(provider =>
- {
- func(provider.GetService<TService>());
- });
- }
- }
- }
|