forked from arcus-azure/arcus.messaging
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: add Azure ServiceBus Queue/Topic MessagePump registration short…
…cuts (arcus-azure#50) * FEAT: add Azure ServiceBus Queue/Topic MessagePump registration shortcuts * PR-SUG: add unit tests to verify if we wire up correctly * PR-SUG: update service extensions tests with backdoor mocking verification
- Loading branch information
1 parent
c960130
commit 2f64e2d
Showing
4 changed files
with
196 additions
and
0 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
41 changes: 41 additions & 0 deletions
41
src/Arcus.Messaging.Tests.Unit/ServiceBus/EmptyMessagePump.cs
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,41 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Arcus.Messaging.Abstractions; | ||
using Arcus.Messaging.Pumps.ServiceBus; | ||
using Arcus.Messaging.Tests.Core.Messages.v1; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Arcus.Messaging.Tests.Unit.ServiceBus | ||
{ | ||
public class EmptyMessagePump : AzureServiceBusMessagePump<Order> | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="configuration">Configuration of the application</param> | ||
/// <param name="serviceProvider">Collection of services that are configured</param> | ||
/// <param name="logger">Logger to write telemetry to</param> | ||
public EmptyMessagePump(IConfiguration configuration, IServiceProvider serviceProvider, ILogger logger) : base(configuration, serviceProvider, logger) { } | ||
|
||
/// <summary> | ||
/// Process a new message that was received | ||
/// </summary> | ||
/// <param name="message">Message that was received</param> | ||
/// <param name="messageContext">Context providing more information concerning the processing</param> | ||
/// <param name="correlationInfo"> | ||
/// Information concerning correlation of telemetry & processes by using a variety of unique | ||
/// identifiers | ||
/// </param> | ||
/// <param name="cancellationToken">Cancellation token</param> | ||
protected override async Task ProcessMessageAsync( | ||
Order message, | ||
AzureServiceBusMessageContext messageContext, | ||
MessageCorrelationInfo correlationInfo, | ||
CancellationToken cancellationToken) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/Arcus.Messaging.Tests.Unit/ServiceBus/IServiceCollectionExtensionsTests.cs
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,97 @@ | ||
using System.Threading.Tasks; | ||
using Arcus.Messaging.Pumps.ServiceBus; | ||
using Arcus.Security.Core; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Arcus.Messaging.Tests.Unit.ServiceBus | ||
{ | ||
public class IServiceCollectionExtensionsTests | ||
{ | ||
[Fact] | ||
public async Task AddServiceBusTopicMessagePump_WithSubscriptionNameIndirectSecretProvider_WiresUpCorrectly() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection(); | ||
var spySecretProvider = new Mock<ISecretProvider>(); | ||
services.AddSingleton(serviceProvider => spySecretProvider.Object); | ||
services.AddSingleton(serviceProvider => Mock.Of<IConfiguration>()); | ||
services.AddSingleton(serviceProvider => Mock.Of<ILogger>()); | ||
|
||
// Act | ||
IServiceCollection result = | ||
services.AddServiceBusTopicMessagePump<EmptyMessagePump>( | ||
"subscription name", "secret name", configureMessagePump: options => options.AutoComplete = true); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
ServiceProvider provider = result.BuildServiceProvider(); | ||
|
||
var messagePump = provider.GetService<IHostedService>(); | ||
Assert.IsType<EmptyMessagePump>(messagePump); | ||
|
||
var settings = provider.GetService<AzureServiceBusMessagePumpSettings>(); | ||
await settings.GetConnectionStringAsync(); | ||
spySecretProvider.Verify(spy => spy.GetRawSecretAsync("secret name"), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task AddServiceBusTopicMessagePump_WithTopicNameAndSubscriptionNameIndirectSecretProvider_WiresUpCorrectly() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection(); | ||
var spySecretProvider = new Mock<ISecretProvider>(); | ||
services.AddSingleton(serviceProvider => spySecretProvider.Object); | ||
services.AddSingleton(serviceProvider => Mock.Of<IConfiguration>()); | ||
services.AddSingleton(serviceProvider => Mock.Of<ILogger>()); | ||
|
||
// Act | ||
IServiceCollection result = | ||
services.AddServiceBusTopicMessagePump<EmptyMessagePump>( | ||
"topic name", "subscription name", "secret name", configureMessagePump: options => options.AutoComplete = true); | ||
|
||
// Assert | ||
// Assert | ||
Assert.NotNull(result); | ||
ServiceProvider provider = result.BuildServiceProvider(); | ||
|
||
var messagePump = provider.GetService<IHostedService>(); | ||
Assert.IsType<EmptyMessagePump>(messagePump); | ||
|
||
var settings = provider.GetService<AzureServiceBusMessagePumpSettings>(); | ||
await settings.GetConnectionStringAsync(); | ||
spySecretProvider.Verify(spy => spy.GetRawSecretAsync("secret name"), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task AddServiceBusQueueMessagePump_IndirectSecretProvider_WiresUpCorrectly() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection(); | ||
var spySecretProvider = new Mock<ISecretProvider>(); | ||
services.AddSingleton(serviceProvider => spySecretProvider.Object); | ||
services.AddSingleton(serviceProvider => Mock.Of<IConfiguration>()); | ||
services.AddSingleton(serviceProvider => Mock.Of<ILogger>()); | ||
|
||
// Act | ||
IServiceCollection result = | ||
services.AddServiceBusQueueMessagePump<EmptyMessagePump>( | ||
"queue name", "secret name", configureMessagePump: options => options.AutoComplete = true); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
ServiceProvider provider = result.BuildServiceProvider(); | ||
|
||
var messagePump = provider.GetService<IHostedService>(); | ||
Assert.IsType<EmptyMessagePump>(messagePump); | ||
|
||
var settings = provider.GetService<AzureServiceBusMessagePumpSettings>(); | ||
await settings.GetConnectionStringAsync(); | ||
spySecretProvider.Verify(spy => spy.GetRawSecretAsync("secret name"), Times.Once); | ||
} | ||
} | ||
} |