Skip to content

Commit

Permalink
add ServiceCollectionExtensionsTests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodchenkov committed Mar 28, 2021
1 parent c9695c7 commit ecc8d7a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using GodelTech.Messaging.AzureServiceBus;
using Microsoft.Extensions.DependencyInjection;

// ReSharper disable once CheckNamespace
namespace Microsoft.AspNetCore.Builder
{
/// <summary>
Expand Down
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);
}
}
}

0 comments on commit ecc8d7a

Please sign in to comment.