Skip to content

Commit

Permalink
Added FutureSagaDbContext and FutureStateMap to the EntityFrameworkCo…
Browse files Browse the repository at this point in the history
…reIntegration package
  • Loading branch information
phatboyg committed Aug 23, 2021
1 parent 6c45f8e commit 33b0c07
Show file tree
Hide file tree
Showing 12 changed files with 462 additions and 0 deletions.
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(); }
}
}
}
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>>());
}
}
}
5 changes: 5 additions & 0 deletions tests/MassTransit.Azure.Table.Tests/Future_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public async Task OneTimeSetup(IServiceProvider provider)
segment = await table.ExecuteQuerySegmentedAsync(query, segment.ContinuationToken);
}
}

public Task OneTimeTearDown(IServiceProvider provider)
{
return Task.CompletedTask;
}
}


Expand Down
5 changes: 5 additions & 0 deletions tests/MassTransit.Containers.Tests/Future_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public Task OneTimeSetup(IServiceProvider provider)
{
return Task.CompletedTask;
}

public Task OneTimeTearDown(IServiceProvider provider)
{
return Task.CompletedTask;
}
}


Expand Down
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 tests/MassTransit.EntityFrameworkCoreIntegration.Tests/Future_Specs.cs
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())
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ProjectReference Include="..\..\src\MassTransit\MassTransit.csproj" />
<ProjectReference Include="..\..\src\MassTransit.TestFramework\MassTransit.TestFramework.csproj" />
<ProjectReference Include="..\..\src\Scheduling\MassTransit.QuartzIntegration\MassTransit.QuartzIntegration.csproj" />
<ProjectReference Include="..\MassTransit.TestComponents\MassTransit.TestComponents.csproj" />
<ProjectReference Include="..\MassTransit.Tests\MassTransit.Tests.csproj" />
<ProjectReference Include="..\..\src\Persistence\MassTransit.EntityFrameworkCoreIntegration\MassTransit.EntityFrameworkCoreIntegration.csproj" />
</ItemGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 33b0c07

Please sign in to comment.