예제 #1
0
        public async Task send_and_handle_end_to_end()
        {
            // when this code appears in an MVC controller, both the IDocumentSession and the IServiceBus could be injected dependencies.
            using (var session = theSender.Get <IDocumentStore>().OpenSession())
            {
                var bus = theSender.Get <IServiceBus>();

                bus.EnlistInTransaction(session);

                var order = new Order {
                    Id = Guid.NewGuid(), ItemName = "Hat"
                };
                session.Store(order);

                var commandMessage = new ProcessOrder {
                    Id = order.Id, ItemName = order.ItemName
                };
                await bus.Send(commandMessage);

                //TODO: assert that at this point, there should not have been anything handed to the sending agent.

                // SaveChangesAsync will: save the document session including the outgoing envelopes,
                // then trigger the sending agent to start delivering those envelopes.
                await session.SaveChangesAsync();

                //TODO: assert that at this point, the sending agent should have been told to deliver the message
            }

            TestSynch.HandledProcessOrderCommand.WaitOne(5.Seconds()).ShouldBe(true, "Waited too long for ProcessOrder event to be handled");
            //TODO: at this point, the warehouse app's sending agent should _not_ have been told to deliver the message
            TestSynch.WarehouseHandlerShouldContinueEvent.Set();

            TestSynch.ProcessedItemOutOfStockEvent.WaitOne(5.Seconds()).ShouldBe(true, "Waited too long for ItemOutOfStock event to be handled");
        }
예제 #2
0
        public object Handle(ProcessOrder processOrder, IDocumentSession session)
        {
            session.Store(new PickList {
                Id = processOrder.Id
            });
            var outOfStockEvent = new ItemOutOfStock {
                OrderId = processOrder.Id, ItemName = processOrder.ItemName
            };

            // wait here for the test to inspect state.
            TestSynch.HandledProcessOrderCommand.Set();
            TestSynch.WarehouseHandlerShouldContinueEvent.WaitOne(5.Seconds());

            return(outOfStockEvent);
        }
예제 #3
0
        public void Handle(ProcessOrder processOrder, IDocumentStore martenStore, IServiceBus bus)
        {
            using (var session = martenStore.OpenSession())
            {
                bus.EnlistInTransaction(session);

                session.Store(new PickList {
                    Id = processOrder.Id
                });
                var outOfStockEvent = new ItemOutOfStock {
                    OrderId = processOrder.Id, ItemName = processOrder.ItemName
                };

                bus.Publish(outOfStockEvent);

                // wait here for the test to inspect state.
                TestSynch.HandledProcessOrderCommand.Set();
                TestSynch.WarehouseHandlerShouldContinueEvent.WaitOne(5.Seconds());

                session.SaveChanges();
            }
        }