Skip to content

Commit

Permalink
Add time measurements. Supress EF warns.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Maruszak <[email protected]>
  • Loading branch information
zarusz committed Oct 24, 2024
1 parent 2d90ec0 commit 888401d
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ void ConfigureExternalBus(MessageBusBuilder mbb)
}

public const string InvalidLastname = "Exception";
private string[] _surnames = ["Doe", "Smith", InvalidLastname];


[Theory]
[InlineData([TransactionType.SqlTransaction, BusType.AzureSB, 100, SqlOutboxMessageIdGenerationMode.ClientGuidGenerator])]
Expand All @@ -160,15 +162,9 @@ public async Task Given_CommandHandlerInTransaction_When_ExceptionThrownDuringHa
_testParamBusType = busType;
_testParamIdGenerationMode = mode;

await PerformDbOperation(async (context, _) =>
{
// migrate db
await context.Database.DropSchemaIfExistsAsync(context.Model.GetDefaultSchema());
await context.Database.MigrateAsync();
});
await PrepareDatabase();

var surnames = new[] { "Doe", "Smith", InvalidLastname };
var commands = Enumerable.Range(0, messageCount).Select(x => new CreateCustomerCommand($"John {x:000}", surnames[x % surnames.Length]));
var commands = Enumerable.Range(0, messageCount).Select(x => new CreateCustomerCommand($"John {x:000}", _surnames[x % _surnames.Length])).ToList();
var validCommands = commands.Where(x => !string.Equals(x.Lastname, InvalidLastname, StringComparison.InvariantCulture)).ToList();

await EnsureConsumersStarted();
Expand Down Expand Up @@ -219,6 +215,17 @@ await PerformDbOperation(async (context, _) =>
customerCountWithValidLastname.Should().Be(validCommands.Count);
}

private Task PrepareDatabase()
=> PerformDbOperation(async (context, _) =>
{
// migrate db
await context.Database.MigrateAsync();
await context.Customers.ExecuteDeleteAsync();
#pragma warning disable EF1002 // Risk of vulnerability to SQL injection.
await context.Database.ExecuteSqlRawAsync($"delete from {context.Model.GetDefaultSchema()}.Outbox");
#pragma warning restore EF1002 // Risk of vulnerability to SQL injection.
});

[Theory]
[InlineData([BusType.AzureSB, 100, SqlOutboxMessageIdGenerationMode.ClientGuidGenerator])]
[InlineData([BusType.AzureSB, 100, SqlOutboxMessageIdGenerationMode.DatabaseGeneratedGuid])]
Expand All @@ -231,15 +238,10 @@ public async Task Given_PublishExternalEventInTransaction_When_ExceptionThrownDu
_testParamTransactionType = TransactionType.TransactionScope;
_testParamBusType = busType;

await PerformDbOperation(async (context, _) =>
{
// migrate db
await context.Database.DropSchemaIfExistsAsync(context.Model.GetDefaultSchema());
await context.Database.MigrateAsync();
});
await PrepareDatabase();

var surnames = new[] { "Doe", "Smith", InvalidLastname };
var events = Enumerable.Range(0, messageCount).Select(x => new CustomerCreatedEvent(Guid.NewGuid(), $"John {x:000}", surnames[x % surnames.Length]));
var events = Enumerable.Range(0, messageCount).Select(x => new CustomerCreatedEvent(Guid.NewGuid(), $"John {x:000}", surnames[x % surnames.Length])).ToList();
var validEvents = events.Where(x => !string.Equals(x.Lastname, InvalidLastname, StringComparison.InvariantCulture)).ToList();

await EnsureConsumersStarted();
Expand Down

0 comments on commit 888401d

Please sign in to comment.