- gRPC auth service for token validation - Value comparator system (string, numeric, boolean, datetime, collection) - Condition evaluator with strategy chain - Form definition and data improvements - Workflow instance/task endpoints updated - Seed data and EF design-time factory - Test coverage for comparators and handlers
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
using Workflow.Infrastructure.Persistence;
|
||
using Xunit;
|
||
|
||
namespace Workflow.Tests.Form;
|
||
|
||
/// <summary>
|
||
/// 表单模块测试夹具,提供 InMemory 数据库上下文及通用辅助方法。
|
||
/// 每个测试方法应使用独立的 database name 以确保数据隔离。
|
||
/// </summary>
|
||
public class FormTestFixture : IDisposable
|
||
{
|
||
/// <summary>
|
||
/// 创建一个独立的 InMemory WorkflowDbContext 实例。
|
||
/// 每次调用都使用新的 database name,确保测试之间互不干扰。
|
||
/// </summary>
|
||
public WorkflowDbContext CreateDbContext([System.Runtime.CompilerServices.CallerMemberName] string testName = "")
|
||
{
|
||
var options = new DbContextOptionsBuilder<WorkflowDbContext>()
|
||
.UseInMemoryDatabase(databaseName: $"WorkflowTest_{testName}_{Guid.NewGuid()}")
|
||
.Options;
|
||
|
||
return new WorkflowDbContext(options);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建一个已包含种子表单定义的 DbContext,用于需要已有数据的测试场景。
|
||
/// </summary>
|
||
public async Task<WorkflowDbContext> CreateDbContextWithSeedAsync(
|
||
string testName,
|
||
Action<WorkflowDbContext>? seedAction = null)
|
||
{
|
||
var db = CreateDbContext(testName);
|
||
|
||
if (seedAction is not null)
|
||
{
|
||
seedAction(db);
|
||
await db.SaveChangesAsync();
|
||
}
|
||
|
||
return db;
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
GC.SuppressFinalize(this);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// xUnit ClassFixture,用于在测试类级别共享 Fixture 实例。
|
||
/// </summary>
|
||
public class FormTestFixtureClassFixture : FormTestFixture;
|
||
|
||
/// <summary>
|
||
/// xUnit CollectionFixture,用于跨测试类共享 Fixture 实例。
|
||
/// </summary>
|
||
[CollectionDefinition("FormTests")]
|
||
public class FormTestCollection : ICollectionFixture<FormTestFixtureClassFixture>;
|