1234567891011121314151617181920212223242526 |
- using System;
- 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();
- var dbContext = (LuUtilsDbContext)serviceProvider.GetService(typeof(LuUtilsDbContext));
- func(serviceProvider);
- dbContext.pk_bigserial.RemoveRange(dbContext.pk_bigserial);
- dbContext.pk_guid.RemoveRange(dbContext.pk_guid);
- dbContext.SaveChanges();
- }
- }
- }
|