diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props
index 5fad0f4..ad1ff31 100644
--- a/tests/Directory.Build.props
+++ b/tests/Directory.Build.props
@@ -4,10 +4,10 @@
-
-
-
-
+
+
+
+
diff --git a/tests/Tests.Nybus.Abstractions/Configuration/NybusConfiguratorExtensionsTests.cs b/tests/Tests.Nybus.Abstractions/Configuration/NybusConfiguratorExtensionsTests.cs
index 77501be..da2340d 100644
--- a/tests/Tests.Nybus.Abstractions/Configuration/NybusConfiguratorExtensionsTests.cs
+++ b/tests/Tests.Nybus.Abstractions/Configuration/NybusConfiguratorExtensionsTests.cs
@@ -29,10 +29,8 @@ public void UseBusEngine_registers_BusEngine(INybusConfigurator configurator, Te
}
[Test, CustomAutoMoqData]
- public void ServiceConfigurator_delegate_is_registered(INybusConfigurator configurator, TestBusEngine engine)
+ public void ServiceConfigurator_delegate_is_registered(INybusConfigurator configurator, TestBusEngine engine, Action serviceConfigurator)
{
- var serviceConfigurator = Mock.Of>();
-
NybusConfiguratorExtensions.UseBusEngine(configurator, serviceConfigurator);
Mock.Get(configurator).Verify(p => p.AddServiceConfiguration(serviceConfigurator));
diff --git a/tests/Tests.Nybus.Engine.InMemory/InMemory/InMemoryBusEngineTests.cs b/tests/Tests.Nybus.Engine.InMemory/InMemory/InMemoryBusEngineTests.cs
index 8fd8b7c..be6e71c 100644
--- a/tests/Tests.Nybus.Engine.InMemory/InMemory/InMemoryBusEngineTests.cs
+++ b/tests/Tests.Nybus.Engine.InMemory/InMemory/InMemoryBusEngineTests.cs
@@ -175,9 +175,8 @@ public void NotifySuccess_returns_completed_task(InMemoryBusEngine sut, CommandM
}
[Test, CustomAutoMoqData]
- public void NotifySuccess_raises_event(InMemoryBusEngine sut, CommandMessage testMessage)
+ public void NotifySuccess_raises_event(InMemoryBusEngine sut, CommandMessage testMessage, EventHandler handler)
{
- var handler = Mock.Of >();
sut.OnMessageNotifySuccess += handler;
sut.NotifySuccessAsync(testMessage);
@@ -188,9 +187,8 @@ public void NotifySuccess_raises_event(InMemoryBusEngine sut, CommandMessage testMessage)
+ public void NotifySuccess_raises_event(InMemoryBusEngine sut, EventMessage testMessage, EventHandler handler)
{
- var handler = Mock.Of>();
sut.OnMessageNotifySuccess += handler;
sut.NotifySuccessAsync(testMessage);
@@ -219,9 +217,8 @@ public void NotifyFail_returns_completed_task(InMemoryBusEngine sut, EventMessag
}
[Test, CustomAutoMoqData]
- public void NotifyFail_raises_event(InMemoryBusEngine sut, CommandMessage testMessage)
+ public void NotifyFail_raises_event(InMemoryBusEngine sut, CommandMessage testMessage, EventHandler handler)
{
- var handler = Mock.Of>();
sut.OnMessageNotifyFail += handler;
sut.NotifyFailAsync(testMessage);
@@ -232,9 +229,8 @@ public void NotifyFail_raises_event(InMemoryBusEngine sut, CommandMessage testMessage)
+ public void NotifyFail_raises_event(InMemoryBusEngine sut, EventMessage testMessage, EventHandler handler)
{
- var handler = Mock.Of>();
sut.OnMessageNotifyFail += handler;
sut.NotifyFailAsync(testMessage);
diff --git a/tests/Tests.Nybus.Engine.RabbitMq/RabbitMq/ObservableConsumerTests.cs b/tests/Tests.Nybus.Engine.RabbitMq/RabbitMq/ObservableConsumerTests.cs
index 0e9646d..f61ca2e 100644
--- a/tests/Tests.Nybus.Engine.RabbitMq/RabbitMq/ObservableConsumerTests.cs
+++ b/tests/Tests.Nybus.Engine.RabbitMq/RabbitMq/ObservableConsumerTests.cs
@@ -110,10 +110,8 @@ public void HandleBasicCancel_accepts_departing_consumerTag(ObservableConsumer s
}
[Test, CustomAutoMoqData]
- public void HandleBasicCancel_raise_ConsumerCancelled_event(ObservableConsumer sut, string consumerTag)
+ public void HandleBasicCancel_raise_ConsumerCancelled_event(ObservableConsumer sut, string consumerTag, EventHandler eventHandler)
{
- var eventHandler = Mock.Of>();
-
sut.HandleBasicConsumeOk(consumerTag);
sut.ConsumerCancelled += eventHandler;
@@ -134,10 +132,8 @@ public void HandleBasicCancelOk_accepts_departing_consumerTag(ObservableConsumer
}
[Test, CustomAutoMoqData]
- public void HandleBasicCancelOk_raise_ConsumerCancelled_event(ObservableConsumer sut, string consumerTag)
+ public void HandleBasicCancelOk_raise_ConsumerCancelled_event(ObservableConsumer sut, string consumerTag, EventHandler eventHandler)
{
- var eventHandler = Mock.Of>();
-
sut.HandleBasicConsumeOk(consumerTag);
sut.ConsumerCancelled += eventHandler;
diff --git a/tests/Tests.Nybus/Configuration/DelegateWrapperCommandHandlerTests.cs b/tests/Tests.Nybus/Configuration/DelegateWrapperCommandHandlerTests.cs
index 6e9792c..5114d27 100644
--- a/tests/Tests.Nybus/Configuration/DelegateWrapperCommandHandlerTests.cs
+++ b/tests/Tests.Nybus/Configuration/DelegateWrapperCommandHandlerTests.cs
@@ -17,10 +17,8 @@ public void Handler_is_required()
}
[Test, CustomAutoMoqData]
- public async Task Handler_is_executed(IDispatcher dispatcher, ICommandContext context)
+ public async Task Handler_is_executed(IDispatcher dispatcher, ICommandContext context, CommandReceivedAsync handler)
{
- var handler = Mock.Of>();
-
var sut = new DelegateWrapperCommandHandler(handler);
await sut.HandleAsync(dispatcher, context);
@@ -29,9 +27,8 @@ public async Task Handler_is_executed(IDispatcher dispatcher, ICommandContext context, Exception error)
+ public void Handler_errors_are_not_caught(IDispatcher dispatcher, ICommandContext context, Exception error, CommandReceivedAsync handler)
{
- var handler = Mock.Of>();
Mock.Get(handler).Setup(p => p(It.IsAny(), It.IsAny>())).Throws(error);
var sut = new DelegateWrapperCommandHandler(handler);
diff --git a/tests/Tests.Nybus/Configuration/DelegateWrapperEventHandlerTests.cs b/tests/Tests.Nybus/Configuration/DelegateWrapperEventHandlerTests.cs
index 86d01e6..5b8abe7 100644
--- a/tests/Tests.Nybus/Configuration/DelegateWrapperEventHandlerTests.cs
+++ b/tests/Tests.Nybus/Configuration/DelegateWrapperEventHandlerTests.cs
@@ -17,10 +17,8 @@ public void Handler_is_required()
}
[Test, CustomAutoMoqData]
- public async Task Handler_is_executed(IDispatcher dispatcher, IEventContext context)
+ public async Task Handler_is_executed(IDispatcher dispatcher, IEventContext context, EventReceivedAsync handler)
{
- var handler = Mock.Of>();
-
var sut = new DelegateWrapperEventHandler(handler);
await sut.HandleAsync(dispatcher, context);
@@ -29,9 +27,8 @@ public async Task Handler_is_executed(IDispatcher dispatcher, IEventContext context, Exception error)
+ public void Handler_errors_are_not_caught(IDispatcher dispatcher, IEventContext context, Exception error, EventReceivedAsync handler)
{
- var handler = Mock.Of>();
Mock.Get(handler).Setup(p => p(It.IsAny(), It.IsAny>())).Throws(error);
var sut = new DelegateWrapperEventHandler(handler);
diff --git a/tests/Tests.Nybus/Configuration/NybusConfiguratorTests.cs b/tests/Tests.Nybus/Configuration/NybusConfiguratorTests.cs
index ad70c60..cd3bf2a 100644
--- a/tests/Tests.Nybus/Configuration/NybusConfiguratorTests.cs
+++ b/tests/Tests.Nybus/Configuration/NybusConfiguratorTests.cs
@@ -21,10 +21,8 @@ public void AddServiceConfiguration_configures_given_service(NybusConfigurator s
}
[Test, CustomAutoMoqData]
- public void AddServiceConfiguration_invokes_configuration_delegate(NybusConfigurator sut, IServiceCollection services)
+ public void AddServiceConfiguration_invokes_configuration_delegate(NybusConfigurator sut, IServiceCollection services, Action configurationDelegate)
{
- var configurationDelegate = Mock.Of>();
-
sut.AddServiceConfiguration(configurationDelegate);
sut.ConfigureServices(services);
@@ -39,10 +37,8 @@ public void AddServiceConfiguration_requires_non_null_configuration_delegate(Nyb
}
[Test, CustomAutoMoqData]
- public void AddSubscription_configures(NybusConfigurator sut, ISubscriptionBuilder subscriptionBuilder)
+ public void AddSubscription_configures(NybusConfigurator sut, ISubscriptionBuilder subscriptionBuilder, Action subscriptionDelegate)
{
- var subscriptionDelegate = Mock.Of>();
-
sut.AddSubscription(subscriptionDelegate);
sut.ConfigureBuilder(subscriptionBuilder);
@@ -87,10 +83,8 @@ public void UseConfiguration_uses_default_sectionName(NybusConfigurator sut, ICo
}
[Test, CustomAutoMoqData]
- public void Configure_(NybusConfigurator sut, IServiceProvider serviceProvider, INybusConfiguration configuration)
+ public void Configure_(NybusConfigurator sut, IServiceProvider serviceProvider, INybusConfiguration configuration, Action configurationDelegate)
{
- var configurationDelegate = Mock.Of>();
-
sut.Configure(configurationDelegate);
sut.CustomizeConfiguration(serviceProvider, configuration);
diff --git a/tests/Tests.Nybus/Filters/DiscardErrorFilterTests.cs b/tests/Tests.Nybus/Filters/DiscardErrorFilterTests.cs
index dac7d8c..edb7840 100644
--- a/tests/Tests.Nybus/Filters/DiscardErrorFilterTests.cs
+++ b/tests/Tests.Nybus/Filters/DiscardErrorFilterTests.cs
@@ -19,30 +19,24 @@ public void Constructor_is_guarded(GuardClauseAssertion assertion)
}
[Test, AutoMoqData]
- public async Task HandleErrorAsync_notifies_engine_on_Command([Frozen] IBusEngine engine, DiscardErrorFilter sut, ICommandContext context, Exception exception)
+ public async Task HandleErrorAsync_notifies_engine_on_Command([Frozen] IBusEngine engine, DiscardErrorFilter sut, ICommandContext context, Exception exception, CommandErrorDelegate next)
{
- var next = Mock.Of>();
-
await sut.HandleErrorAsync(context, exception, next);
Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
}
[Test, AutoMoqData]
- public async Task HandleErrorAsync_notifies_engine_on_Event([Frozen] IBusEngine engine, DiscardErrorFilter sut, IEventContext context, Exception exception)
+ public async Task HandleErrorAsync_notifies_engine_on_Event([Frozen] IBusEngine engine, DiscardErrorFilter sut, IEventContext context, Exception exception, EventErrorDelegate next)
{
- var next = Mock.Of>();
-
await sut.HandleErrorAsync(context, exception, next);
Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
}
[Test, AutoMoqData]
- public async Task HandleErrorAsync_forwards_to_next_if_error_on_Command([Frozen] IBusEngine engine, DiscardErrorFilter sut, ICommandContext context, Exception exception, Exception discardException)
+ public async Task HandleErrorAsync_forwards_to_next_if_error_on_Command([Frozen] IBusEngine engine, DiscardErrorFilter sut, ICommandContext context, Exception exception, Exception discardException, CommandErrorDelegate next)
{
- var next = Mock.Of>();
-
Mock.Get(engine).Setup(p => p.NotifyFailAsync(It.IsAny())).ThrowsAsync(discardException);
await sut.HandleErrorAsync(context, exception, next);
@@ -51,10 +45,8 @@ public async Task HandleErrorAsync_forwards_to_next_if_error_on_Command([Frozen]
}
[Test, AutoMoqData]
- public async Task HandleErrorAsync_forwards_to_next_if_error_on_Event([Frozen] IBusEngine engine, DiscardErrorFilter sut, IEventContext context, Exception exception, Exception discardException)
+ public async Task HandleErrorAsync_forwards_to_next_if_error_on_Event([Frozen] IBusEngine engine, DiscardErrorFilter sut, IEventContext context, Exception exception, Exception discardException, EventErrorDelegate next)
{
- var next = Mock.Of>();
-
Mock.Get(engine).Setup(p => p.NotifyFailAsync(It.IsAny())).ThrowsAsync(discardException);
await sut.HandleErrorAsync(context, exception, next);
diff --git a/tests/Tests.Nybus/Filters/FallbackErrorFilterTests.cs b/tests/Tests.Nybus/Filters/FallbackErrorFilterTests.cs
index 44a24ad..694797d 100644
--- a/tests/Tests.Nybus/Filters/FallbackErrorFilterTests.cs
+++ b/tests/Tests.Nybus/Filters/FallbackErrorFilterTests.cs
@@ -19,20 +19,16 @@ public void Constructor_is_guarded(GuardClauseAssertion assertion)
}
[Test, AutoMoqData]
- public async Task HandleErrorAsync_notifies_engine_on_Command([Frozen] IBusEngine engine, FallbackErrorFilter sut, ICommandContext context, Exception exception)
+ public async Task HandleErrorAsync_notifies_engine_on_Command([Frozen] IBusEngine engine, FallbackErrorFilter sut, ICommandContext context, Exception exception, CommandErrorDelegate next)
{
- var next = Mock.Of>();
-
await sut.HandleErrorAsync(context, exception, next);
Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
}
[Test, AutoMoqData]
- public async Task HandleErrorAsync_notifies_engine_on_Event([Frozen] IBusEngine engine, FallbackErrorFilter sut, IEventContext context, Exception exception)
+ public async Task HandleErrorAsync_notifies_engine_on_Event([Frozen] IBusEngine engine, FallbackErrorFilter sut, IEventContext context, Exception exception, EventErrorDelegate next)
{
- var next = Mock.Of>();
-
await sut.HandleErrorAsync(context, exception, next);
Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
diff --git a/tests/Tests.Nybus/Filters/RetryErrorFilterProviderTests.cs b/tests/Tests.Nybus/Filters/RetryErrorFilterProviderTests.cs
index 8b06b05..bf5c2e9 100644
--- a/tests/Tests.Nybus/Filters/RetryErrorFilterProviderTests.cs
+++ b/tests/Tests.Nybus/Filters/RetryErrorFilterProviderTests.cs
@@ -1,5 +1,4 @@
using System;
-using System.Threading.Tasks;
using AutoFixture.Idioms;
using AutoFixture.NUnit3;
using Microsoft.Extensions.Configuration;
@@ -8,7 +7,6 @@
using NUnit.Framework;
using Nybus;
using Nybus.Filters;
-using Nybus.Utils;
namespace Tests.Filters
{
@@ -40,160 +38,4 @@ public void CreateErrorFilter_returns_filter([Frozen] IServiceProvider servicePr
Assert.That(filter, Is.InstanceOf());
}
}
-
- [TestFixture]
- public class RetryErrorFilterTests
- {
- [Test, AutoMoqData]
- public void Constructor_is_guarded(GuardClauseAssertion assertion)
- {
- assertion.Verify(typeof(RetryErrorFilter).GetConstructors());
- }
-
- [Test, AutoMoqData]
- public void MaxRetries_cant_be_negative(IBusEngine engine, ILogger logger, int retries)
- {
- var options = new RetryErrorFilterOptions { MaxRetries = -retries };
-
- Assert.Throws(() => new RetryErrorFilter(engine, options, logger));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_notifies_engine_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_invokes_next_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(next).Verify(p => p(context, error));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_retries_if_retry_count_less_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(engine).Verify(p => p.SendMessageAsync(context.CommandMessage));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_increments_retry_count_if_retry_count_present([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
- Assert.That(context.Message.Headers[Headers.RetryCount], Is.EqualTo((options.MaxRetries - 1).Stringfy()));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_retries_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context)
- {
- var next = Mock.Of>();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(engine).Verify(p => p.SendMessageAsync(context.CommandMessage));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_adds_retry_count_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context)
- {
- var next = Mock.Of>();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_notifies_engine_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_invokes_next_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(next).Verify(p => p(context, error));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_retries_if_retry_count_less_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(engine).Verify(p => p.SendMessageAsync(context.EventMessage));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_increments_retry_count_if_retry_count_present([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context)
- {
- var next = Mock.Of>();
-
- context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
- Assert.That(context.Message.Headers[Headers.RetryCount], Is.EqualTo((options.MaxRetries - 1).Stringfy()));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_retries_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context)
- {
- var next = Mock.Of>();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Mock.Get(engine).Verify(p => p.SendMessageAsync(context.EventMessage));
- }
-
- [Test, CustomAutoMoqData]
- public async Task HandleError_adds_retry_count_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context)
- {
- var next = Mock.Of>();
-
- await sut.HandleErrorAsync(context, error, next);
-
- Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
- }
- }
}
\ No newline at end of file
diff --git a/tests/Tests.Nybus/Filters/RetryErrorFilterTests.cs b/tests/Tests.Nybus/Filters/RetryErrorFilterTests.cs
new file mode 100644
index 0000000..eba42d4
--- /dev/null
+++ b/tests/Tests.Nybus/Filters/RetryErrorFilterTests.cs
@@ -0,0 +1,144 @@
+using System;
+using System.Threading.Tasks;
+using AutoFixture.Idioms;
+using AutoFixture.NUnit3;
+using Microsoft.Extensions.Logging;
+using Moq;
+using NUnit.Framework;
+using Nybus;
+using Nybus.Filters;
+using Nybus.Utils;
+
+namespace Tests.Filters {
+ [TestFixture]
+ public class RetryErrorFilterTests
+ {
+ [Test, AutoMoqData]
+ public void Constructor_is_guarded(GuardClauseAssertion assertion)
+ {
+ assertion.Verify(typeof(RetryErrorFilter).GetConstructors());
+ }
+
+ [Test, AutoMoqData]
+ public void MaxRetries_cant_be_negative(IBusEngine engine, ILogger logger, int retries)
+ {
+ var options = new RetryErrorFilterOptions { MaxRetries = -retries };
+
+ Assert.Throws(() => new RetryErrorFilter(engine, options, logger));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_notifies_engine_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context, CommandErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_invokes_next_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context, CommandErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(next).Verify(p => p(context, error));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_retries_if_retry_count_less_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context, CommandErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(engine).Verify(p => p.SendMessageAsync(context.CommandMessage));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_increments_retry_count_if_retry_count_present([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context, CommandErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
+ Assert.That(context.Message.Headers[Headers.RetryCount], Is.EqualTo((options.MaxRetries - 1).Stringfy()));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_retries_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context, CommandErrorDelegate next)
+ {
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(engine).Verify(p => p.SendMessageAsync(context.CommandMessage));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_adds_retry_count_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusCommandContext context, CommandErrorDelegate next)
+ {
+ await sut.HandleErrorAsync(context, error, next);
+
+ Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_notifies_engine_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context, EventErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(engine).Verify(p => p.NotifyFailAsync(context.Message));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_invokes_next_if_retry_count_equal_or_greater_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context, EventErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = options.MaxRetries.Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(next).Verify(p => p(context, error));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_retries_if_retry_count_less_than_maxRetries([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context, EventErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(engine).Verify(p => p.SendMessageAsync(context.EventMessage));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_increments_retry_count_if_retry_count_present([Frozen] RetryErrorFilterOptions options, [Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context, EventErrorDelegate next)
+ {
+ context.Message.Headers[Headers.RetryCount] = (options.MaxRetries - 2).Stringfy();
+
+ await sut.HandleErrorAsync(context, error, next);
+
+ Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
+ Assert.That(context.Message.Headers[Headers.RetryCount], Is.EqualTo((options.MaxRetries - 1).Stringfy()));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_retries_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context, EventErrorDelegate next)
+ {
+ await sut.HandleErrorAsync(context, error, next);
+
+ Mock.Get(engine).Verify(p => p.SendMessageAsync(context.EventMessage));
+ }
+
+ [Test, CustomAutoMoqData]
+ public async Task HandleError_adds_retry_count_if_retry_count_not_present([Frozen] IBusEngine engine, RetryErrorFilter sut, Exception error, NybusEventContext context, EventErrorDelegate next)
+ {
+ await sut.HandleErrorAsync(context, error, next);
+
+ Assert.That(context.Message.Headers.ContainsKey(Headers.RetryCount));
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/Tests.Nybus/NybusConfiguratorExtensionsTests.cs b/tests/Tests.Nybus/NybusConfiguratorExtensionsTests.cs
index de161b0..443e25d 100644
--- a/tests/Tests.Nybus/NybusConfiguratorExtensionsTests.cs
+++ b/tests/Tests.Nybus/NybusConfiguratorExtensionsTests.cs
@@ -36,10 +36,8 @@ public void SubscribeToCommand_registers_handler_type(TestNybusConfigurator nybu
}
[Test, CustomAutoMoqData]
- public void SubscribeToCommand_registers_async_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder)
+ public void SubscribeToCommand_registers_async_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder, CommandReceivedAsync testHandler)
{
- var testHandler = Mock.Of>();
-
NybusConfiguratorExtensions.SubscribeToCommand(nybus, testHandler);
nybus.ApplySubscriptions(subscriptionBuilder);
@@ -48,10 +46,8 @@ public void SubscribeToCommand_registers_async_delegate_handler_for_command(Test
}
[Test, CustomAutoMoqData]
- public void SubscribeToCommand_registers_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder)
+ public void SubscribeToCommand_registers_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder, CommandReceivedAsync testHandler)
{
- var testHandler = Mock.Of>();
-
NybusConfiguratorExtensions.SubscribeToCommand(nybus, testHandler);
nybus.ApplySubscriptions(subscriptionBuilder);
@@ -60,10 +56,8 @@ public void SubscribeToCommand_registers_delegate_handler_for_command(TestNybusC
}
[Test, CustomAutoMoqData]
- public void SubscribeToCommand_registers_delegate_handler_type(TestNybusConfigurator nybus, IServiceCollection services)
+ public void SubscribeToCommand_registers_delegate_handler_type(TestNybusConfigurator nybus, IServiceCollection services, CommandReceivedAsync testHandler)
{
- var testHandler = Mock.Of>();
-
NybusConfiguratorExtensions.SubscribeToCommand(nybus, testHandler);
nybus.ApplyServiceConfigurations(services);
@@ -122,10 +116,8 @@ public void SubscribeToEvent_registers_handler_type(TestNybusConfigurator nybus,
}
[Test, CustomAutoMoqData]
- public void SubscribeToEvent_registers_async_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder)
+ public void SubscribeToEvent_registers_async_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder, EventReceivedAsync testHandler)
{
- var testHandler = Mock.Of>();
-
NybusConfiguratorExtensions.SubscribeToEvent(nybus, testHandler);
nybus.ApplySubscriptions(subscriptionBuilder);
@@ -134,10 +126,8 @@ public void SubscribeToEvent_registers_async_delegate_handler_for_command(TestNy
}
[Test, CustomAutoMoqData]
- public void SubscribeToEvent_registers_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder)
+ public void SubscribeToEvent_registers_delegate_handler_for_command(TestNybusConfigurator nybus, ISubscriptionBuilder subscriptionBuilder, EventReceivedAsync testHandler)
{
- var testHandler = Mock.Of>();
-
NybusConfiguratorExtensions.SubscribeToEvent(nybus, testHandler);
nybus.ApplySubscriptions(subscriptionBuilder);
@@ -146,10 +136,8 @@ public void SubscribeToEvent_registers_delegate_handler_for_command(TestNybusCon
}
[Test, CustomAutoMoqData]
- public void SubscribeToEvent_registers_delegate_handler_type(TestNybusConfigurator nybus, IServiceCollection services)
+ public void SubscribeToEvent_registers_delegate_handler_type(TestNybusConfigurator nybus, IServiceCollection services, EventReceivedAsync testHandler)
{
- var testHandler = Mock.Of>();
-
NybusConfiguratorExtensions.SubscribeToEvent(nybus, testHandler);
nybus.ApplyServiceConfigurations(services);
@@ -198,10 +186,8 @@ public void RegisterErrorFilterProvider_adds_provider_with_default_setup(TestNyb
}
[Test, CustomAutoMoqData]
- public void RegisterErrorFilterProvider_adds_provider_with_custom_setup(TestNybusConfigurator nybus, IServiceCollection services)
+ public void RegisterErrorFilterProvider_adds_provider_with_custom_setup(TestNybusConfigurator nybus, IServiceCollection services, Func providerFactory)
{
- var providerFactory = Mock.Of>();
-
NybusConfiguratorExtensions.RegisterErrorFilterProvider(nybus, providerFactory);
nybus.ApplyServiceConfigurations(services);
diff --git a/tests/Tests.Nybus/NybusHostTests.cs b/tests/Tests.Nybus/NybusHostTests.cs
index 09f2898..8fb4965 100644
--- a/tests/Tests.Nybus/NybusHostTests.cs
+++ b/tests/Tests.Nybus/NybusHostTests.cs
@@ -118,14 +118,12 @@ public async Task StopAsync_stops_the_engine_if_started([Frozen] IBusEngine engi
}
[Test, CustomAutoMoqData]
- public async Task Handler_is_executed_when_commandMessages_are_processed([Frozen] IBusEngine engine, NybusHost sut, CommandMessage testMessage)
+ public async Task Handler_is_executed_when_commandMessages_are_processed([Frozen] IBusEngine engine, NybusHost sut, CommandMessage testMessage, CommandReceivedAsync receivedMessage)
{
var subject = new Subject();
Mock.Get(engine).Setup(p => p.StartAsync()).ReturnsAsync(subject);
- var receivedMessage = Mock.Of>();
-
sut.SubscribeToCommand(receivedMessage);
await sut.StartAsync();
@@ -138,14 +136,12 @@ public async Task Handler_is_executed_when_commandMessages_are_processed([Frozen
}
[Test, CustomAutoMoqData]
- public async Task Null_messages_delivered_from_engine_are_discarded([Frozen] IBusEngine engine, NybusHost sut, CommandMessage testMessage)
+ public async Task Null_messages_delivered_from_engine_are_discarded([Frozen] IBusEngine engine, NybusHost sut, CommandMessage testMessage, CommandReceivedAsync receivedMessage)
{
var subject = new Subject();
Mock.Get(engine).Setup(p => p.StartAsync()).ReturnsAsync(subject);
- var receivedMessage = Mock.Of>();
-
sut.SubscribeToCommand(receivedMessage);
await sut.StartAsync();
@@ -158,14 +154,12 @@ public async Task Null_messages_delivered_from_engine_are_discarded([Frozen] IBu
}
[Test, CustomAutoMoqData]
- public async Task Handler_is_executed_when_eventMessages_are_processed([Frozen] IBusEngine engine, NybusHost sut, EventMessage testMessage)
+ public async Task Handler_is_executed_when_eventMessages_are_processed([Frozen] IBusEngine engine, NybusHost sut, EventMessage testMessage, EventReceivedAsync receivedMessage)
{
var subject = new Subject();
Mock.Get(engine).Setup(p => p.StartAsync()).ReturnsAsync(subject);
- var receivedMessage = Mock.Of>();
-
sut.SubscribeToEvent(receivedMessage);
await sut.StartAsync();
@@ -178,14 +172,12 @@ public async Task Handler_is_executed_when_eventMessages_are_processed([Frozen]
}
[Test, CustomAutoMoqData]
- public async Task Null_messages_delivered_from_engine_are_discarded([Frozen] IBusEngine engine, NybusHost sut, EventMessage testMessage)
+ public async Task Null_messages_delivered_from_engine_are_discarded([Frozen] IBusEngine engine, NybusHost sut, EventMessage testMessage, EventReceivedAsync receivedMessage)
{
var subject = new Subject();
Mock.Get(engine).Setup(p => p.StartAsync()).ReturnsAsync(subject);
- var receivedMessage = Mock.Of>();
-
sut.SubscribeToEvent(receivedMessage);
await sut.StartAsync();
diff --git a/tests/Tests.Nybus/ServiceCollectionExtensionsTests.cs b/tests/Tests.Nybus/ServiceCollectionExtensionsTests.cs
index 409a038..8d43f4f 100644
--- a/tests/Tests.Nybus/ServiceCollectionExtensionsTests.cs
+++ b/tests/Tests.Nybus/ServiceCollectionExtensionsTests.cs
@@ -12,16 +12,8 @@ namespace Tests
[TestFixture]
public class ServiceCollectionExtensionsTests
{
- private Action configuratorDelegate;
-
- [SetUp]
- public void Initialize()
- {
- configuratorDelegate = Mock.Of>();
- }
-
[Test, CustomAutoMoqData]
- public void ServiceCollection_is_returned(IServiceCollection services)
+ public void ServiceCollection_is_returned(IServiceCollection services, Action configuratorDelegate)
{
var result = ServiceCollectionExtensions.AddNybus(services, configuratorDelegate);
@@ -29,7 +21,7 @@ public void ServiceCollection_is_returned(IServiceCollection services)
}
[Test, CustomAutoMoqData]
- public void AddNybus_invokes_configuratorDelegate(IServiceCollection services)
+ public void AddNybus_invokes_configuratorDelegate(IServiceCollection services, Action configuratorDelegate)
{
ServiceCollectionExtensions.AddNybus(services, configuratorDelegate);
@@ -42,7 +34,7 @@ public void AddNybus_invokes_configuratorDelegate(IServiceCollection services)
[InlineAutoMoqData(typeof(NybusHost))]
[InlineAutoMoqData(typeof(IBusHost))]
[InlineAutoMoqData(typeof(IBus))]
- public void AddNybus_registers_services(Type serviceType, IServiceCollection services)
+ public void AddNybus_registers_services(Type serviceType, IServiceCollection services, Action configuratorDelegate)
{
ServiceCollectionExtensions.AddNybus(services, configuratorDelegate);
@@ -50,7 +42,7 @@ public void AddNybus_registers_services(Type serviceType, IServiceCollection ser
}
[Test, CustomAutoMoqData]
- public void AddNybus_registers_NybusHostOptions(IServiceCollection services, IConfigurationSection configuration)
+ public void AddNybus_registers_NybusHostOptions(IServiceCollection services, IConfigurationSection configuration, Action configuratorDelegate)
{
ServiceCollectionExtensions.AddNybus(services, configuratorDelegate);
diff --git a/tests/Tests.Nybus/SetupTests.cs b/tests/Tests.Nybus/SetupTests.cs
index dfdbd41..a04656b 100644
--- a/tests/Tests.Nybus/SetupTests.cs
+++ b/tests/Tests.Nybus/SetupTests.cs
@@ -46,10 +46,8 @@ public void Logging_is_required()
}
[Test, AutoMoqData]
- public void Configuration_delegate_is_invoked_when_assembling_the_host(ILoggerFactory loggerFactory)
+ public void Configuration_delegate_is_invoked_when_assembling_the_host(ILoggerFactory loggerFactory, Action configurationDelegate)
{
- var configurationDelegate = Mock.Of>();
-
var services = new ServiceCollection();
services.AddSingleton(loggerFactory);
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerBareSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerBareSetupTests.cs
index e547207..1a444a4 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerBareSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerBareSetupTests.cs
@@ -11,10 +11,8 @@ namespace Tests
public class AutomaticHandlerBareSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(commandReceived);
@@ -43,10 +41,8 @@ public async Task Host_can_loopback_commands(ServiceCollection services, SecondT
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(eventReceived);
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerConfigurationSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerConfigurationSetupTests.cs
index 72c68c9..76ea99d 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerConfigurationSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/AutomaticHandlerConfigurationSetupTests.cs
@@ -13,7 +13,7 @@ namespace Tests
public class AutomaticHandlerConfigurationSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, CommandReceivedAsync commandReceived)
{
var settings = new Dictionary
{
@@ -24,8 +24,6 @@ public async Task Host_can_loopback_commands(ServiceCollection services, SecondT
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(commandReceived);
@@ -56,7 +54,7 @@ public async Task Host_can_loopback_commands(ServiceCollection services, SecondT
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent, EventReceivedAsync eventReceived)
{
var settings = new Dictionary
{
@@ -67,8 +65,6 @@ public async Task Host_can_loopback_events(ServiceCollection services, SecondTes
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(eventReceived);
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerBareSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerBareSetupTests.cs
index 6808438..922149e 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerBareSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerBareSetupTests.cs
@@ -11,10 +11,8 @@ namespace Tests
public class DelegateHandlerBareSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
@@ -40,10 +38,8 @@ public async Task Host_can_loopback_commands(ServiceCollection services, FirstTe
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, FirstTestEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, FirstTestEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerConfigurationSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerConfigurationSetupTests.cs
index 2bb553c..1a013a9 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerConfigurationSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/DelegateHandlerConfigurationSetupTests.cs
@@ -13,10 +13,8 @@ namespace Tests
public class DelegateHandlerConfigurationSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
var settings = new Dictionary
{
["Nybus:ErrorPolicy:ProviderName"] = "retry",
@@ -53,7 +51,7 @@ public async Task Host_can_loopback_commands(ServiceCollection services, FirstTe
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, FirstTestEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, FirstTestEvent testEvent, EventReceivedAsync eventReceived)
{
var settings = new Dictionary
{
@@ -64,8 +62,6 @@ public async Task Host_can_loopback_events(ServiceCollection services, FirstTest
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/HeaderTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/HeaderTests.cs
index c4d4282..8ea6448 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/HeaderTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/HeaderTests.cs
@@ -12,10 +12,8 @@ namespace Tests
public class HeaderTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, string headerKey, string headerValue)
+ public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, CommandReceivedAsync commandReceived, string headerKey, string headerValue)
{
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(commandReceived);
@@ -49,10 +47,8 @@ public async Task Host_can_loopback_commands(ServiceCollection services, SecondT
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent, string headerKey, string headerValue)
+ public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent, EventReceivedAsync eventReceived, string headerKey, string headerValue)
{
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(eventReceived);
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/MessageAttributeTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/MessageAttributeTests.cs
index d8c5663..10b1353 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/MessageAttributeTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/MessageAttributeTests.cs
@@ -12,10 +12,8 @@ namespace Tests
public class MessageAttributeTests
{
[Test, AutoMoqData]
- public async Task Commands_are_matched_via_MessageAttribute(ServiceCollection services, ThirdTestCommand testCommand)
+ public async Task Commands_are_matched_via_MessageAttribute(ServiceCollection services, ThirdTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
@@ -41,10 +39,8 @@ public async Task Commands_are_matched_via_MessageAttribute(ServiceCollection se
}
[Test, AutoMoqData]
- public async Task Events_are_matched_via_MessageAttribute(ServiceCollection services, ThirdTestEvent testEvent)
+ public async Task Events_are_matched_via_MessageAttribute(ServiceCollection services, ThirdTestEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
@@ -70,10 +66,8 @@ public async Task Events_are_matched_via_MessageAttribute(ServiceCollection serv
}
[Test, AutoMoqData]
- public async Task Commands_are_correctly_converted(ServiceCollection services, ThirdTestCommand testCommand)
+ public async Task Commands_are_correctly_converted(ServiceCollection services, ThirdTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
@@ -99,10 +93,8 @@ public async Task Commands_are_correctly_converted(ServiceCollection services, T
}
[Test, AutoMoqData]
- public async Task Events_are_correctly_converted(ServiceCollection services, ThirdTestEvent testEvent)
+ public async Task Events_are_correctly_converted(ServiceCollection services, ThirdTestEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/NoNamespaceMessageTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/NoNamespaceMessageTests.cs
index 0714e69..3ec7d22 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/NoNamespaceMessageTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/NoNamespaceMessageTests.cs
@@ -11,10 +11,8 @@ namespace Tests
public class NoNamespaceMessageTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, NoNamespaceCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, NoNamespaceCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
@@ -40,10 +38,8 @@ public async Task Host_can_loopback_commands(ServiceCollection services, NoNames
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, NoNamespaceEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, NoNamespaceEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerBareSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerBareSetupTests.cs
index a8a78ba..d977cb7 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerBareSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerBareSetupTests.cs
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
+using AutoFixture.NUnit3;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
@@ -11,12 +12,8 @@ namespace Tests
public class RegisteredHandlerBareSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, [Frozen] CommandReceivedAsync commandReceived, SecondTestCommandHandler handler)
{
- var commandReceived = Mock.Of>();
- var mockHandler = new Mock(commandReceived);
- var handler = mockHandler.Object;
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(commandReceived);
@@ -45,12 +42,8 @@ public async Task Host_can_loopback_commands(ServiceCollection services, SecondT
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent, [Frozen] EventReceivedAsync eventReceived, SecondTestEventHandler handler)
{
- var eventReceived = Mock.Of>();
- var mockHandler = new Mock(eventReceived);
- var handler = mockHandler.Object;
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(eventReceived);
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerConfigurationSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerConfigurationSetupTests.cs
index a2d4f23..5663d49 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerConfigurationSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/RegisteredHandlerConfigurationSetupTests.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
+using AutoFixture.NUnit3;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -13,7 +14,7 @@ namespace Tests
public class RegisteredHandlerConfigurationSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand, [Frozen] CommandReceivedAsync commandReceived, SecondTestCommandHandler handler)
{
var settings = new Dictionary
{
@@ -24,10 +25,6 @@ public async Task Host_can_loopback_commands(ServiceCollection services, SecondT
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var commandReceived = Mock.Of>();
- var mockHandler = new Mock(commandReceived);
- var handler = mockHandler.Object;
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(commandReceived);
@@ -58,7 +55,7 @@ public async Task Host_can_loopback_commands(ServiceCollection services, SecondT
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent, [Frozen] EventReceivedAsync eventReceived, SecondTestEventHandler handler)
{
var settings = new Dictionary
{
@@ -69,10 +66,6 @@ public async Task Host_can_loopback_events(ServiceCollection services, SecondTes
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var eventReceived = Mock.Of>();
- var mockHandler = new Mock(eventReceived);
- var handler = mockHandler.Object;
-
services.AddLogging(l => l.AddDebug());
services.AddSingleton(eventReceived);
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/SynchronousDelegateHandlerTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/SynchronousDelegateHandlerTests.cs
index 0612130..370b14d 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.InMemory/SynchronousDelegateHandlerTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.InMemory/SynchronousDelegateHandlerTests.cs
@@ -14,10 +14,8 @@ namespace Tests
public class SynchronousDelegateHandlerTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand)
+ public async Task Host_can_loopback_commands(ServiceCollection services, FirstTestCommand testCommand, CommandReceived commandReceived)
{
- var commandReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
@@ -43,10 +41,8 @@ public async Task Host_can_loopback_commands(ServiceCollection services, FirstTe
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(ServiceCollection services, FirstTestEvent testEvent)
+ public async Task Host_can_loopback_events(ServiceCollection services, FirstTestEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
services.AddLogging(l => l.AddDebug());
services.AddNybus(nybus =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerBareSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerBareSetupTests.cs
index 1872d6b..bf8a826 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerBareSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerBareSetupTests.cs
@@ -12,10 +12,8 @@ namespace Tests
public class AutomaticHandlerBareSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand)
+ public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
var host = CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
@@ -41,10 +39,8 @@ public async Task Host_can_loopback_commands(FakeServer server, SecondTestComman
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent)
+ public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
var host = CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerConfigurationSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerConfigurationSetupTests.cs
index b0eb85c..b36cc03 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerConfigurationSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/AutomaticHandlerConfigurationSetupTests.cs
@@ -13,7 +13,7 @@ namespace Tests
public class AutomaticHandlerConfigurationSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand)
+ public async Task Host_can_loopback_commands(FakeServer server, SecondTestCommand testCommand, CommandReceivedAsync commandReceived)
{
var settings = new Dictionary
{
@@ -24,8 +24,6 @@ public async Task Host_can_loopback_commands(FakeServer server, SecondTestComman
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var commandReceived = Mock.Of>();
-
var host = TestUtils.CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
@@ -53,7 +51,7 @@ public async Task Host_can_loopback_commands(FakeServer server, SecondTestComman
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent)
+ public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent testEvent, EventReceivedAsync eventReceived)
{
var settings = new Dictionary
{
@@ -64,8 +62,6 @@ public async Task Host_can_loopback_events(FakeServer server, SecondTestEvent te
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var eventReceived = Mock.Of>();
-
var host = TestUtils.CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerBareConfigurationTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerBareConfigurationTests.cs
index 2adfa9c..3a7a877 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerBareConfigurationTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerBareConfigurationTests.cs
@@ -15,10 +15,8 @@ namespace Tests
public class DelegateHandlerBareConfigurationTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand)
+ public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
var host = CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
@@ -39,10 +37,8 @@ public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent)
+ public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent, EventReceivedAsync eventReceived)
{
- var eventReceived = Mock.Of>();
-
var host = CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
@@ -63,7 +59,7 @@ public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent tes
}
[Test, AutoMoqData]
- public async Task Hosts_can_exchange_commands(FakeServer server, FirstTestCommand testCommand)
+ public async Task Hosts_can_exchange_commands(FakeServer server, FirstTestCommand testCommand, CommandReceivedAsync commandReceived)
{
var sender = CreateNybusHost(nybus =>
{
@@ -73,8 +69,6 @@ public async Task Hosts_can_exchange_commands(FakeServer server, FirstTestComman
});
});
- var commandReceived = Mock.Of>();
-
var receiver = CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
@@ -99,7 +93,7 @@ public async Task Hosts_can_exchange_commands(FakeServer server, FirstTestComman
}
[Test, AutoMoqData]
- public async Task Hosts_can_exchange_events(FakeServer server, FirstTestEvent testEvent)
+ public async Task Hosts_can_exchange_events(FakeServer server, FirstTestEvent testEvent, EventReceivedAsync eventReceived)
{
var sender = CreateNybusHost(nybus =>
{
@@ -109,8 +103,6 @@ public async Task Hosts_can_exchange_events(FakeServer server, FirstTestEvent te
});
});
- var eventReceived = Mock.Of>();
-
var receiver = CreateNybusHost(nybus =>
{
nybus.UseRabbitMqBusEngine(rabbitMq =>
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerConfigurationSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerConfigurationSetupTests.cs
index 35a817f..611007d 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerConfigurationSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/DelegateHandlerConfigurationSetupTests.cs
@@ -13,10 +13,8 @@ namespace Tests
public class DelegateHandlerConfigurationSetupTests
{
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand)
+ public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of>();
-
var settings = new Dictionary
{
["Nybus:ErrorPolicy:ProviderName"] = "retry",
@@ -48,7 +46,7 @@ public async Task Host_can_loopback_commands(FakeServer server, FirstTestCommand
}
[Test, AutoMoqData]
- public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent)
+ public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent testEvent, EventReceivedAsync eventReceived)
{
var settings = new Dictionary
{
@@ -59,8 +57,6 @@ public async Task Host_can_loopback_events(FakeServer server, FirstTestEvent tes
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings);
var configuration = configurationBuilder.Build();
- var eventReceived = Mock.Of>();
-
var host = CreateNybusHost(nybus =>
{
nybus.UseConfiguration(configuration);
diff --git a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/External/AutomaticHandlerBareSetupTests.cs b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/External/AutomaticHandlerBareSetupTests.cs
index 8065477..18a2360 100644
--- a/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/External/AutomaticHandlerBareSetupTests.cs
+++ b/tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/External/AutomaticHandlerBareSetupTests.cs
@@ -31,10 +31,8 @@ public void OnTestComplete()
private string ExchangeName(Type type) => $"{type.Namespace}:{type.Name}";
[Test, AutoMoqData]
- public async Task Host_can_loopback_commands(SecondTestCommand testCommand)
+ public async Task Host_can_loopback_commands(SecondTestCommand testCommand, CommandReceivedAsync commandReceived)
{
- var commandReceived = Mock.Of