Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Tests.cs 1.2KB

123456789101112131415161718192021222324252627282930313233
  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. try
  19. {
  20. func(serviceProvider);
  21. }
  22. finally
  23. {
  24. dbContext.pk_bigserial.RemoveRange(dbContext.pk_bigserial);
  25. dbContext.pk_guid.RemoveRange(dbContext.pk_guid);
  26. dbContext.SaveChanges();
  27. dbContext.Dispose();
  28. }
  29. }
  30. }
  31. }