2022-10-05 15:47:02 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
2022-01-09 11:46:27 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-06-20 12:43:59 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
2022-01-09 11:46:27 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Tests
|
|
|
|
|
{
|
|
|
|
|
internal static class TestHelpter
|
|
|
|
|
{
|
2022-06-20 12:43:59 +05:00
|
|
|
|
// Попробовать когда-нибудь https://github.com/MichalJankowskii/Moq.EntityFrameworkCore
|
|
|
|
|
|
2022-01-09 11:46:27 +05:00
|
|
|
|
public static AsbCloudDbContext MakeTestContext()
|
|
|
|
|
{
|
|
|
|
|
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
2022-06-20 12:43:59 +05:00
|
|
|
|
//.UseInMemoryDatabase(System.Guid.NewGuid().ToString())
|
|
|
|
|
//.ConfigureWarnings(configBuilder =>
|
|
|
|
|
// configBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning))
|
2022-01-09 11:46:27 +05:00
|
|
|
|
.UseNpgsql("Host=localhost;Database=tests;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True")
|
|
|
|
|
.Options;
|
|
|
|
|
var context = new AsbCloudDbContext(options);
|
2022-06-20 12:43:59 +05:00
|
|
|
|
//context.Database.EnsureDeleted();
|
2022-02-21 12:04:26 +05:00
|
|
|
|
context.Database.EnsureCreated();
|
2022-01-09 11:46:27 +05:00
|
|
|
|
return context;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|