Skip to content

Commit 5c9da78

Browse files
committed
Updated test
1 parent e9ed98f commit 5c9da78

11 files changed

+90
-55
lines changed

Tests/MinimalHostingModel/MinimalHostingModel.Infrastructure/Configuration/MassTransitConfiguration.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ public static void AddMassTransitConfiguration(this IServiceCollection services,
3030
cfg.UseMessageRetry(r => r.Interval(
3131
configuration.GetValue<int?>("MassTransit:RetryInterval:RetryCount") ?? 10,
3232
configuration.GetValue<TimeSpan?>("MassTransit:RetryInterval:Interval") ?? TimeSpan.FromSeconds(5)));
33+
3334
cfg.ConfigureEndpoints(context);
34-
cfg.UseInMemoryOutbox();
35+
cfg.UseMessageScope(context);
36+
cfg.UseInMemoryOutbox(context);
3537
cfg.UsePublishFilter(typeof(FinbucklePublishingFilter<>), context);
3638
cfg.UseConsumeFilter(typeof(FinbuckleConsumingFilter<>), context);
39+
cfg.UseSendFilter(typeof(FinbuckleSendingFilter<>), context);
3740
});
3841
x.AddInMemoryInboxOutbox();
3942
});

Tests/MinimalHostingModel/MinimalHostingModel.Infrastructure/Eventing/FinbuckleConsumingFilter.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class FinbuckleConsumingFilter<T> : IFilter<ConsumeContext<T>>
1818
{
1919
private readonly string _headerName;
2020
private readonly FinbuckleMessageHeaderStrategy _messageHeaderStrategy;
21-
private IMultiTenantContextAccessor _accessor;
22-
private ITenantResolver _tenantResolver;
21+
private readonly IMultiTenantContextAccessor _accessor;
22+
private readonly ITenantResolver _tenantResolver;
2323

2424
public FinbuckleConsumingFilter(IServiceProvider serviceProvider,
2525
IMultiTenantContextAccessor accessor,
@@ -29,9 +29,10 @@ public FinbuckleConsumingFilter(IServiceProvider serviceProvider,
2929
_accessor = accessor;
3030
_tenantResolver = tenantResolver;
3131
_headerName = configuration.GetValue<string?>("MassTransit:TenantHeader") ?? "Tenant-Identifier";
32-
_messageHeaderStrategy = (FinbuckleMessageHeaderStrategy)serviceProvider.GetRequiredService<IEnumerable<IMultiTenantStrategy>>()
33-
.Where(s => s.GetType() == typeof(FinbuckleMessageHeaderStrategy))
34-
.Single();
32+
33+
_messageHeaderStrategy = (FinbuckleMessageHeaderStrategy)serviceProvider
34+
.GetRequiredService<IEnumerable<IMultiTenantStrategy>>()
35+
.Single(s => s.GetType() == typeof(FinbuckleMessageHeaderStrategy));
3536
}
3637

3738
public async Task Send(ConsumeContext<T> context, IPipe<ConsumeContext<T>> next)

Tests/MinimalHostingModel/MinimalHostingModel.Infrastructure/Eventing/FinbuckleMessageHeaderStrategy.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace MinimalHostingModel.Infrastructure.Eventing
99
{
1010
public class FinbuckleMessageHeaderStrategy : IMultiTenantStrategy
1111
{
12-
private string _tenantIdentifier = null!;
12+
private string? _tenantIdentifier;
1313

14-
public Task<string> GetIdentifierAsync(object context)
14+
public Task<string?> GetIdentifierAsync(object context)
1515
{
1616
return Task.FromResult(_tenantIdentifier);
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Threading.Tasks;
2+
using Finbuckle.MultiTenant;
3+
using Intent.RoslynWeaver.Attributes;
4+
using MassTransit;
5+
using Microsoft.Extensions.Configuration;
6+
7+
[assembly: DefaultIntentManaged(Mode.Fully)]
8+
[assembly: IntentTemplate("Intent.Eventing.MassTransit.FinbuckleSendingFilter", Version = "1.0")]
9+
10+
namespace MinimalHostingModel.Infrastructure.Eventing
11+
{
12+
public class FinbuckleSendingFilter<T> : IFilter<SendContext<T>>
13+
where T : class
14+
{
15+
private readonly string _headerName;
16+
private readonly ITenantInfo _tenant;
17+
18+
public FinbuckleSendingFilter(ITenantInfo tenant, IConfiguration configuration)
19+
{
20+
_tenant = tenant;
21+
_headerName = configuration.GetValue<string?>("MassTransit:TenantHeader") ?? "Tenant-Identifier";
22+
}
23+
24+
public void Probe(ProbeContext context)
25+
{
26+
}
27+
28+
public Task Send(SendContext<T> context, IPipe<SendContext<T>> next)
29+
{
30+
context.Headers.Set(_headerName, _tenant.Identifier);
31+
return next.Send(context);
32+
}
33+
}
34+
}

Tests/MinimalHostingModel/MinimalHostingModel.Infrastructure/Eventing/WrapperConsumer.cs Tests/MinimalHostingModel/MinimalHostingModel.Infrastructure/Eventing/IntegrationEventConsumer.cs

+9-15
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
using MinimalHostingModel.Domain.Common.Interfaces;
99

1010
[assembly: DefaultIntentManaged(Mode.Fully)]
11-
[assembly: IntentTemplate("Intent.Eventing.MassTransit.WrapperConsumer", Version = "1.0")]
11+
[assembly: IntentTemplate("Intent.Eventing.MassTransit.IntegrationEventConsumer", Version = "1.0")]
1212

1313
namespace MinimalHostingModel.Infrastructure.Eventing
1414
{
15-
public class WrapperConsumer<THandler, TMessage> : IConsumer<TMessage>
15+
public class IntegrationEventConsumer<THandler, TMessage> : IConsumer<TMessage>
1616
where TMessage : class
1717
where THandler : IIntegrationEventHandler<TMessage>
1818
{
1919
private readonly IServiceProvider _serviceProvider;
2020
private readonly IUnitOfWork _unitOfWork;
2121

22-
public WrapperConsumer(IServiceProvider serviceProvider, IUnitOfWork unitOfWork)
22+
public IntegrationEventConsumer(IServiceProvider serviceProvider, IUnitOfWork unitOfWork)
2323
{
2424
_serviceProvider = serviceProvider;
2525
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
2626
}
2727

2828
public async Task Consume(ConsumeContext<TMessage> context)
2929
{
30-
var eventBus = _serviceProvider.GetService<MassTransitEventBus>()!;
30+
var eventBus = _serviceProvider.GetRequiredService<MassTransitEventBus>();
3131
eventBus.ConsumeContext = context;
32-
var handler = _serviceProvider.GetService<THandler>()!;
32+
var handler = _serviceProvider.GetRequiredService<THandler>();
3333

3434
// The execution is wrapped in a transaction scope to ensure that if any other
3535
// SaveChanges calls to the data source (e.g. EF Core) are called, that they are
@@ -55,22 +55,16 @@ public async Task Consume(ConsumeContext<TMessage> context)
5555
}
5656
}
5757

58-
public class WrapperConsumerDefinition<THandler, TMessage> : ConsumerDefinition<WrapperConsumer<THandler, TMessage>>
58+
public class IntegrationEventConsumerDefinition<THandler, TMessage> : ConsumerDefinition<IntegrationEventConsumer<THandler, TMessage>>
5959
where TMessage : class
6060
where THandler : IIntegrationEventHandler<TMessage>
6161
{
62-
private readonly IServiceProvider _serviceProvider;
63-
64-
public WrapperConsumerDefinition(IServiceProvider serviceProvider)
65-
{
66-
_serviceProvider = serviceProvider;
67-
}
68-
6962
protected override void ConfigureConsumer(
7063
IReceiveEndpointConfigurator endpointConfigurator,
71-
IConsumerConfigurator<WrapperConsumer<THandler, TMessage>> consumerConfigurator)
64+
IConsumerConfigurator<IntegrationEventConsumer<THandler, TMessage>> consumerConfigurator,
65+
IRegistrationContext context)
7266
{
73-
endpointConfigurator.UseInMemoryInboxOutbox(_serviceProvider);
67+
endpointConfigurator.UseInMemoryInboxOutbox(context);
7468
}
7569
}
7670
}

Tests/MinimalHostingModel/MinimalHostingModel.Infrastructure/MinimalHostingModel.Infrastructure.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<PackageReference Include="Finbuckle.MultiTenant.EntityFrameworkCore" Version="6.12.0" />
1717
<PackageReference Include="IdentityModel.AspNetCore" Version="4.3.0" />
1818
<PackageReference Include="Intent.RoslynWeaver.Attributes" Version="2.1.4" />
19-
<PackageReference Include="MassTransit" Version="8.0.16" />
20-
<PackageReference Include="MassTransit.Abstractions" Version="8.0.16" />
19+
<PackageReference Include="MassTransit" Version="8.1.3" />
20+
<PackageReference Include="MassTransit.Abstractions" Version="8.1.3" />
2121
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
2222
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
2323
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />

Tests/MinimalHostingModel/MinimalHostingModel.application.output.log

+14-6
Original file line numberDiff line numberDiff line change
@@ -932,18 +932,26 @@
932932
</FileLog>
933933
<FileLog>
934934
<ProjectId>de97fc2c-cddf-4284-b3b6-33e6fae0dca8</ProjectId>
935-
<CorrelationId>Intent.Eventing.MassTransit.MassTransitEventBus</CorrelationId>
935+
<CorrelationId>Intent.Eventing.MassTransit.FinbuckleSendingFilter</CorrelationId>
936936
<OverwriteBehaviour>always</OverwriteBehaviour>
937-
<ApplicationRelativeFilePath>MinimalHostingModel.Infrastructure/Eventing/MassTransitEventBus.cs</ApplicationRelativeFilePath>
938-
<ProjectRelativeFilePath>MassTransitEventBus.cs</ProjectRelativeFilePath>
937+
<ApplicationRelativeFilePath>MinimalHostingModel.Infrastructure/Eventing/FinbuckleSendingFilter.cs</ApplicationRelativeFilePath>
938+
<ProjectRelativeFilePath>FinbuckleSendingFilter.cs</ProjectRelativeFilePath>
939939
<IsIgnored>false</IsIgnored>
940940
</FileLog>
941941
<FileLog>
942942
<ProjectId>de97fc2c-cddf-4284-b3b6-33e6fae0dca8</ProjectId>
943-
<CorrelationId>Intent.Eventing.MassTransit.WrapperConsumer</CorrelationId>
943+
<CorrelationId>Intent.Eventing.MassTransit.IntegrationEventConsumer</CorrelationId>
944944
<OverwriteBehaviour>always</OverwriteBehaviour>
945-
<ApplicationRelativeFilePath>MinimalHostingModel.Infrastructure/Eventing/WrapperConsumer.cs</ApplicationRelativeFilePath>
946-
<ProjectRelativeFilePath>WrapperConsumer.cs</ProjectRelativeFilePath>
945+
<ApplicationRelativeFilePath>MinimalHostingModel.Infrastructure/Eventing/IntegrationEventConsumer.cs</ApplicationRelativeFilePath>
946+
<ProjectRelativeFilePath>IntegrationEventConsumer.cs</ProjectRelativeFilePath>
947+
<IsIgnored>false</IsIgnored>
948+
</FileLog>
949+
<FileLog>
950+
<ProjectId>de97fc2c-cddf-4284-b3b6-33e6fae0dca8</ProjectId>
951+
<CorrelationId>Intent.Eventing.MassTransit.MassTransitEventBus</CorrelationId>
952+
<OverwriteBehaviour>always</OverwriteBehaviour>
953+
<ApplicationRelativeFilePath>MinimalHostingModel.Infrastructure/Eventing/MassTransitEventBus.cs</ApplicationRelativeFilePath>
954+
<ProjectRelativeFilePath>MassTransitEventBus.cs</ProjectRelativeFilePath>
947955
<IsIgnored>false</IsIgnored>
948956
</FileLog>
949957
<FileLog>

Tests/Standard.AspNetCore.ServiceCallHandlers/Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Configuration/MassTransitConfiguration.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public static void AddMassTransitConfiguration(this IServiceCollection services,
3030
cfg.UseMessageRetry(r => r.Interval(
3131
configuration.GetValue<int?>("MassTransit:RetryInterval:RetryCount") ?? 10,
3232
configuration.GetValue<TimeSpan?>("MassTransit:RetryInterval:Interval") ?? TimeSpan.FromSeconds(5)));
33+
3334
cfg.ConfigureEndpoints(context);
34-
cfg.UseInMemoryOutbox();
35+
cfg.UseInMemoryOutbox(context);
3536
});
3637
x.AddInMemoryInboxOutbox();
3738
});

Tests/Standard.AspNetCore.ServiceCallHandlers/Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Eventing/WrapperConsumer.cs Tests/Standard.AspNetCore.ServiceCallHandlers/Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Eventing/IntegrationEventConsumer.cs

+9-15
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
using Standard.AspNetCore.ServiceCallHandlers.Domain.Common.Interfaces;
99

1010
[assembly: DefaultIntentManaged(Mode.Fully)]
11-
[assembly: IntentTemplate("Intent.Eventing.MassTransit.WrapperConsumer", Version = "1.0")]
11+
[assembly: IntentTemplate("Intent.Eventing.MassTransit.IntegrationEventConsumer", Version = "1.0")]
1212

1313
namespace Standard.AspNetCore.ServiceCallHandlers.Infrastructure.Eventing
1414
{
15-
public class WrapperConsumer<THandler, TMessage> : IConsumer<TMessage>
15+
public class IntegrationEventConsumer<THandler, TMessage> : IConsumer<TMessage>
1616
where TMessage : class
1717
where THandler : IIntegrationEventHandler<TMessage>
1818
{
1919
private readonly IServiceProvider _serviceProvider;
2020
private readonly IUnitOfWork _unitOfWork;
2121

22-
public WrapperConsumer(IServiceProvider serviceProvider, IUnitOfWork unitOfWork)
22+
public IntegrationEventConsumer(IServiceProvider serviceProvider, IUnitOfWork unitOfWork)
2323
{
2424
_serviceProvider = serviceProvider;
2525
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
2626
}
2727

2828
public async Task Consume(ConsumeContext<TMessage> context)
2929
{
30-
var eventBus = _serviceProvider.GetService<MassTransitEventBus>()!;
30+
var eventBus = _serviceProvider.GetRequiredService<MassTransitEventBus>();
3131
eventBus.ConsumeContext = context;
32-
var handler = _serviceProvider.GetService<THandler>()!;
32+
var handler = _serviceProvider.GetRequiredService<THandler>();
3333

3434
// The execution is wrapped in a transaction scope to ensure that if any other
3535
// SaveChanges calls to the data source (e.g. EF Core) are called, that they are
@@ -55,22 +55,16 @@ public async Task Consume(ConsumeContext<TMessage> context)
5555
}
5656
}
5757

58-
public class WrapperConsumerDefinition<THandler, TMessage> : ConsumerDefinition<WrapperConsumer<THandler, TMessage>>
58+
public class IntegrationEventConsumerDefinition<THandler, TMessage> : ConsumerDefinition<IntegrationEventConsumer<THandler, TMessage>>
5959
where TMessage : class
6060
where THandler : IIntegrationEventHandler<TMessage>
6161
{
62-
private readonly IServiceProvider _serviceProvider;
63-
64-
public WrapperConsumerDefinition(IServiceProvider serviceProvider)
65-
{
66-
_serviceProvider = serviceProvider;
67-
}
68-
6962
protected override void ConfigureConsumer(
7063
IReceiveEndpointConfigurator endpointConfigurator,
71-
IConsumerConfigurator<WrapperConsumer<THandler, TMessage>> consumerConfigurator)
64+
IConsumerConfigurator<IntegrationEventConsumer<THandler, TMessage>> consumerConfigurator,
65+
IRegistrationContext context)
7266
{
73-
endpointConfigurator.UseInMemoryInboxOutbox(_serviceProvider);
67+
endpointConfigurator.UseInMemoryInboxOutbox(context);
7468
}
7569
}
7670
}

