Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Tests.cs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using Luticate2.Auth.Controllers;
  3. using Luticate2.Auth.DataAccess;
  4. using Luticate2.Utils.DataAccess;
  5. using Microsoft.EntityFrameworkCore;
  6. using Microsoft.Extensions.DependencyInjection;
  7. namespace TestAuth
  8. {
  9. public class Tests
  10. {
  11. public const string RealDbConnectionString =
  12. "User ID=dev;Password=dev;Host=localhost;Port=5432;Database=luticate2;Pooling=true;";
  13. public static IServiceProvider BuildRealDbServiceProvider()
  14. {
  15. IServiceCollection serviceCollection = new ServiceCollection();
  16. serviceCollection.AddLuticateAuth(dbo =>
  17. {
  18. dbo.Version = "tests";
  19. }, builder =>
  20. {
  21. builder.UseNpgsql(RealDbConnectionString);
  22. });
  23. return serviceCollection.BuildServiceProvider();
  24. }
  25. protected static void _TestRealDb(Action<IServiceProvider> func)
  26. {
  27. var serviceProvider = BuildRealDbServiceProvider();
  28. var transactionScope = serviceProvider.GetService<LuEfTransactionScope>();
  29. transactionScope.BeginTransaction<LuAuthDatabaseContext>(null);
  30. try
  31. {
  32. func(serviceProvider);
  33. }
  34. finally
  35. {
  36. transactionScope.RollbackTransaction<LuAuthDatabaseContext>();
  37. }
  38. }
  39. public static void TestRealDb<TService>(Action<TService> func)
  40. {
  41. _TestRealDb(provider =>
  42. {
  43. func(provider.GetService<TService>());
  44. });
  45. }
  46. }
  47. }