-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to customize Exchange creation in RabbitMQ (#79)
- Loading branch information
Showing
9 changed files
with
226 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue"><data /></s:String> | ||
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters><Filter ModuleMask="Nybus*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="False" /></IncludeFilters><ExcludeFilters><Filter ModuleMask="*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="False" /><Filter ModuleMask="Test*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="False" /></ExcludeFilters></data></s:String> | ||
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters><Filter ModuleMask="Nybus*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /></IncludeFilters><ExcludeFilters><Filter ModuleMask="*" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="False" /></ExcludeFilters></data></s:String> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nybus/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
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
35 changes: 35 additions & 0 deletions
35
src/engines/Nybus.Engine.RabbitMq/Configuration/IExchangeManager.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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using RabbitMQ.Client; | ||
|
||
namespace Nybus.Configuration | ||
{ | ||
public interface IExchangeManager | ||
{ | ||
void EnsureExchangeExists(IModel model, string name, string exchangeType); | ||
} | ||
|
||
public class ExchangeManager : IExchangeManager | ||
{ | ||
private readonly ExchangeOptions _options; | ||
|
||
public ExchangeManager(ExchangeOptions options) | ||
{ | ||
_options = options ?? throw new ArgumentNullException(nameof(options)); | ||
} | ||
|
||
public void EnsureExchangeExists(IModel model, string name, string exchangeType) | ||
{ | ||
model.ExchangeDeclare(name, exchangeType, _options.IsDurable, _options.IsAutoDelete, _options.Properties); | ||
} | ||
} | ||
|
||
public class ExchangeOptions | ||
{ | ||
public bool IsDurable { get; set; } | ||
|
||
public bool IsAutoDelete { get; set; } | ||
|
||
public IDictionary<string, object> Properties { get; set; } | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/engines/Nybus.Engine.RabbitMq/Configuration/IQueueFactory.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
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
27 changes: 27 additions & 0 deletions
27
tests/Tests.Nybus.Engine.RabbitMq/Configuration/ExchangeManagerTests.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,27 @@ | ||
using AutoFixture.Idioms; | ||
using AutoFixture.NUnit3; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Nybus.Configuration; | ||
using RabbitMQ.Client; | ||
|
||
namespace Tests.Configuration | ||
{ | ||
[TestFixture] | ||
public class ExchangeManagerTests | ||
{ | ||
[Test, AutoMoqData] | ||
public void Constructor_is_guarded(GuardClauseAssertion assertion) | ||
{ | ||
assertion.Verify(typeof(ExchangeManager).GetConstructors()); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void EnsureExchangeExists_forwards_settings([Frozen] ExchangeOptions options, ExchangeManager sut, IModel model, string exchangeName, string exchangeType) | ||
{ | ||
sut.EnsureExchangeExists(model, exchangeName, exchangeType); | ||
|
||
Mock.Get(model).Verify(p => p.ExchangeDeclare(exchangeName, exchangeType, options.IsDurable, options.IsAutoDelete, options.Properties)); | ||
} | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
tests/Tests.Nybus.Engine.RabbitMq/Configuration/RabbitMqOptionsBindingTests.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,121 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Configuration; | ||
using NUnit.Framework; | ||
using Nybus.Configuration; | ||
|
||
namespace Tests.Configuration | ||
{ | ||
[TestFixture] | ||
public class RabbitMqOptionsBindingTests | ||
{ | ||
private static IConfiguration CreateConfiguration(IDictionary<string, string> settings) | ||
{ | ||
var builder = new ConfigurationBuilder(); | ||
builder.AddInMemoryCollection(settings); | ||
|
||
return builder.Build(); | ||
} | ||
|
||
[Test] | ||
public void CommandExchange_IsAutoDelete_is_correctly_bound([Values] bool value) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.IsAutoDelete)}"] = value.ToString() | ||
}; | ||
|
||
var configuration = CreateConfiguration(settings); | ||
|
||
var sut = new RabbitMqOptions(); | ||
|
||
configuration.Bind(sut); | ||
|
||
Assert.That(sut.CommandExchange.IsAutoDelete, Is.EqualTo(value)); | ||
} | ||
|
||
[Test] | ||
public void CommandExchange_IsDurable_is_correctly_bound([Values] bool value) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.IsDurable)}"] = value.ToString() | ||
}; | ||
|
||
var configuration = CreateConfiguration(settings); | ||
|
||
var sut = new RabbitMqOptions(); | ||
|
||
configuration.Bind(sut); | ||
|
||
Assert.That(sut.CommandExchange.IsDurable, Is.EqualTo(value)); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void CommandExchange_Properties_is_correctly_bound(string key, string value) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.Properties)}:{key}"] = value | ||
}; | ||
|
||
var configuration = CreateConfiguration(settings); | ||
|
||
var sut = new RabbitMqOptions(); | ||
|
||
configuration.Bind(sut); | ||
|
||
Assert.That(sut.CommandExchange.Properties[key], Is.EqualTo(value)); | ||
} | ||
|
||
[Test] | ||
public void EventExchange_IsAutoDelete_is_correctly_bound([Values] bool value) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.IsAutoDelete)}"] = value.ToString() | ||
}; | ||
|
||
var configuration = CreateConfiguration(settings); | ||
|
||
var sut = new RabbitMqOptions(); | ||
|
||
configuration.Bind(sut); | ||
|
||
Assert.That(sut.EventExchange.IsAutoDelete, Is.EqualTo(value)); | ||
} | ||
|
||
[Test] | ||
public void EventExchange_IsDurable_is_correctly_bound([Values] bool value) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.IsDurable)}"] = value.ToString() | ||
}; | ||
|
||
var configuration = CreateConfiguration(settings); | ||
|
||
var sut = new RabbitMqOptions(); | ||
|
||
configuration.Bind(sut); | ||
|
||
Assert.That(sut.EventExchange.IsDurable, Is.EqualTo(value)); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public void EventExchange_Properties_is_correctly_bound(string key, string value) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.Properties)}:{key}"] = value | ||
}; | ||
|
||
var configuration = CreateConfiguration(settings); | ||
|
||
var sut = new RabbitMqOptions(); | ||
|
||
configuration.Bind(sut); | ||
|
||
Assert.That(sut.EventExchange.Properties[key], Is.EqualTo(value)); | ||
} | ||
} | ||
} |
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