-
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.
- Loading branch information
Showing
17 changed files
with
815 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Tests { | ||
public static class ObservableTestExtensions | ||
{ | ||
public static IReadOnlyList<T> DumpInList<T>(this IObservable<T> sequence) | ||
{ | ||
var incomingItems = new List<T>(); | ||
|
||
sequence.Subscribe(incomingItems.Add); | ||
|
||
return incomingItems; | ||
} | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
tests/Tests.Integration.Nybus/AutomaticHandlerBareSetupTests.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,79 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Nybus; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class AutomaticHandlerBareSetupTests | ||
{ | ||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand) | ||
{ | ||
var commandReceived = Mock.Of<CommandReceived<SecondTestCommand>>(); | ||
|
||
services.AddLogging(l => l.AddDebug()); | ||
|
||
services.AddSingleton(commandReceived); | ||
services.AddSingleton<ICommandHandler<SecondTestCommand>, SecondTestCommandHandler>(); | ||
|
||
services.AddNybus(nybus => | ||
{ | ||
nybus.UseInMemoryBusEngine(); | ||
nybus.SubscribeToCommand<SecondTestCommand>(); | ||
}); | ||
|
||
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<SecondTestCommand>>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent) | ||
{ | ||
var eventReceived = Mock.Of<EventReceived<SecondTestEvent>>(); | ||
|
||
services.AddLogging(l => l.AddDebug()); | ||
|
||
services.AddSingleton(eventReceived); | ||
services.AddSingleton<IEventHandler<SecondTestEvent>, SecondTestEventHandler>(); | ||
|
||
services.AddNybus(nybus => | ||
{ | ||
nybus.UseInMemoryBusEngine(); | ||
nybus.SubscribeToEvent<SecondTestEvent>(); | ||
}); | ||
|
||
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<SecondTestEvent>>())); | ||
|
||
} | ||
|
||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
tests/Tests.Integration.Nybus/AutomaticHandlerConfigurationSetupTests.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,103 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Nybus; | ||
|
||
namespace Tests | ||
{ | ||
[TestFixture] | ||
public class AutomaticHandlerConfigurationSetupTests | ||
{ | ||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_commands(ServiceCollection services, SecondTestCommand testCommand) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
["Nybus:ErrorPolicy:ProviderName"] = "retry", | ||
["Nybus:ErrorPolicy:MaxRetries"] = "5", | ||
}; | ||
|
||
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings); | ||
var configuration = configurationBuilder.Build(); | ||
|
||
var commandReceived = Mock.Of<CommandReceived<SecondTestCommand>>(); | ||
|
||
services.AddLogging(l => l.AddDebug()); | ||
|
||
services.AddSingleton(commandReceived); | ||
services.AddSingleton<ICommandHandler<SecondTestCommand>, SecondTestCommandHandler>(); | ||
|
||
services.AddNybus(nybus => | ||
{ | ||
nybus.UseInMemoryBusEngine(); | ||
nybus.UseConfiguration(configuration); | ||
nybus.SubscribeToCommand<SecondTestCommand>(); | ||
}); | ||
|
||
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<SecondTestCommand>>())); | ||
} | ||
|
||
[Test, AutoMoqData] | ||
public async Task Host_can_loopback_events(ServiceCollection services, SecondTestEvent testEvent) | ||
{ | ||
var settings = new Dictionary<string, string> | ||
{ | ||
["Nybus:ErrorPolicy:ProviderName"] = "retry", | ||
["Nybus:ErrorPolicy:MaxRetries"] = "5", | ||
}; | ||
|
||
var configurationBuilder = new ConfigurationBuilder().AddInMemoryCollection(settings); | ||
var configuration = configurationBuilder.Build(); | ||
|
||
var eventReceived = Mock.Of<EventReceived<SecondTestEvent>>(); | ||
|
||
services.AddLogging(l => l.AddDebug()); | ||
|
||
services.AddSingleton(eventReceived); | ||
services.AddSingleton<IEventHandler<SecondTestEvent>, SecondTestEventHandler>(); | ||
|
||
services.AddNybus(nybus => | ||
{ | ||
nybus.UseInMemoryBusEngine(); | ||
nybus.UseConfiguration(configuration); | ||
nybus.SubscribeToEvent<SecondTestEvent>(); | ||
}); | ||
|
||
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<SecondTestEvent>>())); | ||
|
||
} | ||
|
||
} | ||
} |
Oops, something went wrong.