Skip to content

Commit

Permalink
Added more tests for RabbitMQ configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Kralizek committed Feb 22, 2019
1 parent 9f0324c commit ebe6b9a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public void Configure_usages_are_additive(RabbitMqConfigurator sut, TestNybusCon
}
}

[Test, CustomAutoMoqData]
public void Configure_does_not_accept_null_delegates(RabbitMqConfigurator sut, TestNybusConfigurator configurator, IConfigurationFactory configurationFactory, RabbitMqOptions options)
{
Assert.Throws<ArgumentNullException>(() => sut.Configure(null));
}

[Test, CustomAutoMoqData]
public void UseConfiguration_binds_values_to_options(RabbitMqConfigurator sut, TestNybusConfigurator configurator, IConfigurationFactory configurationFactory, string nybusSectionName, string rabbitMqSectionName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Configuration;
using NUnit.Framework;
using Nybus.Configuration;
Expand All @@ -17,11 +18,12 @@ private static IConfiguration CreateConfiguration(IDictionary<string, string> se
}

[Test]
public void CommandExchange_IsAutoDelete_is_correctly_bound([Values] bool value)
public void CommandExchange_is_correctly_bound([Values] bool autoDelete, [Values] bool durable)
{
var settings = new Dictionary<string, string>
{
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.IsAutoDelete)}"] = value.ToString()
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.IsAutoDelete)}"] = autoDelete.ToString(),
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.IsDurable)}"] = durable.ToString(),
};

var configuration = CreateConfiguration(settings);
Expand All @@ -30,15 +32,34 @@ public void CommandExchange_IsAutoDelete_is_correctly_bound([Values] bool value)

configuration.Bind(sut);

Assert.That(sut.CommandExchange.IsAutoDelete, Is.EqualTo(value));
Assert.That(sut.CommandExchange.IsAutoDelete, Is.EqualTo(autoDelete));
Assert.That(sut.CommandExchange.IsDurable, Is.EqualTo(durable));
}

[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 CommandExchange_IsDurable_is_correctly_bound([Values] bool value)
public void EventExchange_is_correctly_bound([Values] bool autoDelete, [Values] bool durable)
{
var settings = new Dictionary<string, string>
{
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.IsDurable)}"] = value.ToString()
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.IsAutoDelete)}"] = autoDelete.ToString(),
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.IsDurable)}"] = durable.ToString(),
};

var configuration = CreateConfiguration(settings);
Expand All @@ -47,15 +68,16 @@ public void CommandExchange_IsDurable_is_correctly_bound([Values] bool value)

configuration.Bind(sut);

Assert.That(sut.CommandExchange.IsDurable, Is.EqualTo(value));
Assert.That(sut.EventExchange.IsAutoDelete, Is.EqualTo(autoDelete));
Assert.That(sut.EventExchange.IsDurable, Is.EqualTo(durable));
}

[Test, AutoMoqData]
public void CommandExchange_Properties_is_correctly_bound(string key, string value)
public void EventExchange_Properties_is_correctly_bound(string key, string value)
{
var settings = new Dictionary<string, string>
{
[$"{nameof(RabbitMqOptions.CommandExchange)}:{nameof(ExchangeOptions.Properties)}:{key}"] = value
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.Properties)}:{key}"] = value
};

var configuration = CreateConfiguration(settings);
Expand All @@ -64,15 +86,15 @@ public void CommandExchange_Properties_is_correctly_bound(string key, string val

configuration.Bind(sut);

Assert.That(sut.CommandExchange.Properties[key], Is.EqualTo(value));
Assert.That(sut.EventExchange.Properties[key], Is.EqualTo(value));
}

[Test]
public void EventExchange_IsAutoDelete_is_correctly_bound([Values] bool value)
[Test, CustomAutoMoqData]
public void OutboundEncoding_is_correctly_bound(Encoding encoding)
{
var settings = new Dictionary<string, string>
{
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.IsAutoDelete)}"] = value.ToString()
[$"{nameof(RabbitMqOptions.OutboundEncoding)}"] = encoding.WebName
};

var configuration = CreateConfiguration(settings);
Expand All @@ -81,15 +103,15 @@ public void EventExchange_IsAutoDelete_is_correctly_bound([Values] bool value)

configuration.Bind(sut);

Assert.That(sut.EventExchange.IsAutoDelete, Is.EqualTo(value));
Assert.That(sut.OutboundEncoding, Is.EqualTo(encoding.WebName));
}

[Test]
public void EventExchange_IsDurable_is_correctly_bound([Values] bool value)
[Test, AutoMoqData]
public void ConnectionString_is_correctly_bound(string connectionString)
{
var settings = new Dictionary<string, string>
{
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.IsDurable)}"] = value.ToString()
[$"{nameof(RabbitMqOptions.ConnectionString)}"] = connectionString
};

var configuration = CreateConfiguration(settings);
Expand All @@ -98,15 +120,18 @@ public void EventExchange_IsDurable_is_correctly_bound([Values] bool value)

configuration.Bind(sut);

Assert.That(sut.EventExchange.IsDurable, Is.EqualTo(value));
Assert.That(sut.ConnectionString.Value, Is.EqualTo(connectionString));
}

[Test, AutoMoqData]
public void EventExchange_Properties_is_correctly_bound(string key, string value)
public void ConnectionNode_is_correctly_bound(string userName, string password, string hostName, string vhost)
{
var settings = new Dictionary<string, string>
{
[$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.Properties)}:{key}"] = value
[$"{nameof(RabbitMqOptions.Connection)}:UserName"] = userName,
[$"{nameof(RabbitMqOptions.Connection)}:Password"] = password,
[$"{nameof(RabbitMqOptions.Connection)}:HostName"] = hostName,
[$"{nameof(RabbitMqOptions.Connection)}:VirtualHost"] = vhost,
};

var configuration = CreateConfiguration(settings);
Expand All @@ -115,7 +140,10 @@ public void EventExchange_Properties_is_correctly_bound(string key, string value

configuration.Bind(sut);

Assert.That(sut.EventExchange.Properties[key], Is.EqualTo(value));
Assert.That(sut.Connection["UserName"], Is.EqualTo(userName));
Assert.That(sut.Connection["Password"], Is.EqualTo(password));
Assert.That(sut.Connection["HostName"], Is.EqualTo(hostName));
Assert.That(sut.Connection["VirtualHost"], Is.EqualTo(vhost));
}
}
}

0 comments on commit ebe6b9a

Please sign in to comment.