forked from MassTransit/MassTransit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FutureSagaDbContext and FutureStateMap to the EntityFrameworkCo…
…reIntegration package
- Loading branch information
Showing
12 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Persistence/MassTransit.EntityFrameworkCoreIntegration/FutureSagaDbContext.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,21 @@ | ||
namespace MassTransit.EntityFrameworkCoreIntegration | ||
{ | ||
using System.Collections.Generic; | ||
using Mappings; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
|
||
public class FutureSagaDbContext : | ||
SagaDbContext | ||
{ | ||
public FutureSagaDbContext(DbContextOptions options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
protected override IEnumerable<ISagaClassMap> Configurations | ||
{ | ||
get { yield return new FutureStateMap(); } | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Persistence/MassTransit.EntityFrameworkCoreIntegration/FutureStateMap.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,43 @@ | ||
namespace MassTransit.EntityFrameworkCoreIntegration | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Futures; | ||
using Mappings; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
|
||
public class FutureStateMap : | ||
SagaClassMap<FutureState> | ||
{ | ||
protected override void Configure(EntityTypeBuilder<FutureState> entity, ModelBuilder model) | ||
{ | ||
entity.Property(x => x.CurrentState); | ||
|
||
entity.Property(x => x.Created); | ||
entity.Property(x => x.Completed); | ||
entity.Property(x => x.Faulted); | ||
|
||
entity.Property(x => x.Location); | ||
|
||
entity.Property(x => x.Command).HasConversion(new JsonValueConverter<FutureMessage>()) | ||
.Metadata.SetValueComparer(new JsonValueComparer<FutureMessage>()); | ||
entity.Property(x => x.Pending) | ||
.HasConversion(new JsonValueConverter<HashSet<Guid>>()) | ||
.Metadata.SetValueComparer(new JsonValueComparer<HashSet<Guid>>()); | ||
entity.Property(x => x.Subscriptions) | ||
.HasConversion(new JsonValueConverter<HashSet<FutureSubscription>>()) | ||
.Metadata.SetValueComparer(new JsonValueComparer<HashSet<FutureSubscription>>()); | ||
entity.Property(x => x.Variables) | ||
.HasConversion(new JsonValueConverter<Dictionary<string, object>>()) | ||
.Metadata.SetValueComparer(new JsonValueComparer<Dictionary<string, object>>()); | ||
entity.Property(x => x.Results) | ||
.HasConversion(new JsonValueConverter<Dictionary<Guid, FutureMessage>>()) | ||
.Metadata.SetValueComparer(new JsonValueComparer<Dictionary<Guid, FutureMessage>>()); | ||
entity.Property(x => x.Faults) | ||
.HasConversion(new JsonValueConverter<Dictionary<Guid, FutureMessage>>()) | ||
.Metadata.SetValueComparer(new JsonValueComparer<Dictionary<Guid, FutureMessage>>()); | ||
} | ||
} | ||
} |
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
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
35 changes: 35 additions & 0 deletions
35
tests/MassTransit.EntityFrameworkCoreIntegration.Tests/FutureSagaDbContextFactory.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,35 @@ | ||
namespace MassTransit.EntityFrameworkCoreIntegration.Tests | ||
{ | ||
using System.Reflection; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using TestFramework; | ||
|
||
|
||
public class FutureSagaDbContextFactory : | ||
IDesignTimeDbContextFactory<FutureSagaDbContext> | ||
{ | ||
public FutureSagaDbContext CreateDbContext(string[] args) | ||
{ | ||
var builder = new DbContextOptionsBuilder(); | ||
|
||
Apply(builder); | ||
|
||
return new FutureSagaDbContext(builder.Options); | ||
} | ||
|
||
public static void Apply(DbContextOptionsBuilder builder) | ||
{ | ||
builder.UseSqlServer(LocalDbConnectionStringProvider.GetLocalDbConnectionString(), m => | ||
{ | ||
m.MigrationsAssembly(Assembly.GetExecutingAssembly().GetName().Name); | ||
m.MigrationsHistoryTable($"__{nameof(FutureSagaDbContext)}"); | ||
}); | ||
} | ||
|
||
public FutureSagaDbContext CreateDbContext(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
return new FutureSagaDbContext(optionsBuilder.Options); | ||
} | ||
} | ||
} |
167 changes: 167 additions & 0 deletions
167
tests/MassTransit.EntityFrameworkCoreIntegration.Tests/Future_Specs.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,167 @@ | ||
namespace MassTransit.EntityFrameworkCoreIntegration.Tests | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using ExtensionsDependencyInjectionIntegration; | ||
using Futures; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
using TestComponents; | ||
using TestComponents.ForkJoint.Tests; | ||
using TestComponents.Futures.Tests; | ||
using Turnout; | ||
|
||
|
||
class EntityFrameworkFutureTestFixtureConfigurator : | ||
IFutureTestFixtureConfigurator | ||
{ | ||
public void ConfigureFutureSagaRepository(IServiceCollectionBusConfigurator configurator) | ||
{ | ||
configurator.AddSagaRepository<FutureState>() | ||
.EntityFrameworkRepository(r => | ||
{ | ||
r.ConcurrencyMode = ConcurrencyMode.Pessimistic; | ||
r.LockStatementProvider = new SqlServerLockStatementProvider(); | ||
|
||
r.ExistingDbContext<FutureSagaDbContext>(); | ||
}); | ||
} | ||
|
||
public void ConfigureServices(IServiceCollection collection) | ||
{ | ||
collection.AddDbContext<FutureSagaDbContext>(builder => | ||
{ | ||
FutureSagaDbContextFactory.Apply(builder); | ||
}); | ||
} | ||
|
||
public async Task OneTimeSetup(IServiceProvider provider) | ||
{ | ||
using var scope = provider.CreateScope(); | ||
|
||
await using var context = scope.ServiceProvider.GetRequiredService<FutureSagaDbContext>(); | ||
|
||
await context.Database.MigrateAsync(); | ||
} | ||
|
||
public async Task OneTimeTearDown(IServiceProvider provider) | ||
{ | ||
using var scope = provider.CreateScope(); | ||
|
||
await using var context = scope.ServiceProvider.GetRequiredService<FutureSagaDbContext>(); | ||
|
||
await context.Database.EnsureDeletedAsync(); | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkFryFutureSpecs : | ||
FryFuture_Specs | ||
{ | ||
public EntityFrameworkFryFutureSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkShakeFutureSpecs : | ||
ShakeFuture_Specs | ||
{ | ||
public EntityFrameworkShakeFutureSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkFryShakeFutureSpecs : | ||
FryShakeFuture_Specs | ||
{ | ||
public EntityFrameworkFryShakeFutureSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkBurgerFutureSpecs : | ||
BurgerFuture_Specs | ||
{ | ||
public EntityFrameworkBurgerFutureSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkCalculateFutureSpecs : | ||
CalculateFuture_Specs | ||
{ | ||
public EntityFrameworkCalculateFutureSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkOrderFutureSpecs : | ||
OrderFuture_Specs | ||
{ | ||
public EntityFrameworkOrderFutureSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkComboFutureSpecs : | ||
ComboFuture_Specs | ||
{ | ||
public EntityFrameworkComboFutureSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkPriceCalculationFuture_Specs : | ||
PriceCalculationFuture_Specs | ||
{ | ||
public EntityFrameworkPriceCalculationFuture_Specs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkPriceCalculationFuture_RegistrationSpecs : | ||
PriceCalculationFuture_RegistrationSpecs | ||
{ | ||
public EntityFrameworkPriceCalculationFuture_RegistrationSpecs() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
|
||
|
||
[TestFixture] | ||
public class EntityFrameworkPriceCalculationFuture_Faulted : | ||
PriceCalculationFuture_Faulted | ||
{ | ||
public EntityFrameworkPriceCalculationFuture_Faulted() | ||
: base(new EntityFrameworkFutureTestFixtureConfigurator()) | ||
{ | ||
} | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
...eworkCoreIntegration.Tests/Migrations/FutureSagaDb/20210823121833_FutureTests.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.