123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using Luticate2.Auth.Controllers;
- using Luticate2.Auth.DataAccess;
- using Luticate2.Utils.DataAccess;
- using Luticate2.Utils.Interfaces;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.DependencyInjection;
-
- namespace TestAuth
- {
- public class DummyNotificationsBusiness : ILuNotificationsBusiness
- {
- public void Notify(string eventName, string entityType, object oldEntity, object newEntity)
- {
- }
- }
-
- 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.AddSingleton<ILuNotificationsBusiness, DummyNotificationsBusiness>();
- serviceCollection.AddLuticateAuth(dbo =>
- {
- dbo.Version = "tests";
- }, builder =>
- {
- builder.UseNpgsql(RealDbConnectionString);
- }, dbo =>
- {
- dbo.SecureCookies = false;
- });
- 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>());
- });
- }
- }
- }
|