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.
 
 
 
 

45 rivejä
1.5 KiB

  1. using Api;
  2. using AutoMapper;
  3. using Core.Db;
  4. using Core.Repository;
  5. using Domain.Identity;
  6. using Microsoft.AspNetCore.Mvc.Testing;
  7. using Microsoft.EntityFrameworkCore;
  8. using Microsoft.Extensions.Configuration;
  9. using Moq;
  10. using Services.Identity;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using Xunit;
  17. namespace Tests
  18. {
  19. public class BaseTest : IClassFixture<WebApplicationFactory<Program>>
  20. {
  21. public WebApplicationFactory<Program> _factory;
  22. public HttpClient _client;
  23. public PanakDbContext _dbContext;
  24. public BaseTest(WebApplicationFactory<Program> factory)
  25. {
  26. _factory = factory.WithWebHostBuilder(builder => builder.ConfigureServices(services =>
  27. {
  28. var dbContextOptions = services.SingleOrDefault(service => service.ServiceType == typeof(DbContextOptions<PanakDbContext>));
  29. services.Remove(dbContextOptions);
  30. services.AddDbContext<PanakDbContext>(options => options.UseInMemoryDatabase("PanakDb"));
  31. }).UseKestrel().UseSetting("https_port", "8080"));
  32. _client = _factory.CreateClient(new WebApplicationFactoryClientOptions
  33. {
  34. AllowAutoRedirect = false
  35. });
  36. var scope = factory.Services.GetService<IServiceScopeFactory>()!.CreateScope();
  37. _dbContext = scope.ServiceProvider.GetService<PanakDbContext>();
  38. }
  39. }
  40. }