Tests/Standard.AspNetCore.ServiceCallHandlers/Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Standard.AspNetCore.ServiceCallHandlers.Infrastructure.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<ItemGroup>
1414
<PackageReference Include="AutoMapper" Version="13.0.1" />
1515
<PackageReference Include="Intent.RoslynWeaver.Attributes" Version="2.1.4" />
16-
<PackageReference Include="MassTransit" Version="8.0.16" />
17-
<PackageReference Include="MassTransit.Abstractions" Version="8.0.16" />
16+
<PackageReference Include="MassTransit" Version="8.1.3" />
17+
<PackageReference Include="MassTransit.Abstractions" Version="8.1.3" />
1818
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
1919
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14" />
2020
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.14" />

Tests/Standard.AspNetCore.ServiceCallHandlers/Standard.AspNetCore.ServiceCallHandlers.application.output.log

+6-6
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,18 @@
444444
</FileLog>
445445
<FileLog>
446446
<ProjectId>1d945490-fd1f-43ef-a54e-a69010514f18</ProjectId>
447-
<CorrelationId>Intent.Eventing.MassTransit.MassTransitEventBus</CorrelationId>
447+
<CorrelationId>Intent.Eventing.MassTransit.IntegrationEventConsumer</CorrelationId>
448448
<OverwriteBehaviour>always</OverwriteBehaviour>
449-
<ApplicationRelativeFilePath>Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Eventing/MassTransitEventBus.cs</ApplicationRelativeFilePath>
450-
<ProjectRelativeFilePath>MassTransitEventBus.cs</ProjectRelativeFilePath>
449+
<ApplicationRelativeFilePath>Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Eventing/IntegrationEventConsumer.cs</ApplicationRelativeFilePath>
450+
<ProjectRelativeFilePath>IntegrationEventConsumer.cs</ProjectRelativeFilePath>
451451
<IsIgnored>false</IsIgnored>
452452
</FileLog>
453453
<FileLog>
454454
<ProjectId>1d945490-fd1f-43ef-a54e-a69010514f18</ProjectId>
455-
<CorrelationId>Intent.Eventing.MassTransit.WrapperConsumer</CorrelationId>
455+
<CorrelationId>Intent.Eventing.MassTransit.MassTransitEventBus</CorrelationId>
456456
<OverwriteBehaviour>always</OverwriteBehaviour>
457-
<ApplicationRelativeFilePath>Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Eventing/WrapperConsumer.cs</ApplicationRelativeFilePath>
458-
<ProjectRelativeFilePath>WrapperConsumer.cs</ProjectRelativeFilePath>
457+
<ApplicationRelativeFilePath>Standard.AspNetCore.ServiceCallHandlers.Infrastructure/Eventing/MassTransitEventBus.cs</ApplicationRelativeFilePath>
458+
<ProjectRelativeFilePath>MassTransitEventBus.cs</ProjectRelativeFilePath>
459459
<IsIgnored>false</IsIgnored>
460460
</FileLog>
461461
<FileLog>

0 commit comments

Comments
 (0)