Skip to content

Commit

Permalink
Merged in the EF Core 3.1 update MassTransit#1629
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Jan 28, 2020
1 parent 9eedeb8 commit cd805c9
Show file tree
Hide file tree
Showing 54 changed files with 808 additions and 405 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,25 @@
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit.EntityFrameworkCoreIntegration.Tests
namespace MassTransit.EntityFrameworkCoreIntegration.Tests.AuditStore
{
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

using Audit;
using GreenPipes.Util;

using MassTransit.EntityFrameworkCoreIntegration.Audit;
using MassTransit.Testing;

using Microsoft.EntityFrameworkCore;

using NUnit.Framework;

using Shared;
using Shouldly;
using Testing;


[TestFixture]
public class Saving_audit_records_to_the_audit_store
[TestFixture(typeof(SqlServerTestDbParameters))]
[TestFixture(typeof(SqlServerResiliencyTestDbParameters))]
[TestFixture(typeof(PostgresTestDbParameters))]
public class Saving_audit_records_to_the_audit_store<T> :
EntityFrameworkTestFixture<T, AuditDbContext>
where T : ITestDbParameters, new()
{
[Test]
public async Task Should_have_consume_audit_records()
Expand All @@ -53,30 +52,21 @@ public async Task CleanAudit()
}

InMemoryTestHarness _harness;
ConsumerTestHarness<TestConsumer> _consumer;
EntityFrameworkAuditStore _store;

[OneTimeSetUp]
public async Task Send_message_to_test_consumer()
public async Task SetUp()
{
// add migrations by calling
// dotnet ef migrations add --context auditdbcontext --output-dir Migrations\\Audit audit_init
DbContextOptionsBuilder<AuditDbContext> optionsBuilder = new DbContextOptionsBuilder<AuditDbContext>().
UseSqlServer(LocalDbConnectionStringProvider.GetLocalDbConnectionString(),
m =>
{
var executingAssembly = typeof(ContextFactory).GetTypeInfo().Assembly;
m.MigrationsAssembly(executingAssembly.GetName().Name);
m.MigrationsHistoryTable("__AuditEFMigrationHistoryAudit");
});

_store = new EntityFrameworkAuditStore(optionsBuilder.Options, "EfCoreAudit");
using (var dbContext = _store.AuditContext)
var contextFactory = new AuditContextFactory();

await using (var context = contextFactory.CreateDbContext(DbContextOptionsBuilder))
{
await dbContext.Database.MigrateAsync();
await dbContext.Database.ExecuteSqlCommandAsync("TRUNCATE TABLE EfCoreAudit");
await context.Database.MigrateAsync();
}

_store = new EntityFrameworkAuditStore(DbContextOptionsBuilder.Options, "EfCoreAudit");

_harness = new InMemoryTestHarness();
_harness.OnConnectObservers += bus =>
{
Expand All @@ -91,18 +81,24 @@ public async Task Send_message_to_test_consumer()
}

[OneTimeTearDown]
public Task Teardown()
public async Task Teardown()
{
return _harness.Stop();
await _harness.Stop();

var contextFactory = new AuditContextFactory();

await using (var context = contextFactory.CreateDbContext(DbContextOptionsBuilder))
{
context.Database.EnsureDeleted();
}
}

async Task<int> GetAuditRecords(string contextType)
{
using var dbContext = _store.AuditContext;

return await dbContext.Set<AuditRecord>()
.Where(x => x.ContextType == contextType)
.CountAsync();
using (var dbContext = this._store.AuditContext)
return await dbContext.Set<AuditRecord>()
.Where(x => x.ContextType == contextType)
.CountAsync();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace MassTransit.EntityFrameworkCoreIntegration.Tests
{
using System.Reflection;

using MassTransit.EntityFrameworkCoreIntegration.Audit;
using MassTransit.Tests.AutomatonymousIntegration;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Shared;


public class AuditContextFactory : IDesignTimeDbContextFactory<AuditDbContext>
{
public AuditDbContext CreateDbContext(string[] args)
{
// used only for database update and migrations. Since IDesignTimeDbContextFactory is icky,
// we only support command line tools for SQL Server, so use SQL Server if you need to do
// migrations.

var optionsBuilder = new SqlServerTestDbParameters().GetDbContextOptions(typeof(AuditDbContext));
return CreateDbContext(optionsBuilder);
}

public AuditDbContext CreateDbContext(DbContextOptionsBuilder optionsBuilder)
{
return new AuditDbContext(optionsBuilder.Options, "EfCoreAudit");
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace MassTransit.EntityFrameworkCoreIntegration.Tests
{
using System;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;


public static class LocalDbConnectionStringProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

<ItemGroup>
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Shouldly" Version="3.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace MassTransit.EntityFrameworkCoreIntegration.Tests.Migrations.Audit
{
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;


public partial class audit_init : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
Expand All @@ -14,6 +17,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
AuditRecordId = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
ContextType = table.Column<string>(nullable: true),
ConversationId = table.Column<Guid>(nullable: true),
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.EntityFrameworkCore.Migrations;

namespace MassTransit.EntityFrameworkCoreIntegration.Tests.Migrations
namespace MassTransit.EntityFrameworkCoreIntegration.Tests.Migrations.Saga
{
public partial class Init : Migration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using MassTransit.EntityFrameworkCoreIntegration;
namespace MassTransit.EntityFrameworkCoreIntegration.Tests.Migrations.Saga
{
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using SimpleSaga.DataAccess;

using MassTransit.Tests.Saga;

namespace MassTransit.EntityFrameworkCoreIntegration.Tests.Migrations
{
[DbContext(typeof(SimpleSagaDbContext))]
partial class SagaDbContextModelSnapshot : ModelSnapshot
{
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "SagaInnerDependency",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true)
Id = table.Column<Guid>(nullable: false),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
Expand All @@ -24,8 +24,8 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "SagaDependency",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
SagaInnerDependencyId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
Id = table.Column<Guid>(nullable: false),
SagaInnerDependencyId = table.Column<Guid>(nullable: false)
},
constraints: table =>
{
Expand All @@ -42,11 +42,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "EfCoreSagasWithDepencies",
columns: table => new
{
CorrelationId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Completed = table.Column<bool>(type: "bit", nullable: false),
DependencyId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Initiated = table.Column<bool>(type: "bit", nullable: false),
Name = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true)
CorrelationId = table.Column<Guid>(nullable: false),
Completed = table.Column<bool>(nullable: false),
DependencyId = table.Column<Guid>(nullable: false),
Initiated = table.Column<bool>(nullable: false),
Name = table.Column<string>(maxLength: 40, nullable: true)
},
constraints: table =>
{
Expand Down
Loading

0 comments on commit cd805c9

Please sign in to comment.