123456789101112131415161718192021222324252627282930313233 |
- 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));
- try
- {
- func(serviceProvider);
- }
- finally
- {
- dbContext.pk_bigserial.RemoveRange(dbContext.pk_bigserial);
- dbContext.pk_guid.RemoveRange(dbContext.pk_guid);
- dbContext.SaveChanges();
- dbContext.Dispose();
- }
- }
- }
- }
|