Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build/build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ class Build : NukeBuild
Solution.Transports.GCP.Wolverine_Pubsub,
Solution.Persistence.Wolverine_RDBMS,
Solution.Persistence.Wolverine_Postgresql,
Solution.Persistence.Wolverine_EntityFrameworkCore,
Solution.Persistence.Wolverine_Marten,
Solution.Persistence.Wolverine_RavenDb,
Solution.Persistence.Wolverine_SqlServer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task MyBug()
})
.StartAsync();

var session = await host.TrackActivity().DoNotAssertOnExceptionsDetected().WaitForMessageToBeReceivedAt<SayStuffy2>(host)
var session = await host.TrackActivity().DoNotAssertOnExceptionsDetected().WaitForMessageToBeReceivedAt<SayStuffy2>(host).Timeout(30.Seconds())
.SendMessageAndWaitAsync(new SayStuffy0());

session.Executed.SingleMessage<SayStuffy2>().ShouldNotBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,14 @@ public async Task startHostAsync(Action<WolverineOptions> configure)
opts.Services.AddScoped<IEventPublisher, EventPublisher>();

configure(opts);

opts.UseEntityFrameworkCoreWolverineManagedMigrations();
opts.Services.AddResourceSetupOnStartup();

//opts.PublishDomainEventsFromEntityFrameworkCore();
}).StartAsync();

await theHost.RebuildAllEnvelopeStorageAsync();

await withItemsTable();
}

private async Task withItemsTable()
{
await using (var conn = new SqlConnection(Servers.SqlServerConnectionString))
{
await conn.OpenAsync();
var migration = await SchemaMigration.DetermineAsync(conn, ItemsTable);
if (migration.Difference != SchemaPatchDifference.None)
{
var sqlServerMigrator = new SqlServerMigrator();

await sqlServerMigrator.ApplyAllAsync(conn, migration, AutoCreate.CreateOrUpdate);
}

await conn.CloseAsync();
}
}

[Fact]
Expand Down
103 changes: 103 additions & 0 deletions src/Persistence/EfCoreTests/Migrations/with_one_postgresql_context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using IntegrationTests;
using JasperFx.CommandLine.Descriptions;
using JasperFx.Core.Reflection;
using JasperFx.Environment;
using JasperFx.Resources;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Npgsql;
using Shouldly;
using Weasel.Core.Migrations;
using Weasel.Postgresql;
using Wolverine;
using Wolverine.EntityFrameworkCore;
using Wolverine.EntityFrameworkCore.Internals.Migrations;
using Wolverine.Postgresql;
using Wolverine.SqlServer;

namespace EfCoreTests.Migrations;

[Collection("postgresql")]
public class with_one_postgresql_context : IAsyncLifetime
{
private IHost _host;

public async Task InitializeAsync()
{
using var conn = new NpgsqlConnection(Servers.PostgresConnectionString);
await conn.OpenAsync();
await conn.DropSchemaAsync("blogs");
await conn.CloseAsync();

_host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
WolverineEntityCoreExtensions.AddDbContextWithWolverineIntegration<BloggingContext>(opts.Services, x =>
{
x.UseNpgsql(Servers.PostgresConnectionString);
});

opts.Discovery.DisableConventionalDiscovery();

opts.Services.AddResourceSetupOnStartup(StartupAction.ResetState);

opts.PersistMessagesWithPostgresql(Servers.PostgresConnectionString);
opts.UseEntityFrameworkCoreTransactions();

// TODO -- this might go away and get merged into UseEntityFrameworkCoreTransactions() above
opts.UseEntityFrameworkCoreWolverineManagedMigrations();
}).StartAsync();
}

public async Task DisposeAsync()
{
await _host.StopAsync();
}

[Fact]
public void registers_the_system_part()
{
_host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>()
.Any().ShouldBeTrue();
}

[Fact]
public async Task did_apply()
{
using var scope = _host.Services.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<BloggingContext>();

await context.Blogs.AddAsync(new Blog()
{
BlogId = 1,
Url = "http://codebetter.com"
});
await context.SaveChangesAsync();
}

[Fact]
public async Task smoke_test_write_to_console()
{
var part = _host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>().First();
await part.WriteToConsole();
}

[Fact]
public async Task smoke_test_check_connectivity()
{
var part = _host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>().First();
var results = new EnvironmentCheckResults();
await part.AssertEnvironmentAsync(_host.Services, results, CancellationToken.None);

results.Failures.Any().ShouldBeFalse();
}

