Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

39 řádky
1.1KB

  1. using Microsoft.AspNetCore.Hosting;
  2. using Microsoft.AspNetCore.Mvc.Testing;
  3. using Microsoft.Data.Sqlite;
  4. namespace CartWise.Web.Tests;
  5. public class CartWiseWebApplicationFactory : WebApplicationFactory<Program>
  6. {
  7. private readonly string _dbPath = Path.Combine(Path.GetTempPath(), $"cartwise-tests-{Guid.NewGuid():N}.db");
  8. protected override void ConfigureWebHost(IWebHostBuilder builder)
  9. {
  10. builder.UseEnvironment("Development");
  11. builder.UseSetting("ConnectionStrings:DefaultConnection", $"Data Source={_dbPath}");
  12. }
  13. protected override void Dispose(bool disposing)
  14. {
  15. base.Dispose(disposing);
  16. if (!disposing)
  17. {
  18. return;
  19. }
  20. // Release SQLite's pooled native handles before deleting the temp file, or the delete fails while the
  21. // process still holds the file open.
  22. SqliteConnection.ClearAllPools();
  23. foreach (var path in new[] { _dbPath, $"{_dbPath}-shm", $"{_dbPath}-wal" })
  24. {
  25. if (File.Exists(path))
  26. {
  27. File.Delete(path);
  28. }
  29. }
  30. }
  31. }

Powered by TurnKey Linux.