You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Tests.cs 1.0KB

1234567891011121314151617181920212223242526
  1. using System;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using TestUtils.DataAccess;
  5. namespace TestUtils
  6. {
  7. public class Tests
  8. {
  9. public const string ConnectionString =
  10. "User ID=dev;Password=dev;Host=localhost;Port=5432;Database=luticate2_utils;Pooling=true;";
  11. public static void TestRealDb(Action<IServiceProvider> func)
  12. {
  13. IServiceCollection serviceCollection = new ServiceCollection();
  14. serviceCollection.AddDbContext<LuUtilsDbContext>(builder => builder.UseNpgsql(ConnectionString),
  15. ServiceLifetime.Transient);
  16. var serviceProvider = serviceCollection.BuildServiceProvider();
  17. var dbContext = (LuUtilsDbContext)serviceProvider.GetService(typeof(LuUtilsDbContext));
  18. func(serviceProvider);
  19. dbContext.pk_bigserial.RemoveRange(dbContext.pk_bigserial);
  20. dbContext.pk_guid.RemoveRange(dbContext.pk_guid);
  21. dbContext.SaveChanges();
  22. }
  23. }
  24. }