Skip to content

Instantly share code, notes, and snippets.

@chribben
Created February 12, 2012 22:36
Show Gist options
  • Save chribben/1811264 to your computer and use it in GitHub Desktop.
Save chribben/1811264 to your computer and use it in GitHub Desktop.
Quantum.TestSendReceive w/o IoC
[TestFixture]
public class TestSendMessageReceiveEventNoIoC
{
private readonly Guid _aggregateId = Guid.NewGuid();
private static readonly ILog Logger = LogManager.GetLogger(typeof (TestSendMessageReceiveEvent));
private readonly ManualResetEvent _received = new ManualResetEvent(false);
public TestSendMessageReceiveEventNoIoC()
{
BasicConfigurator.Configure();
}
public IServiceBus LocalBus { get; private set; }
[Given]
public void installation_of_infrastructure_objects()
{
Logger.Info("Installing stuff");
LocalBus = ServiceBusFactory.New(x => x.ReceiveFrom("loopback://localhost/mt_client"));
var eventPublisher = new EventPublisher(LocalBus);
var inMemoryEventStore = new InMemoryEventStore(eventPublisher);
var aggregateFactory = new AggregateFactory();
var simpleEventRepository = new SimpleEventRepository(inMemoryEventStore, aggregateFactory);
LocalBus.SubscribeConsumer(() => new MyEventConsumer(_received));
LocalBus.SubscribeConsumer(() => new CreateBatchCommandHandler(simpleEventRepository));
LocalBus.SubscribeConsumer(() => new RequestSeparateDocumentsCommandHandler(simpleEventRepository));
LocalBus.SubscribeConsumer(() => new RequestClassifyDocumentsCommandHandler(simpleEventRepository));
simpleEventRepository.Save(new Batch(_aggregateId), Guid.NewGuid(), null);
}
[When]
public void sending_a_command()
{
LocalBus.Publish(new RequestSeparateDocuments(_aggregateId));
}
[Then]
public void corresponding_event_should_be_received_by_consumer()
{
Assert.AreEqual(LocalBus.HasSubscription<SeparateDocumentsRequested>().Count(), 1, "No subscription for the SeparateDocumentsRequested was found.");
_received.WaitOne(10000).ShouldBeTrue();
}
[TestFixtureTearDown]
public void TearDown()
{
LocalBus.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment