using Elsa.Common.Multitenancy;
using Elsa.Common.Services;
using Elsa.Labels.Contracts;
using Elsa.Labels.Entities;
using Elsa.Labels.Services;
using Elsa.Persistence.EFCore;
using Elsa.Persistence.EFCore.EntityHandlers;
using Elsa.Persistence.EFCore.Extensions;
using Elsa.Persistence.EFCore.Modules.Labels;
using Elsa.Persistence.EFCore.Sqlite;
using Elsa.Tenants.Options;
using Elsa.Testing.Shared.Multitenancy;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Labels.Persistence.ConformanceTests;
///
/// Holds one InMemory or EF/SQLite pair of Labels stores and the ambient tenant they read.
///
public sealed class LabelStoreScenario(
TestTenantAccessor tenantAccessor,
ILabelStore labels,
IWorkflowDefinitionLabelStore associations,
IWorkflowDefinitionLabelQuery associationQuery,
Func, Task> assertUniquenessConflictAsync,
Func disposeAsync) : IAsyncDisposable
{
public TestTenantAccessor TenantAccessor { get; } = tenantAccessor;
public ILabelStore Labels { get; } = labels;
public IWorkflowDefinitionLabelStore Associations { get; } = associations;
public IWorkflowDefinitionLabelQuery AssociationQuery { get; } = associationQuery;
public IDisposable UseTenant(string tenantId) =>
TenantAccessor.PushContext(tenantId == Tenant.DefaultTenantId
? Tenant.Default
: new Tenant { Id = tenantId, Name = tenantId });
public Task AssertUniquenessConflictAsync(Func operation) => assertUniquenessConflictAsync(operation);
public ValueTask DisposeAsync() => disposeAsync();
public static Task CreateInMemoryAsync()
{
var tenantAccessor = new TestTenantAccessor("tenant-a");
var labels = new MemoryStore