Skip to content

Commit

Permalink
Fix how MessageDescriptor is constructed (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kralizek committed Feb 20, 2019
1 parent f0aa6df commit 2c6cf7d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Nybus.Abstractions/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class Message

public abstract Type Type { get; }

public MessageDescriptor Descriptor => new MessageDescriptor(Type);
public MessageDescriptor Descriptor => MessageDescriptor.CreateFromType(Type);

public object Item { get; protected set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class Envelope

public Type Type { get; set; }

public MessageDescriptor Descriptor => new MessageDescriptor(Type);
public MessageDescriptor Descriptor => MessageDescriptor.CreateFromType(Type);

public string Content { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ public async Task Commands_are_matched_via_MessageAttribute(ServiceCollection se
Mock.Get(commandReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<ICommandContext<AttributeTestCommand>>()), Times.Once);
}

[Test, AutoMoqData]
public async Task Outgoing_commands_are_marked_via_MessageAttribute(ServiceCollection services, AttributeTestCommand testCommand, CommandReceivedAsync<ThirdTestCommand> commandReceived)
{
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<ThirdTestCommand>>()), Times.Once);

}

[Test, AutoMoqData]
public async Task Events_are_matched_via_MessageAttribute(ServiceCollection services, ThirdTestEvent testEvent, EventReceivedAsync<AttributeTestEvent> eventReceived)
{
Expand Down Expand Up @@ -65,6 +93,34 @@ public async Task Events_are_matched_via_MessageAttribute(ServiceCollection serv
Mock.Get(eventReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<IEventContext<AttributeTestEvent>>()), Times.Once);
}

[Test, AutoMoqData]
public async Task Outgoing_events_are_marked_via_MessageAttribute(ServiceCollection services, AttributeTestEvent testEvent, EventReceivedAsync<ThirdTestEvent> eventReceived)
{
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<ThirdTestEvent>>()), Times.Once);

}

[Test, AutoMoqData]
public async Task Commands_are_correctly_converted(ServiceCollection services, ThirdTestCommand testCommand, CommandReceivedAsync<AttributeTestCommand> commandReceived)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ public async Task Commands_are_matched_via_MessageAttribute(FakeServer server, T
Mock.Get(commandReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<ICommandContext<AttributeTestCommand>>()), Times.Once);
}

[Test, AutoMoqData]
public async Task Outgoing_commands_are_marked_via_MessageAttribute(FakeServer server, AttributeTestCommand testCommand, CommandReceivedAsync<ThirdTestCommand> commandReceived)
{
var host = CreateNybusHost(nybus =>
{
nybus.SubscribeToCommand(commandReceived);
nybus.UseRabbitMqBusEngine(rabbitMq =>
{
rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory());
});
});

await host.StartAsync();

await host.Bus.InvokeCommandAsync(testCommand);

await host.StopAsync();

Mock.Get(commandReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<ICommandContext<ThirdTestCommand>>()), Times.Once);
}

[Test, AutoMoqData]
public async Task Events_are_matched_via_MessageAttribute(FakeServer server, ThirdTestEvent testEvent, EventReceivedAsync<AttributeTestEvent> eventReceived)
{
Expand All @@ -55,6 +77,28 @@ public async Task Events_are_matched_via_MessageAttribute(FakeServer server, Thi
Mock.Get(eventReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<IEventContext<AttributeTestEvent>>()), Times.Once);
}

[Test, AutoMoqData]
public async Task Outgoing_Events_are_marked_via_MessageAttribute(FakeServer server, AttributeTestEvent testEvent, EventReceivedAsync<ThirdTestEvent> eventReceived)
{
var host = CreateNybusHost(nybus =>
{
nybus.SubscribeToEvent(eventReceived);
nybus.UseRabbitMqBusEngine(rabbitMq =>
{
rabbitMq.Configure(c => c.ConnectionFactory = server.CreateConnectionFactory());
});
});

await host.StartAsync();

await host.Bus.RaiseEventAsync(testEvent);

await host.StopAsync();

Mock.Get(eventReceived).Verify(p => p(It.IsAny<IDispatcher>(), It.IsAny<IEventContext<ThirdTestEvent>>()), Times.Once);
}

[Test, AutoMoqData]
public async Task Commands_are_correctly_converted(FakeServer server, ThirdTestCommand testCommand, CommandReceivedAsync<AttributeTestCommand> commandReceived)
{
Expand Down

0 comments on commit 2c6cf7d

Please sign in to comment.