-
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.
add ServiceCollectionExtensionsTests
- Loading branch information
1 parent
c9695c7
commit ecc8d7a
Showing
2 changed files
with
50 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
...h.Messaging.AzureServiceBus.Tests/DependencyInjection/ServiceCollectionExtensionsTests.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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Azure.Messaging.ServiceBus; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Xunit; | ||
|
||
namespace GodelTech.Messaging.AzureServiceBus.Tests.DependencyInjection | ||
{ | ||
public class ServiceCollectionExtensionsTests | ||
{ | ||
[Fact] | ||
public void AddAzureServiceBusSender_Success() | ||
{ | ||
// Arrange | ||
const string connectionString = "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YourAccessKey"; | ||
var queues = new Dictionary<string, string> | ||
{ | ||
{ | ||
"InternalKey", | ||
"AzureServiceBusQueueName" | ||
} | ||
}; | ||
Action<AzureServiceBusOptions> optionsAction = options => | ||
{ | ||
options.Queues = queues; | ||
}; | ||
|
||
var services = new ServiceCollection(); | ||
|
||
// Act | ||
services.AddAzureServiceBusSender(connectionString, optionsAction); | ||
|
||
// Assert | ||
var provider = services.BuildServiceProvider(); | ||
|
||
var resultRequiredService = provider.GetRequiredService<ServiceBusClient>(); | ||
Assert.NotNull(resultRequiredService); | ||
|
||
var resultOptionsAction = provider.GetRequiredService<IOptions<AzureServiceBusOptions>>(); | ||
Assert.NotNull(resultOptionsAction); | ||
Assert.NotNull(resultOptionsAction.Value); | ||
Assert.Equal(queues, resultOptionsAction.Value.Queues); | ||
|
||
var resultAzureServiceBusSender = provider.GetRequiredService<AzureServiceBusSender>(); | ||
Assert.NotNull(resultAzureServiceBusSender); | ||
} | ||
} | ||
} |