-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32257bb
commit 74d392a
Showing
21 changed files
with
1,256 additions
and
26 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using TestExtensions; | ||
using Xunit; | ||
|
||
namespace Tester.EFCore; | ||
|
||
|
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,76 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Orleans.Persistence; | ||
using Orleans.Persistence.EntityFrameworkCore.SqlServer.Data; | ||
using Orleans.Reminders; | ||
using Orleans.Reminders.EntityFrameworkCore.SqlServer.Data; | ||
using Orleans.TestingHost; | ||
using TestExtensions; | ||
|
||
namespace Tester.EFCore; | ||
|
||
public class EFCoreFixture<TDbContext> : BaseTestClusterFixture where TDbContext : DbContext | ||
{ | ||
protected override void CheckPreconditionsOrThrow() => EFCoreTestUtils.CheckSqlServer(); | ||
|
||
protected override void ConfigureTestCluster(TestClusterBuilder builder) | ||
{ | ||
builder.Options.InitialSilosCount = 4; | ||
builder.AddSiloBuilderConfigurator<SiloConfigurator>(); | ||
} | ||
|
||
private class SiloConfigurator : ISiloConfigurator | ||
{ | ||
public void Configure(ISiloBuilder hostBuilder) | ||
{ | ||
var ctxTypeName = typeof(TDbContext).Name; | ||
var cs = $"Server=localhost,1433;Database=OrleansTests.{ctxTypeName};User Id=sa;Password=yourStrong(!)Password;TrustServerCertificate=True"; | ||
|
||
hostBuilder.Services.AddPooledDbContextFactory<TDbContext>(optionsBuilder => | ||
{ | ||
optionsBuilder.UseSqlServer(cs, opt => | ||
{ | ||
opt.MigrationsHistoryTable("__EFMigrationsHistory"); | ||
opt.MigrationsAssembly(typeof(TDbContext).Assembly.FullName); | ||
}); | ||
}); | ||
|
||
switch (ctxTypeName) | ||
{ | ||
case nameof(SqlServerGrainStateDbContext): | ||
hostBuilder | ||
.AddEntityFrameworkCoreSqlServerGrainStorage("GrainStorageForTest"); | ||
break; | ||
case nameof(SqlServerReminderDbContext): | ||
hostBuilder | ||
.UseEntityFrameworkCoreSqlServerReminderService(); | ||
break; | ||
} | ||
|
||
hostBuilder | ||
.AddMemoryGrainStorage("MemoryStore"); | ||
|
||
var sp = new ServiceCollection() | ||
.AddPooledDbContextFactory<TDbContext>(optionsBuilder => | ||
{ | ||
optionsBuilder.UseSqlServer(cs, opt => | ||
{ | ||
opt.MigrationsHistoryTable("__EFMigrationsHistory"); | ||
opt.MigrationsAssembly(typeof(TDbContext).Assembly.FullName); | ||
}); | ||
}).BuildServiceProvider(); | ||
|
||
var factory = sp.GetRequiredService<IDbContextFactory<TDbContext>>(); | ||
|
||
var ctx = factory.CreateDbContext(); | ||
if (ctx.Database.GetPendingMigrations().Any()) | ||
{ | ||
try | ||
{ | ||
ctx.Database.Migrate(); | ||
} | ||
catch { } | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.