public void CreateNodesAndVerifyPublishing()
        {
            const string initialText      = "Initial Text";
            const string nodeOneEventText = "Node One event text";

            String myTestString = initialText;

            var autoResetEvent      = new AutoResetEvent(false);
            var rabbitMqPubSubNode1 =
                new RabbitMqPubSubNode("Test",
                                       (x) =>
            {
                //Do something in the callback
                autoResetEvent.Set();
                myTestString += x;
            });

            // A moment for Rabbit to establish queue etc.
            Thread.Sleep(2000);
            rabbitMqPubSubNode1.Publish(nodeOneEventText);
            Assert.IsTrue(autoResetEvent.WaitOne());
            Assert.AreEqual(
                string.Format("{0}Message Received by Test: {1}", initialText, nodeOneEventText),
                myTestString);
        }
Exemple #2
0
        public void AddItemToCart_AndAssertOnSubscriberHandling()
        {
            const string purchasingDomainEvent1 = "AddItemToCart";

            string myPurchasingTestString = string.Empty;
            string myInventoryTestString  = string.Empty;

            var autoResetEventPurchasing = new AutoResetEvent(false); // used to assert async callback
            var autoResetEventInventory  = new AutoResetEvent(false); // used to assert async callback

            // kick off the two pub sub domains as background workers
            // one for inventory and one for purchasing
            var purchasingPubSubNode =
                new RabbitMqPubSubNode("Purchasing",
                                       messageReceivedByPurchasingNode =>
            {
                autoResetEventPurchasing.Set();
                myPurchasingTestString += messageReceivedByPurchasingNode + Environment.NewLine;
            });

            var inventoryPubSubNode =
                new RabbitMqPubSubNode("Inventory",
                                       messageReceivedByInventoryNode =>
            {
                autoResetEventInventory.Set();
                myInventoryTestString += messageReceivedByInventoryNode + Environment.NewLine;
            });

            // Publish First Domain Event from purchasing
            // Publish first Domain event
            purchasingPubSubNode.Publish(purchasingDomainEvent1);

            Assert.IsTrue(autoResetEventPurchasing.WaitOne()); // Leverage AutoResetEvent to assert async callback
            // Should assert for message being received twice, once by inventory and once by purchasing itself
            Assert.AreEqual(
                string.Format(
                    "Message received by Purchasing: {0}" + Environment.NewLine,
                    purchasingDomainEvent1),
                myPurchasingTestString);

            Assert.IsTrue(autoResetEventInventory.WaitOne()); // Leverage AutoResetEvent to assert async callback
            Assert.AreEqual(
                string.Format(
                    "Message received by Inventory: {0}" + Environment.NewLine,
                    purchasingDomainEvent1),
                myInventoryTestString);
        }