mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
Update test plugin with more data related functionality
This commit is contained in:
parent
316d39f24c
commit
a64b8fb310
@ -19,6 +19,7 @@ namespace BTCPayServer.Plugins.Test
|
||||
{
|
||||
services.AddSingleton<IUIExtension>(new UIExtension("TestExtensionNavExtension", "header-nav"));
|
||||
services.AddHostedService<ApplicationPartsLogger>();
|
||||
services.AddHostedService<TestPluginMigrationRunner>();
|
||||
services.AddSingleton<TestPluginService>();
|
||||
services.AddSingleton<TestPluginDbContextFactory>();
|
||||
services.AddDbContext<TestPluginDbContext>((provider, o) =>
|
||||
@ -27,13 +28,5 @@ namespace BTCPayServer.Plugins.Test
|
||||
factory.ConfigureBuilder(o);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Execute(IApplicationBuilder applicationBuilder, IServiceProvider applicationBuilderApplicationServices)
|
||||
{
|
||||
base.Execute(applicationBuilder, applicationBuilderApplicationServices);
|
||||
applicationBuilderApplicationServices.GetService<TestPluginDbContextFactory>().CreateContext().Database.Migrate();
|
||||
applicationBuilderApplicationServices.GetService<TestPluginService>().AddTestDataRecord().GetAwaiter().GetResult();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
BTCPayServer.Plugins.Test/TestPluginMigrationRunner.cs
Normal file
45
BTCPayServer.Plugins.Test/TestPluginMigrationRunner.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using BTCPayServer.Plugins.Test.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace BTCPayServer.Plugins.Test;
|
||||
|
||||
public class TestPluginMigrationRunner:IHostedService
|
||||
{
|
||||
public class TestPluginDataMigrationHistory
|
||||
{
|
||||
public bool UpdatedSomething { get; set; }
|
||||
}
|
||||
private readonly TestPluginDbContextFactory _testPluginDbContextFactory;
|
||||
private readonly ISettingsRepository _settingsRepository;
|
||||
private readonly TestPluginService _testPluginService;
|
||||
|
||||
public TestPluginMigrationRunner(TestPluginDbContextFactory testPluginDbContextFactory, ISettingsRepository settingsRepository, TestPluginService testPluginService)
|
||||
{
|
||||
_testPluginDbContextFactory = testPluginDbContextFactory;
|
||||
_settingsRepository = settingsRepository;
|
||||
_testPluginService = testPluginService;
|
||||
}
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var settings = await _settingsRepository.GetSettingAsync<TestPluginDataMigrationHistory>() ??
|
||||
new TestPluginDataMigrationHistory();
|
||||
await using var ctx = _testPluginDbContextFactory.CreateContext();
|
||||
await ctx.Database.MigrateAsync(cancellationToken: cancellationToken);
|
||||
if (!settings.UpdatedSomething)
|
||||
{
|
||||
await _testPluginService.AddTestDataRecord();
|
||||
settings.UpdatedSomething = true;
|
||||
await _settingsRepository.UpdateSetting(settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user