fix web.api tests
This commit is contained in:
parent
7afc44abda
commit
0e6d5405d2
@ -33,7 +33,7 @@ public abstract class BaseStartup
|
||||
private const string BasicAuthScheme = "Basic";
|
||||
private const string MultiAuthSchemes = "MultiAuthSchemes";
|
||||
|
||||
private readonly IConfiguration _configuration;
|
||||
protected readonly IConfiguration _configuration;
|
||||
private readonly IHostEnvironment _hostEnvironment;
|
||||
|
||||
protected virtual JsonConverter[] Converters { get; }
|
||||
|
@ -15,6 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\migrations\mysql\ASC.Migrations.MySql.csproj" />
|
||||
<ProjectReference Include="..\..\..\web\ASC.Web.Api\ASC.Web.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -46,16 +46,15 @@ class ApiApplication : WebApplicationFactory<Program>
|
||||
builder.UseSetting(s.Key, s.Value);
|
||||
}
|
||||
|
||||
builder.ConfigureAppConfiguration((context, a) =>
|
||||
{
|
||||
(a.Sources[0] as ChainedConfigurationSource).Configuration["pathToConf"] = a.Build()["pathToConf"];
|
||||
});
|
||||
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddBaseDbContext<UserDbContext>();
|
||||
services.AddBaseDbContext<TenantDbContext>();
|
||||
services.AddBaseDbContext<WebstudioDbContext>();
|
||||
|
||||
var DIHelper = new ASC.Common.DIHelper();
|
||||
DIHelper.Configure(services);
|
||||
foreach (var a in Assembly.Load("ASC.Files").GetTypes().Where(r => r.IsAssignableTo<ControllerBase>()))
|
||||
foreach (var a in Assembly.Load("ASC.Web.Api").GetTypes().Where(r => r.IsAssignableTo<ControllerBase>()))
|
||||
{
|
||||
DIHelper.TryAdd(a);
|
||||
}
|
||||
@ -73,19 +72,18 @@ public class MySetUpClass
|
||||
[OneTimeSetUp]
|
||||
public void CreateDb()
|
||||
{
|
||||
var host = new ApiApplication(new Dictionary<string, string>
|
||||
var args = new Dictionary<string, string>
|
||||
{
|
||||
{ "pathToConf", Path.Combine("..","..", "..", "config") },
|
||||
{ "ConnectionStrings:default:connectionString", BaseApiTests.TestConnection },
|
||||
{ "migration:enabled", "true" },
|
||||
{ "core:products:folder", Path.Combine("..","..", "..", "products") },
|
||||
{ "web:hub::internal", "" }
|
||||
})
|
||||
.WithWebHostBuilder(builder =>
|
||||
{
|
||||
});
|
||||
|
||||
Migrate(host.Services);
|
||||
{ "web:hub::internal", "" },
|
||||
{ "disableLdapNotifyService", "true" }
|
||||
};
|
||||
|
||||
var host = new ApiApplication(args);
|
||||
Migrate(host.Services, "ASC.Migrations.MySql");
|
||||
|
||||
host = new ApiApplication(args);
|
||||
Migrate(host.Services, Assembly.GetExecutingAssembly().GetName().Name);
|
||||
|
||||
_scope = host.Services.CreateScope();
|
||||
@ -99,18 +97,21 @@ public class MySetUpClass
|
||||
}
|
||||
|
||||
|
||||
private void Migrate(IServiceProvider serviceProvider, string testAssembly = null)
|
||||
private void Migrate(IServiceProvider serviceProvider, string testAssembly )
|
||||
{
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
|
||||
var configuration = scope.ServiceProvider.GetService<IConfiguration>();
|
||||
configuration["testAssembly"] = testAssembly;
|
||||
|
||||
if (!string.IsNullOrEmpty(testAssembly))
|
||||
{
|
||||
var configuration = scope.ServiceProvider.GetService<IConfiguration>();
|
||||
configuration["testAssembly"] = testAssembly;
|
||||
}
|
||||
|
||||
using var db = scope.ServiceProvider.GetService<IDbContextFactory<UserDbContext>>().CreateDbContext();
|
||||
db.Database.Migrate();
|
||||
using var userDbContext = scope.ServiceProvider.GetService<UserDbContext>();
|
||||
userDbContext.Database.Migrate();
|
||||
|
||||
using var tenantDbContext = scope.ServiceProvider.GetService<TenantDbContext>();
|
||||
tenantDbContext.Database.Migrate();
|
||||
|
||||
using var webstudioDbContext = scope.ServiceProvider.GetService<WebstudioDbContext>();
|
||||
webstudioDbContext.Database.Migrate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,10 +132,10 @@ class BaseApiTests
|
||||
{
|
||||
var host = new ApiApplication(new Dictionary<string, string>
|
||||
{
|
||||
{ "pathToConf", Path.Combine("..","..", "..", "config") },
|
||||
{ "ConnectionStrings:default:connectionString", TestConnection },
|
||||
{ "migration:enabled", "true" },
|
||||
{ "web:hub:internal", "" }
|
||||
{ "web:hub:internal", "" },
|
||||
{ "disableLdapNotifyService", "true" }
|
||||
})
|
||||
.WithWebHostBuilder(a => { });
|
||||
|
||||
|
@ -28,7 +28,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ASC.Core.Common.Migrations;
|
||||
|
||||
public partial class TestMigration : Microsoft.EntityFrameworkCore.Migrations.Migration
|
||||
public partial class TestMigration : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
@ -41,8 +41,8 @@ public partial class TestMigration : Microsoft.EntityFrameworkCore.Migrations.Mi
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "core_user",
|
||||
columns: new[] { "id", "activation_status", "bithdate", "contacts", "culture", "email", "firstname", "last_modified", "lastname", "location", "notes", "phone", "phone_activation", "removed", "sex", "sid", "sso_name_id", "sso_session_id", "status", "tenant", "terminateddate", "title", "username", "workfromdate" },
|
||||
values: new object[] { "99223c7b-e3c9-11eb-9063-982cbc0ea1e5", 0, null, null, null, "test@gmail.com", "Test", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(2928), "User", null, null, null, 0, false, null, null, null, null, 1, 1, null, null, "TestUser", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(2940) });
|
||||
columns: new[] { "id", "activation_status", "bithdate", "contacts", "culture", "email", "firstname", "last_modified", "lastname", "location", "notes", "phone", "phone_activation", "removed", "sex", "sid", "sso_name_id", "sso_session_id", "status", "tenant", "terminateddate", "title", "username", "workfromdate", "create_on" },
|
||||
values: new object[] { "99223c7b-e3c9-11eb-9063-982cbc0ea1e5", 0, null, null, null, "test@gmail.com", "Test", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(2928), "User", null, null, null, 0, false, null, null, null, null, 1, 1, null, null, "TestUser", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(2940), DateTime.UtcNow });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "core_usersecurity",
|
||||
@ -69,4 +69,4 @@ public partial class TestMigration : Microsoft.EntityFrameworkCore.Migrations.Mi
|
||||
columns: new[] { "last_modified", "workfromdate" },
|
||||
values: new object[] { new DateTime(2021, 8, 3, 21, 35, 0, 522, DateTimeKind.Utc).AddTicks(6893), new DateTime(2021, 8, 3, 21, 35, 0, 522, DateTimeKind.Utc).AddTicks(5587) });
|
||||
}
|
||||
}
|
||||
}
|
@ -82,7 +82,6 @@ class WizardTest : BaseApiTests
|
||||
PasswordHash = passwordHash,
|
||||
Lng = lng,
|
||||
TimeZone = timeZone,
|
||||
Promocode = promocode,
|
||||
AmiId = amiid,
|
||||
SubscribeFromSite = subscribeFromSite
|
||||
};
|
||||
|
@ -39,8 +39,11 @@ public class Startup : BaseStartup
|
||||
{
|
||||
base.ConfigureServices(services);
|
||||
|
||||
services.AddHostedService<LdapNotifyService>();
|
||||
DIHelper.TryAdd<LdapNotifyService>();
|
||||
if (!_configuration.GetValue<bool>("disableLdapNotifyService"))
|
||||
{
|
||||
services.AddHostedService<LdapNotifyService>();
|
||||
DIHelper.TryAdd<LdapNotifyService>();
|
||||
}
|
||||
services.AddBaseDbContextPool<FilesDbContext>();
|
||||
services.AddBaseDbContextPool<BackupsContext>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user