[Fact]
public async Task smoke_tests_describe_databases()
{
var part = _host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>().First();
var usage = await part.As<IDatabaseSource>().DescribeDatabasesAsync(CancellationToken.None);
usage.ShouldNotBeNull();
}
}
151 changes: 151 additions & 0 deletions src/Persistence/EfCoreTests/Migrations/with_one_sqlserver_context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System.ComponentModel.DataAnnotations.Schema;
using IntegrationTests;
using JasperFx.CommandLine.Descriptions;
using JasperFx.Core.Reflection;
using JasperFx.Environment;
using JasperFx.Resources;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SharedPersistenceModels.Items;
using Shouldly;
using Weasel.Core.Migrations;
using Weasel.SqlServer;
using Wolverine;
using Wolverine.EntityFrameworkCore;
using Wolverine.EntityFrameworkCore.Internals.Migrations;
using Wolverine.SqlServer;

namespace EfCoreTests.Migrations;

[Collection("sqlserver")]
public class with_one_sqlserver_context : IAsyncLifetime
{
private IHost _host;

public async Task InitializeAsync()
{
using var conn = new SqlConnection(Servers.SqlServerConnectionString);
await conn.OpenAsync();
await conn.DropSchemaAsync("blogs");
await conn.CloseAsync();

_host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.Services.AddDbContextWithWolverineIntegration<BloggingContext>(x =>
x.UseSqlServer(Servers.SqlServerConnectionString));

opts.Discovery.DisableConventionalDiscovery();

opts.Services.AddResourceSetupOnStartup(StartupAction.ResetState);

opts.PersistMessagesWithSqlServer(Servers.SqlServerConnectionString, "blogs");
opts.UseEntityFrameworkCoreTransactions();

// TODO -- this might go away and get merged into UseEntityFrameworkCoreTransactions() above
opts.UseEntityFrameworkCoreWolverineManagedMigrations();
}).StartAsync();
}

public async Task DisposeAsync()
{
await _host.StopAsync();
}

[Fact]
public void registers_the_system_part()
{
_host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>()
.Any().ShouldBeTrue();
}

[Fact]
public async Task did_apply()
{
using var scope = _host.Services.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<BloggingContext>();

await context.Blogs.AddAsync(new Blog()
{
BlogId = 1,
Url = "http://codebetter.com"
});
await context.SaveChangesAsync();
}

[Fact]
public async Task smoke_test_write_to_console()
{
var part = _host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>().First();
await part.WriteToConsole();
}

[Fact]
public async Task smoke_test_check_connectivity()
{
var part = _host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>().First();
var results = new EnvironmentCheckResults();
await part.AssertEnvironmentAsync(_host.Services, results, CancellationToken.None);

results.Failures.Any().ShouldBeFalse();
}

[Fact]
public async Task smoke_tests_describe_databases()
{
var part = _host.Services.GetServices<ISystemPart>().OfType<EntityFrameworkCoreSystemPart>().First();
var usage = await part.As<IDatabaseSource>().DescribeDatabasesAsync(CancellationToken.None);
usage.ShouldNotBeNull();
}
}

public class Blog
{
[Column("id")]
public int BlogId { get; set; }

[Column("url")]
public string Url { get; set; }
// Navigation property for related posts
public List<Post> Posts { get; set; }
}

public class Post
{
[Column("post_id")]
public int PostId { get; set; }

[Column("title")]
public string Title { get; set; }

[Column("content")]
public string Content { get; set; }
// Foreign key to the Blog
[Column("blog_id")]
public int BlogId { get; set; }
// Navigation property for the related blog
public Blog Blog { get; set; }
}

public class BloggingContext : DbContext
{
// DbSet properties represent the collections of entities in the context
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }

// Constructor for dependency injection (recommended in ASP.NET Core apps)
public BloggingContext(DbContextOptions<BloggingContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasDefaultSchema("blogs");


}
}
2 changes: 1 addition & 1 deletion src/Persistence/EfCoreTests/NoParallelization.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public class eager_idempotency_with_non_wolverine_mapped_db_context : IClassFixt
public eager_idempotency_with_non_wolverine_mapped_db_context(EFCorePersistenceContext context)
{
Host = context.theHost;
ItemsTable = context.ItemsTable;
}

public Table ItemsTable { get; }

public IHost Host { get; }

Expand Down
Loading
Loading