Ho un gestore di comandi che richiama un'operazione su un oggetto dominio che a sua volta genera un evento quando l'operazione è stata eseguita. Mi piacerebbe testare che un gestore di eventi riceve l'evento quando il comando corrispondente è stato inviato (vedi sotto, alcuni codici omessi per brevità). Il gestore di eventi (MyEventConsumer.Consume) non viene mai richiamato anche se il messaggio di evento è pubblicato sul bus (bus di loopback in questo caso). Qualche idea?Come testare un sistema basato su comandi ed eventi con Masstransit
//Test
[TestFixture]
public class TestSendCommandReceiveEvent
{
[Given]
public void installation_of_infrastructure_objects()
{
container.Register(Component.For<MyEventConsumer>().UsingFactoryMethod(() => new MyEventConsumer(_received)));
container.Register(
Component.For<IServiceBus>()
.UsingFactoryMethod(() => ServiceBusFactory.New(x => { x.ReceiveFrom("loopback://localhost/mt_client"); x.Subscribe(conf => conf.LoadFrom(container)); })));
}
[When]
public void sending_a_command()
{
var LocalBus = container.Resolve<IServiceBus>();
LocalBus.Publish(new DoSomething(_aggregateId));
}
[Then]
public void corresponding_event_should_be_received_by_consumer()
{
_received.WaitOne(5000).ShouldBeTrue();
}
}
public class MyEventConsumer : Consumes<SomethingDone>.All
{
private readonly ManualResetEvent _received;
public MyEventConsumer(ManualResetEvent received)
{
_received = received;
}
public void Consume(SomethingDone message)
{
_received.Set();
}
}
//Command handler
public class DoSomethingCommandHandler : Consumes<DoSomething>.All where T:class
{
public void Consume(DoSomething message)
{
var ar = Repository.GetById<SomeAR>(message.ArId);
ar.DoSomething();
Repository.Save(ar, Guid.NewGuid(), null);
}
}
//Domain object
public class SomeDomainObject : AggregateBase
{
public void DoSomething()
{
RaiseEvent(new SomethingDone(Id, 1));
}
}
fa questo lavoro nella produzione e solo falliscono in un test? Sembra che roba sia accettabile dal codice, ma come penso ci siano alcuni errori nel codice, quindi si presume che le cose si colleghino correttamente. Suggerirei di unirti alla mailing list con un po 'più di dettagli su cosa sta succedendo. https://groups.google.com/forum/#!forum/masstransit-discuss Se dovessi indovinare, forse è un problema con il contenitore. Penso che li abbiamo visti tutti, ma potrebbe essere un outlier. – Travis
Hmm, sembra essere un problema di produzione. Deve aver configurato l'autobus sbagliato. Darò un occhiata. – Christian
Ok, non posso vedere cosa manca qui (tranne la mia mancanza di esperienza con MT/Castle). Passare alla mailing list. – Christian