-
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.
MessageDescriptor can be created from types with no namespace (#49)
- Loading branch information
Showing
7 changed files
with
246 additions
and
3 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
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
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
71 changes: 71 additions & 0 deletions
71
tests/integration/Tests.Integration.Nybus.Engine.InMemory/NoNamespaceMessageTests.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,71 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Nybus; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class NoNamespaceMessageTests | ||
{ | ||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_commands(ServiceCollection services, NoNamespaceCommand testCommand) | ||
{ | ||
var commandReceived = Mock.Of<CommandReceivedAsync<NoNamespaceCommand>>(); | ||
|
||
services.AddLogging(l => l.AddDebug()); | ||
|
||
services.AddNybus(nybus => | ||
{ | ||
nybus.UseInMemoryBusEngine(); | ||
nybus.SubscribeToCommand(commandReceived); | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var host = serviceProvider.GetRequiredService<IBusHost>(); | ||
|
||
var bus = serviceProvider.GetRequiredService<IBus>(); | ||
|
||
await host.StartAsync(); | ||
|
||
await bus.InvokeCommandAsync(testCommand); | ||
|
||
await host.StopAsync(); | ||
|
||
Mock.Get(commandReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<ICommandContext<NoNamespaceCommand>>()), Times.Once); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_events(ServiceCollection services, NoNamespaceEvent testEvent) | ||
{ | ||
var eventReceived = Mock.Of<EventReceivedAsync<NoNamespaceEvent>>(); | ||
|
||
services.AddLogging(l => l.AddDebug()); | ||
|
||
services.AddNybus(nybus => | ||
{ | ||
nybus.UseInMemoryBusEngine(); | ||
nybus.SubscribeToEvent(eventReceived); | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var host = serviceProvider.GetRequiredService<IBusHost>(); | ||
|
||
var bus = serviceProvider.GetRequiredService<IBus>(); | ||
|
||
await host.StartAsync(); | ||
|
||
await bus.RaiseEventAsync(testEvent); | ||
|
||
await host.StopAsync(); | ||
|
||
Mock.Get(eventReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<IEventContext<NoNamespaceEvent>>()), Times.Once); | ||
} | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
tests/integration/Tests.Integration.Nybus.Engine.RabbitMq/NoNamespaceMessageTests.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,137 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using FakeRabbitMQ; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Nybus; | ||
using Nybus.Configuration; | ||
using static Tests.TestUtils; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class NoNamespaceMessageTests | ||
{ | ||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_commands(FakeServer server, NoNamespaceCommand testCommand) | ||
{ | ||
var commandReceived = Mock.Of<CommandReceivedAsync<NoNamespaceCommand>>(); | ||
|
||
var host = CreateNybusHost(nybus => | ||
{ | ||
nybus.UseRabbitMqBusEngine(rabbitMq => | ||
{ | ||
rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); | ||
}); | ||
nybus.SubscribeToCommand(commandReceived); | ||
}); | ||
|
||
await host.StartAsync(); | ||
|
||
await host.Bus.InvokeCommandAsync(testCommand); | ||
|
||
await host.StopAsync(); | ||
|
||
Mock.Get(commandReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<ICommandContext<NoNamespaceCommand>>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_events(FakeServer server, NoNamespaceEvent testEvent) | ||
{ | ||
var eventReceived = Mock.Of<EventReceivedAsync<NoNamespaceEvent>>(); | ||
|
||
var host = CreateNybusHost(nybus => | ||
{ | ||
nybus.UseRabbitMqBusEngine(rabbitMq => | ||
{ | ||
rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); | ||
}); | ||
nybus.SubscribeToEvent(eventReceived); | ||
}); | ||
|
||
await host.StartAsync(); | ||
|
||
await host.Bus.RaiseEventAsync(testEvent); | ||
|
||
await host.StopAsync(); | ||
|
||
Mock.Get(eventReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<IEventContext<NoNamespaceEvent>>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public async Task Hosts_can_exchange_commands(FakeServer server, NoNamespaceCommand testCommand) | ||
{ | ||
var sender = CreateNybusHost(nybus => | ||
{ | ||
nybus.UseRabbitMqBusEngine(rabbitMq => | ||
{ | ||
rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); | ||
}); | ||
}); | ||
|
||
var commandReceived = Mock.Of<CommandReceivedAsync<NoNamespaceCommand>>(); | ||
|
||
var receiver = CreateNybusHost(nybus => | ||
{ | ||
nybus.UseRabbitMqBusEngine(rabbitMq => | ||
{ | ||
rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); | ||
}); | ||
nybus.SubscribeToCommand(commandReceived); | ||
}); | ||
|
||
await sender.StartAsync(); | ||
|
||
await receiver.StartAsync(); | ||
|
||
await sender.Bus.InvokeCommandAsync(testCommand); | ||
|
||
await receiver.StopAsync(); | ||
|
||
await sender.StopAsync(); | ||
|
||
Mock.Get(commandReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<ICommandContext<NoNamespaceCommand>>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public async Task Hosts_can_exchange_events(FakeServer server, NoNamespaceEvent testEvent) | ||
{ | ||
var sender = CreateNybusHost(nybus => | ||
{ | ||
nybus.UseRabbitMqBusEngine(rabbitMq => | ||
{ | ||
rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); | ||
}); | ||
}); | ||
|
||
var eventReceived = Mock.Of<EventReceivedAsync<NoNamespaceEvent>>(); | ||
|
||
var receiver = CreateNybusHost(nybus => | ||
{ | ||
nybus.UseRabbitMqBusEngine(rabbitMq => | ||
{ | ||
rabbitMq.Configure(configuration => configuration.ConnectionFactory = server.CreateConnectionFactory()); | ||
}); | ||
nybus.SubscribeToEvent(eventReceived); | ||
}); | ||
|
||
await sender.StartAsync(); | ||
|
||
await receiver.StartAsync(); | ||
|
||
await sender.Bus.RaiseEventAsync(testEvent); | ||
|
||
await receiver.StopAsync(); | ||
|
||
await sender.StopAsync(); | ||
|
||
Mock.Get(eventReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<IEventContext<NoNamespaceEvent>>())); | ||
} | ||
} | ||
} |