| 123456789101112131415161718192021222324252627282930313233343536 | using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TestUtils.DataAccess;
namespace TestUtils
{
    public class Tests
    {
        public const string ConnectionString =
            "User ID=dev;Password=dev;Host=localhost;Port=5432;Database=luticate2_utils;Pooling=true;";
        public static void TestRealDb(Action<IServiceProvider> func)
        {
            IServiceCollection serviceCollection = new ServiceCollection();
            serviceCollection.AddDbContext<LuUtilsDbContext>(builder => builder.UseNpgsql(ConnectionString),
                ServiceLifetime.Transient);
            var serviceProvider = serviceCollection.BuildServiceProvider();
            try
            {
                func(serviceProvider);
            }
            finally
            {
                var dbContext = (LuUtilsDbContext)serviceProvider.GetService(typeof(LuUtilsDbContext));
                dbContext.pk_bigserial.RemoveRange(dbContext.pk_bigserial);
                dbContext.pk_guid.RemoveRange(dbContext.pk_guid);
                dbContext.fk_pk_guids.RemoveRange(dbContext.fk_pk_guids);
                dbContext.SaveChanges();
                dbContext.Dispose();
            }
        }
    }
}
 |