public async Task VerifySubscriberIsInitializedWhenRegistered()
        {
            // Setup the message bus.
            var cs = Any.String();
            var subscriber = new MockSubscriber();
            var mbf = new MockMessageBusFactory { Subscriber = subscriber };
            var mbd = new MessageBusDescription { ConnectionString = cs, Factory = mbf };
            var bus = new MessageBus(mbd);
            var entity = "MessageSendSuccess;MessageSendFailure";
            var name = "MessageSendSuccess";

            Assert.IsFalse(
                subscriber.IsInitialized, 
                "The subscriber should not be initialized before it is registered.");

            var called = false;

            // Register the subscriber.
            await bus.RegisterHandlerAsync(entity, name, message => Task.Run(() => { called = true; }));

            Assert.IsTrue(subscriber.IsInitialized, "The subscriber should be initialized after it is registered.");
            Assert.AreEqual(subscriber.Description.ConnectionString, cs);
            Assert.AreEqual(subscriber.Description.Entity, entity);
            Assert.AreEqual(subscriber.Description.Name, name);

            await subscriber.Handler.Invoke(null);
            Assert.IsTrue(called, "The handler must be callable.");

            // Close the bus.
            await bus.CloseAsync();

            Assert.IsTrue(subscriber.IsClosed, "The subscriber should be closed after the bus is closed.");
        }
Example #2
0
        public async Task VerifySubscriberIsInitializedWhenRegistered()
        {
            // Setup the message bus.
            var cs         = Any.String();
            var subscriber = new MockSubscriber();
            var mbf        = new MockMessageBusFactory {
                Subscriber = subscriber
            };
            var mbd = new MessageBusDescription {
                ConnectionString = cs, Factory = mbf
            };
            var bus    = new MessageBus(mbd);
            var entity = "MessageSendSuccess;MessageSendFailure";
            var name   = "MessageSendSuccess";

            Assert.IsFalse(
                subscriber.IsInitialized,
                "The subscriber should not be initialized before it is registered.");

            var called = false;

            // Register the subscriber.
            await bus.RegisterHandlerAsync(entity, name, message => Task.Run(() => { called = true; }));

            Assert.IsTrue(subscriber.IsInitialized, "The subscriber should be initialized after it is registered.");
            Assert.AreEqual(subscriber.Description.ConnectionString, cs);
            Assert.AreEqual(subscriber.Description.Entity, entity);
            Assert.AreEqual(subscriber.Description.Name, name);

            await subscriber.Handler.Invoke(null);

            Assert.IsTrue(called, "The handler must be callable.");

            // Close the bus.
            await bus.CloseAsync();

            Assert.IsTrue(subscriber.IsClosed, "The subscriber should be closed after the bus is closed.");
        }