-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing codegen issues for EF Core sagas. Closes GH-252
- Loading branch information
Jeremy D. Miller
authored and
Jeremy D. Miller
committed
Mar 17, 2023
1 parent
dbe4880
commit b74b38f
Showing
2 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/Persistence/PersistenceTests/EFCore/Bug_252_codegen_issue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using IntegrationTests; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Weasel.Core; | ||
using Weasel.SqlServer; | ||
using Weasel.SqlServer.Tables; | ||
using Wolverine; | ||
using Wolverine.EntityFrameworkCore; | ||
using Wolverine.SqlServer; | ||
using Wolverine.Tracking; | ||
using Xunit; | ||
|
||
namespace PersistenceTests.EFCore; | ||
|
||
[Collection("sqlserver")] | ||
public class Bug_252_codegen_issue | ||
{ | ||
[Fact] | ||
public async Task use_the_saga_type_to_determine_the_correct_DbContext_type() | ||
{ | ||
using var host = await Host.CreateDefaultBuilder() | ||
.UseWolverine(opt => | ||
{ | ||
opt.Services.AddDbContextWithWolverineIntegration<AppDbContext>(o => | ||
{ | ||
o.UseSqlServer(Servers.SqlServerConnectionString); | ||
}); | ||
|
||
opt.PersistMessagesWithSqlServer(Servers.SqlServerConnectionString); | ||
opt.UseEntityFrameworkCoreTransactions(); | ||
opt.Policies.UseDurableLocalQueues(); | ||
opt.Policies.AutoApplyTransactions(); | ||
}).StartAsync(); | ||
|
||
var table = new Table("OrderSagas"); | ||
table.AddColumn<Guid>("id").AsPrimaryKey(); | ||
await using var conn = new SqlConnection(Servers.SqlServerConnectionString); | ||
await conn.OpenAsync(); | ||
|
||
var migration = await SchemaMigration.DetermineAsync(conn, table); | ||
await new SqlServerMigrator().ApplyAllAsync(conn, migration, AutoCreate.All); | ||
|
||
var dbContext = host.Services.GetRequiredService<AppDbContext>(); | ||
await dbContext.Database.EnsureCreatedAsync(); | ||
|
||
await host.InvokeMessageAndWaitAsync(new OrderCreated(Guid.NewGuid())); | ||
} | ||
} | ||
|
||
public class AppDbContext : DbContext | ||
{ | ||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { } | ||
|
||
public DbSet<ProcessOrderSaga> OrderSagas { get; set; } | ||
} | ||
|
||
public record OrderCreated(Guid Id); | ||
|
||
public class ProcessOrderSaga : Saga | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public void Start(OrderCreated order) | ||
{ | ||
Id = order.Id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters